Debian Codegraph @

examples/debfile/extract_cron

raw
1 #!/usr/bin/python3
2
3 # extract_cron - extract cron-related files from .deb s
4 # Copyright (C) 2007 Stefano Zacchiroli <[email protected]>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 """Extracts all cron-related files from a (list of) .deb package(s)."""
12
13 import os
14 import re
15 import sys
16
17 from debian import debfile
18
19 def is_cron(fname):
20 return re.match(r'^etc/cron\.(d|daily|hourly|monthly|weekly)\b', fname)
21
22 if __name__ == '__main__':
23 if not sys.argv[1:]:
24 print("Usage: extract_cron DEB ...")
25 sys.exit(1)
26
27 for fname in sys.argv[1:]:
28 deb = debfile.DebFile(fname)
29 cron_files = filter(is_cron, list(deb.data))
30 for cron_file in cron_files:
31 print('Extracting cron-related file %s ...' % cron_file)
32 path = os.path.join('.', cron_file)
33 dir = os.path.dirname(path)
34 if not os.path.exists(dir):
35 os.mkdir(dir)
36 with open(path, 'w') as out:
37 out.write(deb.data.get_content(cron_file))
38