~ubuntu-langpack/langpack-o-matic/main

« back to all changes in this revision

Viewing changes to lib/static_translations.py

  • Committer: Martin Pitt
  • Date: 2011-03-14 13:07:20 UTC
  • Revision ID: martin.pitt@canonical.com-20110314130720-4q5tjhwr7od8zhfd
use logging module instead of bare print, and make remaining print statements Python 3 friendly

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
3
3
import tempfile, atexit, shutil, urllib, os.path, os, subprocess
 
4
import logging
4
5
import tarfile
5
6
 
6
7
from macros import _file_map
92
93
    unpack_dir = tempfile.mkdtemp('.')
93
94
 
94
95
    try:
95
 
        print 'fetching tarballs...'
 
96
        logging.debug('fetching tarballs...')
96
97
        for t in tarball_urls:
97
 
            print '    ', t
 
98
            logging.debug('    ' + t)
98
99
            (dest, _) = urllib.urlretrieve(t)
99
100
            assert subprocess.call(['tar', '-C', unpack_dir, '-xzf', dest]) == 0
100
101
            if t != dest:
101
102
                os.unlink(dest)
102
103
 
103
104
        # rename to *-langpack
104
 
        print 'renaming to *-langpack...'
 
105
        logging.debug('renaming to *-langpack...')
105
106
        for (root, dirs, _) in os.walk(unpack_dir):
106
107
            if root.endswith('/gnome') and 'help' in dirs:
107
108
                os.rename(os.path.join(root, 'help'),
113
114
 
114
115
        # sort files into langpack buckets
115
116
        map = {}
116
 
        print 'sorting static files per language pack...'
 
117
        logging.debug('sorting static files per language pack...')
117
118
        for (root, dirs, files) in os.walk(unpack_dir):
118
119
            root = root[len(unpack_dir)+1:]
119
120
            comps = root.split(os.path.sep)
134
135
 
135
136
        # create static.tar.gz
136
137
        for pkgname, files in map.iteritems():
137
 
            print 'creating %s.tar...' % pkgname
 
138
            logging.debug('creating %s.tar...' % pkgname)
138
139
            tar = tarfile.open(os.path.join(output_dir, pkgname + '.tar'), 'w')
139
140
            for f in files:
140
141
                tar.add(os.path.join(unpack_dir, f), f[f.index('/')+1:], False)
224
225
            # not automatically tested
225
226
            tarballs = get_static_translation_tarballs('maverick')
226
227
            for t in tarballs:
227
 
                print t
 
228
                print(t)
228
229
 
229
230
    unittest.main()