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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
#!/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('.'))
if not os.path.exists('./dist'):
os.mkdir('./dist')
os.environ['INFO_L10N'] = '0'
import zipfile
import info
import logging
bundle_name = 'dist/%s-%s.xo' % (info.name.replace(' ', ''), info.version)
log_file = '%s.log' % bundle_name
if os.path.exists(log_file):
os.remove(log_file)
logging.basicConfig(filename=log_file, level=logging.DEBUG)
print "Started log in %s" % log_file
logger = logging.getLogger('xo-bundler')
import time
logger.debug('Log started on %s' % time.strftime('%c'))
ignore_ends = ['.pyc',
'~',
'.git',
'.gitignore',
'.gitmodules',
'.xo']
ignores = ['makescripts',
'dist'
'Makefile',
'install',
'desktop',
'install',
'mimetypes.xml',
'mimetype.png',
info.lower_name,
info.lower_name + '.desktop',
info.lower_name + '.png',
'data/appicon.svg', # Comment this line if you feel it's necessary.
'application.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 == 'sugar':
for name in os.listdir(filepath):
new_filepath = os.path.join(filepath, name)
new_filename = new_filepath[2:]
if validate(new_filename):
if os.path.isfile(new_filepath):
new_path = list(os.path.split(
new_filename))
if newpath:
global new_path
if newpath != '.':
new_path[0] = newpath
manifest.append((new_filepath,
'/'.join(new_path)))
print '%s listed to pack' % filename
else:
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:
if newpath != '.':
new_path[0] = newpath
manifest.append((filename, '/'.join(new_path)))
logger.info('%s listed to pack' % filename)
packdir('./', '%s.activity' % info.name.replace(' ', ''))
xofile = zipfile.ZipFile(bundle_name, 'w')
for name, path in manifest:
xofile.write(name, path)
logger.info('Packed %s as %s' % (name, path))
xofile.close()
logger.info('Closing log file')
print "Closed log file"
|