"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/Tardis/Util.py" between
Tardis-1.1.5.tar.gz and Tardis-1.2.1.tar.gz

About: Tardis is a system for making encrypted, incremental backups of filesystems.

Util.py  (Tardis-1.1.5):Util.py  (Tardis-1.2.1)
skipping to change at line 61 skipping to change at line 61
import signal import signal
import urllib.request, urllib.parse, urllib.error import urllib.request, urllib.parse, urllib.error
import zlib import zlib
import bz2 import bz2
import lzma import lzma
import srp import srp
import passwordmeter import passwordmeter
import colorlog import colorlog
import parsedatetime
import Tardis.Connection as Connection import Tardis.Connection as Connection
import Tardis.CompressedBuffer as CompressedBuffer import Tardis.CompressedBuffer as CompressedBuffer
import Tardis.Defaults as Defaults import Tardis.Defaults as Defaults
import Tardis.TardisDB as TardisDB import Tardis.TardisDB as TardisDB
import Tardis.TardisCrypto as TardisCrypto import Tardis.TardisCrypto as TardisCrypto
import Tardis.CacheDir as CacheDir import Tardis.CacheDir as CacheDir
import Tardis.RemoteDB as RemoteDB import Tardis.RemoteDB as RemoteDB
skipping to change at line 158 skipping to change at line 159
return int(x[1:], 8) return int(x[1:], 8)
else: else:
return int(x) return int(x)
# Make a path look short. # Make a path look short.
def shortPath(path, width=80): def shortPath(path, width=80):
""" """
Compress a path to only show the last elements if it's wider than specified. Compress a path to only show the last elements if it's wider than specified.
Replaces early elements with ".../" Replaces early elements with ".../"
""" """
# If we're already short enough, just return what we have
if not path or len(path) < width: if not path or len(path) < width:
return path return path
# Compensate for a coming .../ plus slosh
width -= 5 width -= 5
# split into path prefix, + the current file
path, retPath = os.path.split(path) path, retPath = os.path.split(path)
# Check to see if we're already wider than width..... # Check to see if we're already wider than width.....
# If so, put a "..." in the middle of the filename # If so, put a "..." in the middle of the filename
# retPath is the current file at this point
if len(retPath) > width: if len(retPath) > width:
namecomps = retPath.rsplit('.', 1) namecomps = retPath.rsplit('.', 1)
#print("Name Comps:: ", namecomps)
if len(namecomps) == 2: if len(namecomps) == 2:
main, suffix = namecomps main, suffix = namecomps
else: else:
main = namecomps[0] main = namecomps[0]
suffix = '' suffix = ''
length = len(main) - len(suffix) - 5 #print("Split:: ", main, suffix)
length = min(length, width - 4) length = min(len(retPath), width) - 5
retPath = main[0:length // 2] + "..." + main[-(length // 2):] retPath = main[0:(length // 2) - 1] + "..." + main[-(length // 2) + 1:
]
if suffix: if suffix:
retPath = '.'.join([retPath, suffix]) retPath = '.'.join([retPath, suffix])
#print("First chunk:: ", len(retPath), retPath)
# Build it up backwards from the end # Build it up backwards from the end
while len(retPath) < width: while len(retPath) < width:
#print retPath, len(retPath), width
path, tail = os.path.split(path) path, tail = os.path.split(path)
#print(retPath, len(retPath), path, tail)
if not path or not tail: if not path or not tail:
break break
elif len(tail) + len(retPath) > width: elif len(tail) + len(os.sep) + len(retPath) > width:
break break
else: else:
retPath = os.path.join(tail, retPath) retPath = os.path.join(tail, retPath)
return "..." + os.sep + retPath return "..." + os.sep + retPath
def accumulateStat(stats, name, amount=1): def accumulateStat(stats, name, amount=1):
if stats: if stats:
stats[name] = stats.setdefault(name, 0) + amount stats[name] = stats.setdefault(name, 0) + amount
skipping to change at line 752 skipping to change at line 762
client = str(client) client = str(client)
config.add_section(client) config.add_section(client)
config.read(fullPath(name)) config.read(fullPath(name))
try: try:
contentKey = _updateLen(config.get(client, 'ContentKey'), 32) contentKey = _updateLen(config.get(client, 'ContentKey'), 32)
nameKey = _updateLen(config.get(client, 'FilenameKey'), 32) nameKey = _updateLen(config.get(client, 'FilenameKey'), 32)
return (nameKey, contentKey) return (nameKey, contentKey)
except configparser.NoOptionError as e: except configparser.NoOptionError as e:
raise Exception("No keys available for client " + client) raise Exception("No keys available for client " + client)
def saveKeys(name, client, nameKey, contentKey): def saveKeys(name, client, nameKey, contentKey, srpSalt=None, srpVKey=None):
def _addOrDelete(config, client, key, value):
if value:
config.set(client, key, value)
else:
config.remove_option(client, key)
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.add_section(client) config.add_section(client)
config.read(name) config.read(name)
if contentKey: _addOrDelete(config, client, 'ContentKey', contentKey)
config.set(client, 'ContentKey', contentKey) _addOrDelete(config, client, 'FilenameKey', nameKey)
else: _addOrDelete(config, client, 'SRPSalt', srpSalt)
config.remove_option(client, 'ContentKey') _addOrDelete(config, client, 'SRPVkey', srpVkey)
if nameKey:
config.set(client, 'FilenameKey', nameKey)
else:
config.remove_option(client, 'FilenameKey')
with open(name, 'w') as configfile: with open(name, 'w') as configfile:
config.write(configfile) config.write(configfile)
def mkKeyString(client, nameKey, contentKey): def mkKeyString(client, nameKey, contentKey):
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.add_section(client) config.add_section(client)
config.set(client, 'ContentKey', contentKey) config.set(client, 'ContentKey', contentKey)
config.set(client, 'FilenameKey', nameKey) config.set(client, 'FilenameKey', nameKey)
x = io.StringIO() x = io.StringIO()
skipping to change at line 805 skipping to change at line 816
f.close() f.close()
except Exception as e: except Exception as e:
logger.warning("Could not write metadata file for %s: %s: %s", checksum, metaName, str(e)) logger.warning("Could not write metadata file for %s: %s: %s", checksum, metaName, str(e))
class StoreBoolean(argparse.Action): class StoreBoolean(argparse.Action):
""" """
Class to handle options of the form "--[no]argument" where you can specify - -noargument to store a False, Class to handle options of the form "--[no]argument" where you can specify - -noargument to store a False,
or --argument to store a true. or --argument to store a true.
""" """
def __init__(self, option_strings, dest, negate="no", nargs=0, **kwargs): def __init__(self, option_strings, dest, negate="no", nargs=0, **kwargs):
if nargs is not 0: if nargs != 0:
raise ValueError("nargs not allowed") raise ValueError("nargs not allowed")
#if len(option_strings) > 1: #if len(option_strings) > 1:
# raise ValueError("Multiple option strings not allowed") # raise ValueError("Multiple option strings not allowed")
self.negative_option = "--" + negate + option_strings[0][2:] self.negative_option = "--" + negate + option_strings[0][2:]
self.help_option = "--[" + negate + "]" + option_strings[0][2:] self.help_option = "--[" + negate + "]" + option_strings[0][2:]
option_strings.append(self.negative_option) option_strings.append(self.negative_option)
super(StoreBoolean, self).__init__(option_strings, dest, nargs=0, **kwar gs) super(StoreBoolean, self).__init__(option_strings, dest, nargs=0, **kwar gs)
def __call__(self, parser, arguments, values, option_string=None): def __call__(self, parser, arguments, values, option_string=None):
#print "Here: ", option_string, " :: ", self.option_strings #print "Here: ", option_string, " :: ", self.option_strings
 End of changes. 14 change blocks. 
16 lines changed or deleted 28 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)