3 import hashsplit, git, options
17 for sub in os.listdir(n):
18 subfull = os.path.join(n, sub)
19 for sub2 in direxpand([subfull]):
22 if e.errno == errno.ENOTDIR:
24 elif e.errno in [errno.ENOENT, errno.EPERM, errno.EACCES]:
31 p = os.path.normpath(dir)
32 return (p != '.') and p or ''
36 def __init__(self, parent, name):
38 assert(not (parent and not name))
44 self.parent.children[self.name] = self
48 return os.path.join(self.parent.fullpath(), self.name)
58 def getdir(self, dir):
59 # FIXME: deal with '..' somehow
60 if dir.startswith('/'):
65 for part in _normpath(dir).split('/'):
66 sub = top.children.get(part)
68 sub = top.children[part] = Tree(top, part)
72 def addfile(self, mode, fullname, id):
73 (dir, name) = os.path.split(fullname)
74 self.getdir(dir).children[name] = (mode, name, id)
77 for c in self.children.values():
78 if isinstance(c, tuple): # sha1 entry for a file
81 t = ('40000', c.name, c.gen_tree())
86 self.sha = git.gen_tree(self.shalist())
91 bup save [-tc] [-n name] <filenames...>
93 t,tree output a tree id
94 c,commit output a commit id
95 n,name= name of backup set to update (if any)
97 o = options.Options('bup save', optspec)
98 (opt, flags, extra) = o.parse(sys.argv[1:])
100 if not (opt.tree or opt.commit or opt.name):
101 log("bup save: use one or more of -t, -c, -n\n")
104 root = Tree(None, '')
105 for fn in direxpand(extra):
107 # FIXME: symlinks etc.
115 (mode, id) = hashsplit.split_to_blob_or_tree([f])
116 root.addfile(mode, fn, id)
117 tree = root.gen_tree()
120 if opt.commit or opt.name:
121 msg = 'bup save\n\nGenerated by command:\n%r' % sys.argv
122 ref = opt.name and ('refs/heads/%s' % opt.name) or None
123 commit = git.gen_commit_easy(ref, tree, msg)
128 log('WARNING: %d errors encountered while saving.\n' % len(saved_errors))