~duplicity-team/duplicity/0.7-series

« back to all changes in this revision

Viewing changes to duplicity/manifest.py

  • Committer: Kenneth Loafman
  • Date: 2014-12-12 14:39:54 UTC
  • Revision ID: kenneth@loafman.com-20141212143954-wyln65yd1ynzsrlx
* Source formatted, using PyDev, all source files to fix some easily fixed
  PEP8 issues. Use ignore space when comparing against previous versions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
    """
41
41
    List of volumes and information about each one
42
42
    """
43
 
    def __init__(self, fh = None):
 
43
    def __init__(self, fh=None):
44
44
        """
45
45
        Create blank Manifest
46
46
 
52
52
        """
53
53
        self.hostname = None
54
54
        self.local_dirname = None
55
 
        self.volume_info_dict = {} # dictionary vol numbers -> vol infos
 
55
        self.volume_info_dict = {}  # dictionary vol numbers -> vol infos
56
56
        self.fh = fh
57
57
 
58
58
    def set_dirinfo(self):
64
64
        @return: manifest
65
65
        """
66
66
        self.hostname = globals.hostname
67
 
        self.local_dirname = globals.local_path.name #@UndefinedVariable
 
67
        self.local_dirname = globals.local_path.name  # @UndefinedVariable
68
68
        if self.fh:
69
69
            if self.hostname:
70
70
                self.fh.write("Hostname %s\n" % self.hostname)
92
92
            code = log.ErrorCode.hostname_mismatch
93
93
            code_extra = "%s %s" % (util.escape(globals.hostname), util.escape(self.hostname))
94
94
 
95
 
        elif (self.local_dirname and self.local_dirname != globals.local_path.name): #@UndefinedVariable
 
95
        elif (self.local_dirname and self.local_dirname != globals.local_path.name):  # @UndefinedVariable
96
96
            errmsg = _("Fatal Error: Backup source directory has changed.\n"
97
97
                       "Current directory: %s\n"
98
 
                       "Previous directory: %s") % (globals.local_path.name, self.local_dirname) #@UndefinedVariable
 
98
                       "Previous directory: %s") % (globals.local_path.name, self.local_dirname)  # @UndefinedVariable
99
99
            code = log.ErrorCode.source_dir_mismatch
100
 
            code_extra = "%s %s" % (util.escape(globals.local_path.name), util.escape(self.local_dirname)) #@UndefinedVariable
 
100
            code_extra = "%s %s" % (util.escape(globals.local_path.name), util.escape(self.local_dirname))  # @UndefinedVariable
101
101
        else:
102
102
            return
103
103
 
104
 
        log.FatalError(errmsg + "\n\n" +
 
104
        log.FatalError(errmsg + "\n\n" + 
105
105
                       _("Aborting because you may have accidentally tried to "
106
106
                         "backup two different data sets to the same remote "
107
107
                         "location, or using the same archive directory.  If "
325
325
 
326
326
        slist = ["Volume %d:" % self.volume_number]
327
327
        whitespace = "    "
328
 
        slist.append("%sStartingPath   %s %s" %
 
328
        slist.append("%sStartingPath   %s %s" % 
329
329
                     (whitespace, index_to_string(self.start_index), (self.start_block or " ")))
330
 
        slist.append("%sEndingPath     %s %s" %
 
330
        slist.append("%sEndingPath     %s %s" % 
331
331
                     (whitespace, index_to_string(self.end_index), (self.end_block or " ")))
332
332
        for key in self.hashes:
333
 
            slist.append("%sHash %s %s" %
 
333
            slist.append("%sHash %s %s" % 
334
334
                         (whitespace, key, self.hashes[key]))
335
335
        return "\n".join(slist)
336
336
 
417
417
        """
418
418
        return not self.__eq__(other)
419
419
 
420
 
    def contains(self, index_prefix, recursive = 1):
 
420
    def contains(self, index_prefix, recursive=1):
421
421
        """
422
422
        Return true if volume might contain index
423
423
 
427
427
        indicies.
428
428
        """
429
429
        if recursive:
430
 
            return (self.start_index[:len(index_prefix)] <=
 
430
            return (self.start_index[:len(index_prefix)] <= 
431
431
                    index_prefix <= self.end_index)
432
432
        else:
433
433
            return self.start_index <= index_prefix <= self.end_index
439
439
    Return quoted version of s safe to put in a manifest or volume info
440
440
    """
441
441
    if not nonnormal_char_re.search(s):
442
 
        return s # no quoting necessary
 
442
        return s  # no quoting necessary
443
443
    slist = []
444
444
    for char in s:
445
445
        if nonnormal_char_re.search(char):
457
457
        return quoted_string
458
458
    assert quoted_string[0] == quoted_string[-1]
459
459
    return_list = []
460
 
    i = 1 # skip initial char
461
 
    while i < len(quoted_string)-1:
 
460
    i = 1  # skip initial char
 
461
    while i < len(quoted_string) - 1:
462
462
        char = quoted_string[i]
463
463
        if char == "\\":
464
464
            # quoted section
465
 
            assert quoted_string[i+1] == "x"
466
 
            return_list.append(chr(int(quoted_string[i+2:i+4], 16)))
 
465
            assert quoted_string[i + 1] == "x"
 
466
            return_list.append(chr(int(quoted_string[i + 2:i + 4], 16)))
467
467
            i += 4
468
468
        else:
469
469
            return_list.append(char)