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

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
# this is part of langpack-o-matic, by Martin Pitt <martin.pitt@canonical.com>

# (C) 2005 Canonical Ltd.

import os.path, os, gzip

def make_pkg(skeleton, path, lpmacros, extra_tar = None): 
    '''Create a new source package from a skeleton for a specific locale and
    class and subsitute all macros using the given LangpackMacros object. 
    
    If the package already exists, then only the changelog is updated. The
    "cls" parameter specifies the desired package class (kde, gnome, or empty
    string for the "all other stuff" language pack). The source package path is
    appended to "updated-packages" (if not already present).

    If a file name extra_tar is given, the file is installed into
    data/extra.tar.
    '''

    if os.path.isdir(path):
        print "Updating source package %s from skeleton %s" % (path, skeleton)
        _update_pkg(skeleton, path, lpmacros)
    else:
        print "Creating source package %s from skeleton %s" % (path, skeleton)
        _create_pkg(skeleton, path, lpmacros)

    # add package to updated-packages
    if not os.path.exists('updated-packages') or path not in [l.strip() for l
        in open('updated-packages')]:
        print >> open('updated-packages', 'a'), path

    # Refresh upgrade notes
    notedir = os.path.join(path, 'debian', 'upgrade-notes')
    if os.path.isdir(notedir) and not lpmacros['CLASS']:
	for f in os.listdir('upgrade-notes'):
	    # ignore .arch-ids and other stuff
	    if f[0] == '.':
		continue
	    # copy file, substitute macros
	    content = open(os.path.join('upgrade-notes',f)).read()
	    content = lpmacros.subst_string(content)
	    open(os.path.join(notedir,f), 'w').write(content)

    # Install extra tarball
    if extra_tar:
        target = os.path.join(path, 'data', 'extra.tar')
        if extra_tar.endswith('.gz'):
            tardata = gzip.open(extra_tar).read()
        else:
            tardata = open(extra_tar).read()
        open(target, 'w').write(tardata)

def _create_pkg(skel, dest, lpmacros):
    # copy skel files, omitting hidden files
    for path, dirs, files in os.walk(skel):
        if os.path.basename(path)[0] == '.':
            continue
        destdir = os.path.join(dest, os.path.sep.join(path.split(os.path.sep)[1:]))
        os.makedirs(destdir)
        for f in files:
            if f[0] == '.':
                continue
            # copy file, substitute macros
            content = open(os.path.join(path,f)).read()
            content = lpmacros.subst_string(content)
            open(os.path.join(destdir,f), 'w').write(content)

def _update_pkg(skel, dest, lpmacros):
    # copy control files (but changelog) again, in case they have changed
    srcdir = os.path.join(skel, 'debian')
    destdir = os.path.join(dest, 'debian')
    for f in os.listdir(srcdir):
        if f[0] == '.' or f == 'changelog':
            continue

        # copy file, substitute macros
	src = os.path.join(srcdir,f)
	if os.path.isfile(src):
	    content = open(src).read()
	    content = lpmacros.subst_string(content)
	    open(os.path.join(destdir,f), 'w').write(content)

    # call dch to update changelog
    cwd = os.getcwd()
    os.chdir(dest)
    result = os.spawnlpe(os.P_WAIT, 'dch', 'dch', '-v', 
	'1:%s+%s' % (lpmacros['RELEASEVERSION'], lpmacros['TIMESTAMP']),
        '-p', '-D', lpmacros['RELEASE'], 
        'Automatic update to latest translation data.',
        {'DEBEMAIL': lpmacros['UPLOADER']})
    os.chdir(cwd)

    if result != 0:
        raise Exception, 'dch failed'