Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/desktopbuild.py
blob: 169202026d8236ef85c8484072481260228be02c (plain)
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2012 S. Daniel Francis <francis@sugarlabs.org>
#
# 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.

import sys
import os
sys.path.append(os.path.abspath('.'))
os.environ['INFO_L10N'] = '0'
import tarfile
import info

ignore_ends = ['.pyc',
               '~',
               '.git',
               '.gitignore',
               '.gitmodules']
ignores = ['makescripts/activity_luncher.py',
           'makescripts/xobuild.py',
           'sugar',
           'activity',
           'mimetypes.xml',
           'mimetype.png',
           info.lower_name + '.desktop',
           info.lower_name + '.png',
#           'data/appicon.svg', # Comment this line if you feel it's necessary.
           'activity.py']
if info.file_filter_mime:
    ignores.append(info.file_filter_mime.replace('/', '-') + '.xml')
manifest = []


def validate(path):
    """Validate - Checks in the ignored files and ends"""
    if path in ignores:
        return False
    for i in ignore_ends:
        if path[-len(i):] == i:
            return False
    return True


def packdir(path, newpath=None):
    for i in os.listdir(path):
        filepath = os.path.join(path, i)
        filename = filepath[2:]
        if validate(filename):
            if os.path.isdir(filepath):
                if filename == 'desktop':
                    for name in os.listdir(filepath):
                        new_filepath = os.path.join(filepath, name)
                        new_filename = new_filepath[2:]
                        if validate(new_filename):
                            packdir(new_filepath, os.path.join(newpath, name))
                else:
                    if newpath:
                        packdir(filepath, os.path.join(newpath, filename))
                    else:
                        packdir(filepath)
            else:
                new_path = list(os.path.split(filename))
                if newpath:
                    global new_path
                    if newpath != '.':
                        new_path[0] = newpath
                manifest.append((filename, '/'.join(new_path)))
                print '%s listed to pack' % filename

packdir('./', '%s-%s' % (info.lower_name, info.version))

tar = tarfile.open('./%s-%s.tgz' % (info.lower_name,
                                         info.version), 'w:gz')
for name, path in manifest:
    tar.add(name, path)
    print 'Packed %s as %s' % (name, path)
tar.close()