|
From: <fcr...@us...> - 2012-01-13 11:47:22
|
Revision: 791
http://safekeep.svn.sourceforge.net/safekeep/?rev=791&view=rev
Author: fcrawford
Date: 2012-01-13 11:47:11 +0000 (Fri, 13 Jan 2012)
Log Message:
-----------
Clean up simple coding issues reported by pylint
Modified Paths:
--------------
safekeep/trunk/safekeep
Modified: safekeep/trunk/safekeep
===================================================================
--- safekeep/trunk/safekeep 2012-01-08 00:01:59 UTC (rev 790)
+++ safekeep/trunk/safekeep 2012-01-13 11:47:11 UTC (rev 791)
@@ -66,7 +66,6 @@
base_dir = None
current_pid = os.getpid()
default_bandwidth = {}
-cmd = "<Missing>"
PROTOCOL = "1.2"
VERSION = "1.3.3"
@@ -110,10 +109,10 @@
else:
print >> sys.stderr, msg.encode('utf-8')
-def info_file(file, marker=None):
- info('# File: ' + file)
- errs = 0;
- fin = open(file, 'r')
+def info_file(filename, marker=None):
+ info('# File: ' + filename)
+ errs = 0
+ fin = open(filename, 'r')
try:
for line in fin.readlines():
if marker:
@@ -183,7 +182,7 @@
child_in.write(stdin)
child_in.close()
- lines=[]
+ lines = []
for line in child_out:
if stdout:
lines.append(line)
@@ -207,7 +206,7 @@
rc, out = do_spawn(args, stdin, stdout)
except OSError, ex:
ret = "OSError: %s" % (ex)
- error('%s failed: %s' % (cmd, ret));
+ error('%s failed: %s' % (cmd, ret))
return ret
if not rc:
@@ -219,7 +218,7 @@
else:
ret = 'unknown exit status: %d' % rc
if ret:
- error('%s failed: %s' % (cmd, ret));
+ error('%s failed: %s' % (cmd, ret))
return (ret, out)
# this just spawns an external program (optionally through a shell)
@@ -242,7 +241,7 @@
rc, out = do_spawn(args, None, True)
except OSError, ex:
return None
- if not rc in (0,1):
+ if not rc in (0, 1):
return None
return out or ''
@@ -265,8 +264,8 @@
cmd = ['/usr/sbin/sendmail', '-t', '-f', email_from]
call(cmd, stdin=msg)
-def is_temp_root(dir):
- return dir != '/'
+def is_temp_root(directory):
+ return directory != '/'
def reroot(root, path):
if root == '/': return path
@@ -275,9 +274,9 @@
if path.startswith('/'): return root + path
return os.path.join(root, path)
-def parse_prop_file(file):
+def parse_prop_file(filename):
props = {}
- fin = open(file)
+ fin = open(filename)
lines = fin.readlines()
fin.close()
for line in lines:
@@ -301,23 +300,23 @@
return repr(self.value)
def parse_dump(dump_el):
- type = dump_el.getAttribute('type')
- if not type:
+ dbtype = dump_el.getAttribute('type')
+ if not dbtype:
raise ConfigException('You need to specify the database type')
- if type not in ('postgres', 'postgresql', 'pgsql', 'mysql'):
- raise ConfigException('Invalid database type: %s' % type)
+ if dbtype not in ('postgres', 'postgresql', 'pgsql', 'mysql'):
+ raise ConfigException('Invalid database type: %s' % dbtype)
db = dump_el.getAttribute('db')
user = dump_el.getAttribute('user')
dbuser = dump_el.getAttribute('dbuser')
dbpasswd = dump_el.getAttribute('dbpasswd')
opts = (dump_el.getAttribute('options') or '').split()
- file = dump_el.getAttribute('file')
- if not file:
+ dbfile = dump_el.getAttribute('file')
+ if not dbfile:
raise ConfigException('You need to specify where the database should be dumped')
cleanup = dump_el.getAttribute('cleanup')
- return { 'type' : type, 'db' : db, 'user' : user, 'dbuser' : dbuser, 'dbpasswd': dbpasswd,
- 'opts' : opts, 'file' : file, 'cleanup' : cleanup }
+ return { 'type' : dbtype, 'db' : db, 'user' : user, 'dbuser' : dbuser, 'dbpasswd': dbpasswd,
+ 'opts' : opts, 'file' : dbfile, 'cleanup' : cleanup }
def parse_snap(snap_el):
device = snap_el.getAttribute('device')
@@ -358,8 +357,8 @@
def parse_config(backup_el, dflt_id):
if backup_el.tagName != 'backup':
raise ConfigException('Invalid config file, the top level element must be <backup>')
- id = backup_el.getAttribute('id')
- if not id: id = dflt_id
+ cfg_id = backup_el.getAttribute('id')
+ if not cfg_id: cfg_id = dflt_id
host_el = backup_el.getElementsByTagName('host')
if host_el:
@@ -392,15 +391,15 @@
raise ConfigException('Can not have more than one bandwidth element')
repo_el = backup_el.getElementsByTagName('repo')
- dir = None
+ repo_dir = None
retention = None
if len(repo_el) == 1:
- dir = repo_el[0].getAttribute('path')
+ repo_dir = repo_el[0].getAttribute('path')
retention = repo_el[0].getAttribute('retention')
elif len(repo_el) > 1:
raise ConfigException('Can not have more than one repo element')
- if not dir: dir = id
- dir = os.path.join(base_dir, dir)
+ if not repo_dir: repo_dir = cfg_id
+ repo_dir = os.path.join(base_dir, repo_dir)
options_els = backup_el.getElementsByTagName('options')
options = []
@@ -410,7 +409,7 @@
continue
option = options_el.nodeName
if option == 'special-files':
- warn('options element special-files is deprecated, use data attributes instead')
+ warn('options element special-files is deprecated, use data attributes instead')
if option in ('special-files', 'rdiff-backup'):
if options_el.hasAttributes():
for key, value in options_el.attributes.items():
@@ -466,8 +465,8 @@
'/var/named/chroot/var/run', '/var/named/chroot/var/tmp' ]
cludes = [{ 'type' : 'exclude', 'path' : path, 'glob' : None, 'regexp' : None } for path in path_xcludes]
- return { 'id': id, 'host' : host, 'port' : port, 'nice' : nice, 'user' : user, 'key_ctrl' : key_ctrl, 'key_data' : key_data,
- 'dir' : dir, 'retention' : retention, 'dumps' : dumps, 'snaps' : snaps, 'script' : script,
+ return { 'id': cfg_id, 'host' : host, 'port' : port, 'nice' : nice, 'user' : user, 'key_ctrl' : key_ctrl, 'key_data' : key_data,
+ 'dir' : repo_dir, 'retention' : retention, 'dumps' : dumps, 'snaps' : snaps, 'script' : script,
'cludes' : cludes, 'data_options' : data_options, 'options' : options, 'bw' : bw}
def parse_locs(cfglocs):
@@ -548,10 +547,10 @@
def do_client_dbdump(cfg):
debug('Doing DB dumps')
for dump in cfg['dumps']:
- type = dump['type']
+ dbtype = dump['type']
opts = dump['opts']
passwdfile = None
- if type in ('postgres', 'postgresql', 'pgsql'):
+ if dbtype in ('postgres', 'postgresql', 'pgsql'):
if dump['db']:
args = ['pg_dump']
args.extend(['-C'])
@@ -568,7 +567,7 @@
f.write(dump['dbpasswd'])
f.close()
- elif type in ('mysql'):
+ elif dbtype in ('mysql'):
args = ['mysqldump']
if dump['dbuser']:
args.extend(['-u', dump['dbuser']])
@@ -581,7 +580,7 @@
args.extend([dump['db']])
else:
- warn('Invalid database type: ' + type)
+ warn('Invalid database type: ' + dbtype)
continue
if dump['user']:
@@ -592,7 +591,7 @@
if passwdfile:
- os.environ['PGPASSFILE'] = passwdfile
+ os.environ['PGPASSFILE'] = passwdfile
try:
ec = spawn(cmd)
finally:
@@ -656,11 +655,11 @@
def do_lvremove(device):
(group, volume) = device.split('/')[-2:]
if group == 'mapper':
- lvmdev = device;
+ lvmdev = device
else:
lvmdev = '/dev/mapper/%s-%s' % (group, volume.replace('-', '--'))
if os.path.exists(lvmdev):
- for i in range(1,10):
+ for i in range(1, 10):
ret = spawn(['sync'])
ret = spawn(['dmsetup', 'remove', lvmdev])
ret = spawn(['dmsetup', 'remove', lvmdev + '-cow'])
@@ -1025,9 +1024,9 @@
client_side_script('POST-SETUP', cfg, bdir)
send('OK ' + bdir)
elif line.startswith('CLEANUP'):
- dir = line[7:].strip()
- if dir == bdir: should_cleanup = False
- do_client_cleanup(cfg, dir)
+ path = line[7:].strip()
+ if path == bdir: should_cleanup = False
+ do_client_cleanup(cfg, path)
client_side_script('POST-BACKUP', cfg, bdir)
send('OK')
elif line.startswith('SCRUB'):
@@ -1113,15 +1112,15 @@
limit_ul = get_bandwidth(cfg, 'upload')
if limit_dl or limit_ul:
trickle.extend([trickle_cmd])
- if verbosity_trickle: trickle.extend([verbosity_trickle])
+ if verbosity_trickle: trickle.extend([verbosity_trickle])
if limit_dl:
trickle.extend(['-d', str(limit_dl)])
if limit_ul:
trickle.extend(['-u', str(limit_ul)])
if len(trickle):
if try_to_run([trickle_cmd, '-V']) is None:
- warn('Trickle not available, bandwidth limiting disabled')
- trickle = []
+ warn('Trickle not available, bandwidth limiting disabled')
+ trickle = []
args.extend(trickle)
args.extend(['rdiff-backup'])
@@ -1139,7 +1138,7 @@
special_files = []
if cfg['data_options'].get('exclude-devices').lower() == 'true':
- special_files.extend(['--exclude-device-files'])
+ special_files.extend(['--exclude-device-files'])
if cfg['data_options'].get('exclude-sockets').lower() == 'true':
special_files.extend(['--exclude-sockets'])
if cfg['data_options'].get('exclude-fifos').lower() == 'true':
@@ -1203,10 +1202,10 @@
debug("Do server main loop")
output_done = False
for cfg in cfgs.itervalues():
- id = cfg['id']
- if ids and id not in ids: continue
+ cfg_id = cfg['id']
+ if ids and cfg_id not in ids: continue
info('------------------------------------------------------------------')
- info('Server backup starting for client %s' % id)
+ info('Server backup starting for client %s' % cfg_id)
output_done = True
cleaned_up = True
@@ -1231,9 +1230,9 @@
cmd = []
if cfg['host']:
cmd.extend(['ssh'])
- if verbosity_ssh: cmd.extend([verbosity_ssh])
+ if verbosity_ssh: cmd.extend([verbosity_ssh])
if cfg['port']: cmd.extend(['-p', cfg['port']])
- cmd.extend(['-T', '-i', cfg['key_ctrl'], '-l', cfg['user'], cfg['host']])
+ cmd.extend(['-T', '-i', cfg['key_ctrl'], '-l', cfg['user'], cfg['host']])
cmd.extend(['safekeep', '--client'])
if use_subprocess:
@@ -1248,7 +1247,7 @@
client_versions = do_server_getanswer(cout)
do_server_compat(client_versions)
- cin.write('CONFIG: %d: %s\n' % (len(cfg['text'].splitlines()), id))
+ cin.write('CONFIG: %d: %s\n' % (len(cfg['text'].splitlines()), cfg_id))
cin.write(cfg['text'] + '\n')
cin.flush()
remote_script = do_server_getanswer(cout)
@@ -1316,19 +1315,19 @@
do_server_getanswer(cout)
if errs == 0:
- info('Server backup for client %s: OK' % id)
+ info('Server backup for client %s: OK' % cfg_id)
else:
- info('Server backup for client %s: OK (%d WARNINGS)' % (id, errs))
+ info('Server backup for client %s: OK (%d WARNINGS)' % (cfg_id, errs))
except Exception, ex:
if cleanup:
- info('Client-side cleanup for client %s: FAILED' % id)
+ info('Client-side cleanup for client %s: FAILED' % cfg_id)
else:
- if isinstance(ex, ClientException):
- error('Client %s: FAILED due to: %s' % (id, ex or ''))
- if ex.traceback and verbosity_level > 2: error(ex.traceback)
- else:
- error('Server backup for client %s: FAILED' % id, ex)
+ if isinstance(ex, ClientException):
+ error('Client %s: FAILED due to: %s' % (cfg_id, ex or ''))
+ if ex.traceback and verbosity_level > 2: error(ex.traceback)
+ else:
+ error('Server backup for client %s: FAILED' % cfg_id, ex)
# Shutdown client
cout.close()
@@ -1346,13 +1345,13 @@
debug("Do server listing main loop")
output_done = False
for cfg in cfgs.itervalues():
- id = cfg['id']
- if ids and id not in ids: continue
+ cfg_id = cfg['id']
+ if ids and cfg_id not in ids: continue
if list_parsable:
- info('Client: %s' % id)
+ info('Client: %s' % cfg_id)
else:
info('------------------------------------------------------------------')
- info('Server listing for client %s' % id)
+ info('Server listing for client %s' % cfg_id)
output_done = True
args = ['rdiff-backup']
@@ -1382,11 +1381,11 @@
def do_keys(cfgs, ids, nice_rem, identity, status, dump, deploy):
for cfg in cfgs.itervalues():
- id = cfg['id']
- if ids and id not in ids: continue
- info('Handling keys for client: %s' % id)
+ cfg_id = cfg['id']
+ if ids and cfg_id not in ids: continue
+ info('Handling keys for client: %s' % cfg_id)
if not cfg['host']:
- info('%s: Client is local, it needs no keys' % id)
+ info('%s: Client is local, it needs no keys' % cfg_id)
continue
nice = cfg['nice'] or nice_rem
@@ -1403,25 +1402,25 @@
publickeyfile = privatekeyfile + '.pub'
if not os.path.isfile(privatekeyfile):
if os.path.isfile(publickeyfile):
- error('%s: Public key exists %s, but private key is missing. Skipping client.' % (id, publickeyfile))
+ error('%s: Public key exists %s, but private key is missing. Skipping client.' % (cfg_id, publickeyfile))
break
if dump:
- print '%s: Key does not exist: %s.' % (id, privatekeyfile)
+ print '%s: Key does not exist: %s.' % (cfg_id, privatekeyfile)
break
if status:
- print '%s: Key does not exist: %s. Will be generated.' % (id, privatekeyfile)
+ print '%s: Key does not exist: %s. Will be generated.' % (cfg_id, privatekeyfile)
break
if deploy:
- info('%s: Key do not exist, generating it now: %s' % (id, privatekeyfile))
+ info('%s: Key do not exist, generating it now: %s' % (cfg_id, privatekeyfile))
gencmd = 'ssh-keygen -q -b 1024 -t dsa -N "" -C "SafeKeep auto generated key at %s@%s" -f %s' % (backup_user, os.uname()[1], privatekeyfile)
if backup_user != work_user:
gencmd = 'su -s /bin/sh -c %s - %s' % (commands.mkarg(gencmd), backup_user)
debug(gencmd)
if spawn(gencmd):
- error('%s: Failed to generate key %s. Skipping client.' % (id, privatekeyfile))
+ error('%s: Failed to generate key %s. Skipping client.' % (cfg_id, privatekeyfile))
break
if not os.path.isfile(publickeyfile):
- error('%s: Private key exists %s, but public key is missing. Skipping client.' % (id, privatekeyfile))
+ error('%s: Private key exists %s, but public key is missing. Skipping client.' % (cfg_id, privatekeyfile))
break
fin = open(publickeyfile, 'r')
publickey = fin.read()
@@ -1445,7 +1444,7 @@
cmd = [basessh, '%s@%s' % (cfg['user'], cfg['host']), "if test -f .ssh/authorized_keys; then cat .ssh/authorized_keys; fi"]
authtext = call(cmd)
if authtext is None:
- error('%s: Failed to read the %s@%s:~/.ssh/authorized_keys file.' % (id, cfg['user'], cfg['host']))
+ error('%s: Failed to read the %s@%s:~/.ssh/authorized_keys file.' % (cfg_id, cfg['user'], cfg['host']))
continue
auth_keys = parse_authorized_keys(authtext)
this_keys = parse_authorized_keys(output)
@@ -1457,11 +1456,11 @@
new_keys.append(this_key)
if not new_keys:
if status:
- print '%s: Client is up to date.' % id
+ print '%s: Client is up to date.' % cfg_id
continue
if status:
- print '%s: Keys will be deployed on the client.' % id
+ print '%s: Keys will be deployed on the client.' % cfg_id
if deploy:
cmd = [basessh, '%s@%s' % (cfg['user'], cfg['host']), "umask 077; test -d .ssh || mkdir .ssh; cat >> .ssh/authorized_keys"]
keys = '%s\n' % '\n'.join([key[4] for key in new_keys])
@@ -1479,7 +1478,7 @@
if line[0] in '0123456789':
warn('SSH Protocol 1 keys are ignored: %s' % line)
continue
- opts =''
+ opts = ''
if line[0:7] not in ('ssh-dss', 'ssh-rsa'):
in_str = False
in_esc = False
@@ -1509,9 +1508,9 @@
error('Invalid key line, skipping: %s' % line)
continue
- type = parts[0]
- if type not in ('ssh-dss', 'ssh-rsa'):
- error('Invalid key type "%s", skipping: %s' % (type, line))
+ ssh_type = parts[0]
+ if ssh_type not in ('ssh-dss', 'ssh-rsa'):
+ error('Invalid key type "%s", skipping: %s' % (ssh_type, line))
continue
base46enc = parts[1]
@@ -1521,7 +1520,7 @@
else:
comment = parts[2]
- keys.append((opts, type, base46enc, comment, line))
+ keys.append((opts, ssh_type, base46enc, comment, line))
return keys
@@ -1697,7 +1696,7 @@
if cfgfile:
warn('Configuration file does not exist, skipping: %s' % cfgfile)
else:
- cfgfile = config_file
+ cfgfile = config_file
props = {}
def get_int(p):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|