1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
#!/usr/bin/python
# Copyright 2011 Lars Wirzenius
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import cliapp
import logging
import os
import subprocess
import time
class PbuilderCreate(cliapp.Application):
def add_settings(self):
self.settings.string(['mirror', 'm'],
'use URL for mirror (%default)',
metavar='URL',
default='http://cdn.debian.net/debian')
self.settings.string_list(['release', 'r'],
'build tgz for RELEASE (%default)',
metavar='RELEASE',
default=['unstable'])
arch = self.runcmd(['dpkg', '--print-architecture']).strip()
self.settings.string_list(['arch', 'a'],
'build tgz for ARCH (%default)',
metavar='ARCH', default=[arch])
self.settings.string_list(['othermirror', 'o'],
'also build tgz with pbuilder '
'--othermirror, set to empty to avoid '
'this (%default)')
self.settings.integer(['max-age'],
'trigger tgz update if older than N days '
'(%default)',
metavar='N', default=1)
self.settings.boolean(['no-act', 'dry-run'], 'just pretend')
self.settings.boolean(['verbose'], 'print commands before executing')
self.settings.string(['directory', 'd'],
'where to put tgz files (%default)',
default='/var/cache/pbuilder')
def process_args(self, args):
for release in self.settings['release']:
for arch in self.settings['arch']:
self.pbuilder(release, arch, 'pristine', None)
if self.settings['othermirror']:
self.pbuilder(release, arch, 'custom',
self.settings['othermirror'])
def pbuilder(self, release, arch, suffix, othermirror):
tgz = self.tgz(release, arch, suffix)
if os.path.exists(tgz):
if not self.need_to_update_tgz(tgz):
return
argv = ['pbuilder',
'--update',
'--basetgz', tgz,
'--logfile', tgz + '.log']
else:
argv = ['pbuilder',
'--create',
'--mirror', self.settings['mirror'],
'--architecture', arch,
'--distribution', release,
'--basetgz', tgz,
'--logfile', tgz + '.log']
for x in othermirror or []:
argv += ['--othermirror', x]
if self.settings['verbose']:
print ' '.join(argv)
if self.settings['no-act']:
return
self.runcmd(argv)
def need_to_update_tgz(self, tgz):
mtime = os.path.getmtime(tgz)
now = time.time()
max_age_secs = self.settings['max-age'] * 24 * 60 * 40
return mtime <= now - max_age_secs
def tgz(self, release, arch, suffix):
basename = '%s-%s-%s.tgz' % (release, arch, suffix)
return os.path.join(self.settings['directory'], basename)
if __name__ == '__main__':
PbuilderCreate().run()
|