3 ### GNU Affero General Public License compliance
5 ### (c) 2013 Mark Wooding
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of Chopwood: a password-changing service.
12 ### Chopwood is free software; you can redistribute it and/or modify
13 ### it under the terms of the GNU Affero General Public License as
14 ### published by the Free Software Foundation; either version 3 of the
15 ### License, or (at your option) any later version.
17 ### Chopwood is distributed in the hope that it will be useful,
18 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ### GNU Affero General Public License for more details.
22 ### You should have received a copy of the GNU Affero General Public
23 ### License along with Chopwood; if not, see
24 ### <http://www.gnu.org/licenses/>.
26 import contextlib as CTX
30 import subprocess as SUB
35 from auto import PACKAGE, VERSION
42 finally: SH.rmtree(d, ignore_errors = True)
46 for m in SYS.modules.itervalues():
48 except AttributeError: continue
49 d = OS.path.realpath(OS.path.dirname(f))
50 if d.startswith('/usr/') and not d.startswith('/usr/local/'): continue
56 if d.startswith(last): continue
61 def exists_subdir(subdir):
62 return lambda dir: OS.path.isdir(OS.path.join(dir, subdir))
66 kid = SUB.Popen(SL.split(cmd), stdout = SUB.PIPE, cwd = dir)
69 buf = kid.stdout.read(16384)
77 if f.startswith('./'): f = f[2:]
82 raise U.ExpectedError, \
83 (500, "trailing junk from `%s' in `%s'" % (cmd, dir))
87 (exists_subdir('.git'), [filez('git ls-files -coz --exclude-standard'),
88 filez('find .git -print0')]),
89 (lambda d: True, [filez('find . ( ! -perm +004 -prune ) -o -print0')])]
91 def dump_dir(dir, tf, root):
92 for test, listers in DUMPERS:
95 raise U.ExpectedError, (500, "no dumper for `%s'" % dir)
96 for lister in listers:
97 base = OS.path.basename(dir)
98 for file in lister(dir):
99 tf.add(OS.path.join(dir, file), OS.path.join(root, base, file),
103 if SYS.version_info >= (2, 6):
104 tf = TAR.open(fileobj = out, mode = 'w|gz', format = TAR.USTAR_FORMAT)
106 tf = TAR.open(fileobj = out, mode = 'w|gz')
108 for d in dirs_to_dump():
109 dump_dir(d, tf, '%s-%s' % (PACKAGE, VERSION))
112 ###----- That's all, folks --------------------------------------------------