48
def init_apt(release):
49
tmpdir = tempfile.mkdtemp()
50
logging.debug('Created a temp directory at {}'.format(tmpdir))
51
rootdir = os.path.join(tmpdir, 'etc', 'apt')
53
logging.debug('Created apt temp directory at {}'.format(rootdir))
55
with open(os.path.join(rootdir, 'sources.list'), 'w+') as fp:
56
fp.write('deb http://archive.ubuntu.com/ubuntu {} main restricted\n'.format(release))
57
fp.write('deb-src http://archive.ubuntu.com/ubuntu {} main restricted\n'.format(release))
59
#sourceslist = SourcesList()
62
logging.info('Initializing cache...')
63
cache = apt.Cache(rootdir = tmpdir)
64
# Now, lets update the package list
65
logging.info('Updating cache...')
67
# We need to re-open the cache because it needs to read the package list
68
logging.info('Opening cache...')
72
#acquire = apt_pkg.Acquire()
47
74
def uses_intltool(template):
49
76
Given a dict containing a translations template with a
51
78
intltool, and False otherwise.
54
rootdir = tempfile.mkdtemp()
56
with open(rootdir + '/etc/apt/sources.list', 'w+') as fp:
59
sourceslist = SourcesList()
63
#acquire = apt_pkg.Acquire()
65
cache = apt.Cache(rootdir = rootdir)
66
# Now, lets update the package list
68
# We need to re-open the cache because it needs to read the package list
71
# TODO: fetch the source records from another release
81
#logging.info('Processing template {}'.format(template['template_name']))
73
82
sr = apt_pkg.SourceRecords()
75
84
src_package = template['sourcepackage']
85
#logging.info('Processing source package {}'.format(src_package))
76
86
if sr.lookup(src_package):
77
for k, v in sr.build_depends.items():
87
for v in sr.build_depends.values():
79
89
if dep[0][0] == 'intltool':
95
def write_templates():
97
with open(ubuntu_pots_listconfig.get_data_file('intltool_templates.json'), 'w') as fp:
98
json.dump(intltool_templates, fp)
101
def print_wiki_table(templates, release):
104
SRC_PKG_URL_BASE = 'https://launchpad.net/ubuntu/{0}/+source'.format(release)
105
POT_URL_BASE = 'https://translations.launchpad.net/ubuntu/{0}/+source'.format(release)
106
PROJECT_URL_BASE = 'https://launchpad.net'
107
HEADER = "|| '''Source Package''' || '''Template''' || '''Has upstream project''' || '''Upstream project owner''' || '''Has upstream link''' ||"
110
for row in templates:
111
print "|| [[{0}/{1}|{1}]] || [[{2}/{3}|{3}]] || [[{4}/{5}|{5}]] || [[{6}|{7}]] || [[{8}|{9}]]||".format(
113
row['sourcepackage'],
115
row['template_name'],
120
row['projectseries_link'],
121
row['projectseries_name'],
125
def iter_upstream_info(distroseries, templates):
126
for template in templates:
127
package = distroseries.getSourcePackage(name = template['sourcepackage'])
128
project_series = package.productseries
129
if project_series is None:
131
projectseries_name = None
132
projectseries_link = None
136
project = project_series.project
137
owner = project.owner
139
project_name = project.name
140
projectseries_name = project_series.name
141
projectseries_link = project_series.web_link
142
owner_name = owner.name
143
owner_link = owner.web_link
145
template['project_name'] = project_name
146
template['projectseries_name'] = projectseries_name
147
template['projectseries_link'] = projectseries_link
148
template['owner_name'] = owner_name
149
template['owner_link'] = owner_link
153
def get_upstream_info(series_name, templates):
154
logging.info('Logging into Launchpad...')
155
launchpad = Launchpad.login_anonymously(
156
'get_packaging', 'production', version='devel')
157
logging.info('Getting Ubuntu distro series...')
158
distroseries = launchpad.distributions['ubuntu'].getSeries(
159
name_or_version = series_name)
161
logging.info('Getting upstream info...')
162
return list(iter_upstream_info(distroseries, templates))
85
166
version = ubuntu_pots_listconfig.__version__
86
167
# Support for command line options.
90
171
help=_('Print the maximum debugging info (implies -vv)'))
91
172
parser.add_option('-v', '--verbose', dest='logging_level', action='count',
92
173
help=_('set error_level output to warning, info, and then debug'))
93
# exemple of silly CLI option
94
174
parser.add_option("-r", "--release", action="store", dest="release",
95
175
help=_("Release to get the list of templates from"))
96
176
parser.set_defaults(logging_level = 0,
114
194
active_templates = [pot for pot in templates if pot['enabled']]
116
196
# Find out which templates depend on intltool and return a sorted list
198
logging.info('Finding out intltool templates...')
117
199
intltool_templates = filter(uses_intltool, active_templates)
118
200
intltool_templates = sorted(intltool_templates, key = itemgetter('priority'), reverse = True)
119
logging.debug(len(intltool_templates))
121
with open(ubuntu_pots_listconfig.get_data_file('intltool_templates.json'), 'w') as fp:
122
json.dump(intltool_templates, fp)
124
SRC_PKG_URL_BASE = 'https://launchpad.net/ubuntu/{0}/+source'.format(options.release)
125
POT_URL_BASE = 'https://translations.launchpad.net/ubuntu/{0}/+source'.format(options.release)
126
print "|| '''Source Package''' || '''Template''' || '''Has upstream project''' || '''Upstream project owner''' || '''Has upstream link''' ||"
127
for row in intltool_templates:
128
print "|| [[{1}/{0}|{0}]] || [[{3}/{2}|{2}]] || {4} || {5} ||".format(row['sourcepackage'],
130
row['template_name'],
202
# Find out upstream info
203
intltool_templates = get_upstream_info(release, intltool_templates)
204
#print intltool_templates
207
print_wiki_table(intltool_templates, release)
137
210
if __name__ == "__main__":