# Copyright (C) 2012-2013 S. Daniel Francis # # 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 tarfile import info import logging bundle_name = 'dist/%s-%s.tar.gz' % (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'] ignores = ['makescripts/activity_luncher.py', 'makescripts/xobuild.py', 'dist', 'sugar', 'activity/activity.info', 'activity/activity-graph-plotter.svg', 'activity/mimetypes.xml', '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): 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-%s' % (info.lower_name, info.version)) tar = tarfile.open(bundle_name, 'w:gz') for name, path in manifest: tar.add(name, path) logger.info('Packed %s as %s' % (name, path)) tar.close() logger.info('Closing log file') print "Closed log file"