Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Francis <francis@sugarlabs.org>2013-02-03 12:51:11 (GMT)
committer Daniel Francis <francis@sugarlabs.org>2013-02-03 12:51:11 (GMT)
commit5c19d2ddccc128b23c483f55df4a1fb2ee2ff011 (patch)
tree9912dd0cb406e331da4b890f2381e71d1fd3469a
parent770d1514740f6889ed77eee1b96fa8e234972a84 (diff)
Automake / Debian package builder
Signed-off-by: Daniel Francis <francis@sugarlabs.org>
-rw-r--r--application.desktop.in11
-rw-r--r--application.in33
-rw-r--r--automake.py300
-rw-r--r--configure.ac10
-rw-r--r--debian/control14
-rw-r--r--debian/copyright47
-rw-r--r--debianpackage.py68
7 files changed, 483 insertions, 0 deletions
diff --git a/application.desktop.in b/application.desktop.in
new file mode 100644
index 0000000..6585bb5
--- /dev/null
+++ b/application.desktop.in
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Name=@PKG_NAME@
+GenericName=@GEN_NAME@
+Comment=@DESCRIPTION@
+Exec=@PACKAGE@
+Icon=@datadir@/@PACKAGE@/appicon.svg
+Terminal=false
+Categories=@CATEGORIES@
+MimeType=@MIMETYPES@
+Type=Application
diff --git a/application.in b/application.in
new file mode 100644
index 0000000..c77bfa1
--- /dev/null
+++ b/application.in
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+#
+# Copyright 2012 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 2 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
+name = os.path.split(sys.argv[0])[-1]
+
+os.environ['DATADIR'] = os.path.join('@datadir@', name)
+os.environ['PROGRAMRUNNING'] = 'DESKTOP'
+os.environ['ICONDIR'] = os.path.join('@datadir@', '%s/icons' % name)
+os.environ['TRANSLATIONDIR'] = os.path.join('@datadir@', 'locale')
+os.environ['INFO_L10N'] = '1'
+os.chdir(os.path.join('@datadir@', name))
+os.system('python %s %s' %
+ (os.path.join('@datadir@', '%s/application.py' % name),
+ ('"%s"' % sys.argv[1:]) if len(sys.argv) > 1 else ''))
diff --git a/automake.py b/automake.py
new file mode 100644
index 0000000..a3c35b8
--- /dev/null
+++ b/automake.py
@@ -0,0 +1,300 @@
+#!/usr/bin/env python
+
+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 info
+
+import logging
+
+log_file = 'dist/automake.log'
+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'))
+
+logger.info('Creating directory')
+
+automake_dir = 'dist/automake'
+
+if os.path.exists(automake_dir):
+ os.system('rm -Rf %s' % automake_dir)
+os.mkdir(automake_dir)
+
+logger.info('Adding source files')
+
+src_dir = os.path.join(automake_dir, 'src')
+
+os.mkdir(src_dir)
+
+os.system('cp %s %s' % ('makescripts/application.in', os.path.join(src_dir, '%s.in' % info.lower_name)))
+os.system('cp -R desktop/sweetener* %s' % src_dir)
+
+src_ignores = [
+ 'style.css',
+ 'activity',
+ 'makescripts',
+ 'dist',
+ 'sugar',
+ 'desktop',
+ 'icons',
+ 'mimetypes.xml',
+ 'mimetype.png',
+ 'install',
+ 'setup.py',
+ info.lower_name,
+ info.lower_name + '.desktop',
+ info.lower_name + '.png',
+ 'data',
+ 'activity.py',
+ 'MAINTAINERS',
+ 'NEWS',
+ 'COPYING',
+ 'README',
+ 'Makefile',
+ 'po',
+ 'locale',
+ ]
+
+roots = [
+ 'README',
+ 'MAINTAINERS',
+ 'NEWS',
+ 'COPYING',
+ ]
+
+ignore_ends = [
+ '.pyc',
+ '~',
+ '.gitignore',
+ '.gitmodules',
+ '.git',
+ ]
+
+
+def validate(path):
+ """Validate - Checks in the ignored files and ends"""
+ logger.debug('Validating %s' % path)
+ if path in src_ignores:
+ logger.debug('Ignoring %s' % path)
+ return False
+ for i in ignore_ends:
+ if path.endswith(i):
+ logger.debug('Ignoring %s' % path)
+ return False
+ return True
+
+for i in os.listdir('.'):
+ if validate(i):
+ logger.debug('Copying %s' % i)
+ os.system('cp -R %s %s' % (i, src_dir))
+
+logger.info('Copying extra files')
+for i in roots:
+ if os.path.exists(i):
+ logger.debug('Copying %s' % i)
+ if i == 'MAINTAINERS':
+ output = os.path.join(automake_dir, 'AUTHORS')
+ else:
+ output = automake_dir
+ os.system('cp -R %s %s' % (i, output))
+ else:
+ logger.error('%s does not exist' % i)
+
+if os.path.exists('data'):
+ logger.info('Copying data')
+ os.system('cp -R data %s' % automake_dir)
+
+if os.path.exists('desktop/icons'):
+ os.system('cp -R desktop/icons %s' % automake_dir)
+
+logger.info('Generating desktop entry')
+desktop_input = open('makescripts/application.desktop.in', 'r')
+desktop_data = desktop_input.read()
+desktop_input.close()
+desktop_data = desktop_data.replace('@PKG_NAME@', info.name)
+desktop_data = desktop_data.replace('@GEN_NAME@', info.generic_name)
+desktop_data = desktop_data.replace('@DESCRIPTION@', info.description)
+desktop_data = desktop_data.replace('@PACKAGE@', info.lower_name)
+desktop_data = desktop_data.replace('@CATEGORIES@', ';'.join(info.categories))
+desktop_data = desktop_data.replace('@MIMETYPES@', info.file_filter_mime + ';')
+desktop_output = open(os.path.join(automake_dir, info.lower_name + '.desktop.in'), 'w')
+desktop_output.write(desktop_data)
+desktop_output.close()
+
+logger.info('Cleaning ignorable files')
+
+def clean_dir(path):
+ logger.debug('Cleaning directory %s' % path)
+ for i in os.listdir(path):
+ logger.debug('Checking %s' % i)
+ i_path = os.path.join(path, i)
+ if os.path.isdir(i_path):
+ clean_dir(i_path)
+ else:
+ for end in ignore_ends:
+ if i.endswith(end):
+ logger.debug('Cleaning %s' % i)
+ os.system('rm -Rf %s' % i_path)
+
+clean_dir(automake_dir)
+
+logger.info('Setting up autotools')
+
+makefiles = []
+
+logger.debug('Creating root Makefile.am')
+
+subdirs = []
+for i in ['src', 'data', 'icons']:
+ path = os.path.join(automake_dir, i)
+ if os.path.exists(path):
+ subdirs.append(i)
+
+root_makefile = open(os.path.join(automake_dir, 'Makefile.am'), 'w')
+content = [
+ 'copyingdir = $(datadir)/%s' % info.lower_name,
+ 'copying_DATA = COPYING',
+ 'desktopdir = $(datadir)/applications',
+ 'desktop_DATA = %s.desktop' % info.lower_name,
+ 'SUBDIRS = %s' % ' '.join(subdirs),
+ 'do_substitution = sed -e "s,[@]datadir[@],$(datadir),g"',
+ '{entry}: {entry}.in'.format(entry=info.lower_name+'.desktop'),
+ '\t$(do_substitution) < {entry}.in > {entry}'.format(entry='%s.desktop' % info.lower_name),
+ '',
+ 'EXTRA_DIST = %s.desktop.in' % info.lower_name,
+ 'UPDATE_DESKTOP = update-desktop-database $(datadir)/applications || :',
+ '',
+ 'install-data-hook:',
+ '\t$(UPDATE_DESKTOP)',
+ 'uninstall-hook:',
+ '\t$(UPDATE_DESKTOP)',
+ '']
+root_makefile.write('\n'.join(content))
+root_makefile.close()
+
+makefiles.append('Makefile')
+
+logger.debug('Creating src Makefile.am')
+
+subdirs = []
+files = []
+
+for i in os.listdir(src_dir):
+ path = os.path.join(automake_dir, 'src', i)
+ if os.path.isdir(path):
+ subdirs.append(i)
+ else:
+ if i != '%s.in' % info.lower_name:
+ files.append(i)
+
+content = []
+if subdirs:
+ content.append('SUBDIRS = %s' % ' '.join(subdirs))
+content.append('bin_SCRIPTS = %s' % info.lower_name)
+content.append(
+ 'modulesdir = {dest}'.format(dest='$(datadir)/%s' % info.lower_name))
+content.append(
+ 'modules_DATA = {files}'.format(files=' \\\n\t'.join(files)))
+content.append('CLEANFILES = $(bin_SCRIPTS)')
+content.append('EXTRA_DIST = %s.in $(modules_DATA)' % info.lower_name)
+content.append(
+ 'do_substitution = sed -e "s,[@]datadir[@],$(datadir),g"')
+content.append(
+ '{lower_name}: {lower_name}.in Makefile'.format(lower_name=info.lower_name))
+content.append(
+ '\t$(do_substitution) < $(srcdir)/{lower_name}.in > {lower_name}'.format(
+ lower_name=info.lower_name))
+content.append('\tchmod +x %s' % info.lower_name)
+content.append('')
+
+makefiles.append('src/Makefile')
+
+def create_makefile(path, destination):
+ logger.debug('Creating %s Makefile.am' % path)
+ subdirs = []
+ files = []
+ full_path = os.path.join(automake_dir, path)
+ for i in os.listdir(full_path):
+ i_path = os.path.join(full_path, i)
+ if os.path.isdir(i_path):
+ subdirs.append(i)
+ else:
+ files.append(i)
+
+ content = []
+ if subdirs:
+ content.append('SUBDIRS = %s' % ' '.join(subdirs))
+ basename = os.path.basename(path)
+ basename = basename if basename != 'data' else 'share'
+ content.append(
+ '{dir}dir = {dest}'.format(dir=basename,
+ dest=destination))
+ content.append(
+ '{dir}_DATA = {files}'.format(dir=basename,
+ files=' \\\n\t'.join(files)))
+ content.append('EXTRA_DIST = $({dir}_DATA)'.format(dir=basename))
+ content.append('')
+ subdir_makefile = open(os.path.join(full_path, 'Makefile.am'), 'w')
+ subdir_makefile.write('\n'.join(content))
+ subdir_makefile.close()
+ makefiles.append(os.path.join(path, 'Makefile'))
+
+ for i in subdirs:
+ create_makefile(os.path.join(path, i), os.path.join(destination, i))
+
+for i in subdirs:
+ create_makefile(os.path.join('src', i),
+ '$(datadir)/%s/%s' % (info.lower_name, i))
+
+src_makefile = open(os.path.join(src_dir, 'Makefile.am'), 'w')
+src_makefile.write('\n'.join(content))
+src_makefile.close()
+
+if os.path.exists(os.path.join(automake_dir, 'data')):
+ create_makefile('data', '$(datadir)/%s' % info.lower_name)
+
+if os.path.exists(os.path.join(automake_dir, 'icons')):
+ create_makefile('icons', '$(datadir)/%s/icons' % info.lower_name)
+
+
+logger.debug('Generating configure.ac')
+configure_ac = open('makescripts/configure.ac', 'r')
+configure = configure_ac.read()
+configure_ac.close()
+
+autoconfigure = open(os.path.join(automake_dir, 'configure.ac'), 'w')
+autoconfigure.write(configure.format(name=info.name, version=info.version,
+ makefiles='\n'.join(makefiles)))
+autoconfigure.close()
+
+logger.debug('Touching files')
+for i in ['ChangeLog', 'AUTHORS', 'NEWS', 'README']:
+ os.system('touch %s/%s' % (automake_dir, i))
+
+bundle_path = os.environ['PWD']
+os.chdir(automake_dir)
+os.system('aclocal')
+os.system('autoconf')
+os.system('automake --add-missing')
+os.system('./configure')
+os.system('make dist')
+bundle_name = '%s-%s.tar.gz' % (info.lower_name, info.version)
+os.system('mv %s ../' % bundle_name)
+os.chdir(bundle_path)
+
+print "Tarball generated at", os.path.join('dist', bundle_name)
+logger.info('Closing log file')
+print "Closed log file"
+
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..14c1021
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,10 @@
+AC_INIT([{name}], [{version}])
+
+AM_INIT_AUTOMAKE
+AM_PATH_PYTHON([2.7])
+
+AC_CONFIG_FILES([
+{makefiles}
+])
+
+AC_OUTPUT
diff --git a/debian/control b/debian/control
new file mode 100644
index 0000000..9ab73e6
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,14 @@
+Source: {lower_name}
+Section: education
+Priority: extra
+Maintainer: {maintainer}
+Build-Depends: debhelper (>= 8.0.0), autotools-dev
+Standards-Version: 3.9.3
+Homepage: {url}
+Vcs-Git: {git}
+Vcs-Browser: {git_browser}
+
+Package: {lower_name}
+Architecture: all
+Depends: {deb_depends}
+Description: {description}
diff --git a/debian/copyright b/debian/copyright
new file mode 100644
index 0000000..8b41d04
--- /dev/null
+++ b/debian/copyright
@@ -0,0 +1,47 @@
+Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+Upstream-Name: {upstream_name}
+
+Files: *
+Copyright: {copyright_note}
+License: GPL-3+
+ This package 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 package 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, see <http://www.gnu.org/licenses/>
+ .
+ On Debian systems, the complete text of the GNU General
+ Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
+
+# If you want to use GPL v2 or later for the /debian/* files use
+# the following clauses, or change it to suit. Delete these two lines
+Files: debian/*
+Copyright: 2013 {name}
+License: GPL-3+
+ This package 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 package 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, see <http://www.gnu.org/licenses/>
+ .
+ On Debian systems, the complete text of the GNU General
+ Public License version 2 can be found in "/usr/share/common-licenses/GPL-3".
+
+# Please also look if there are files or directories which have a
+# different copyright/license attached and list them here.
+# Please avoid to pick license terms that are more restrictive than the
+# packaged work, as it may make Debian's contributions unacceptable upstream.
diff --git a/debianpackage.py b/debianpackage.py
new file mode 100644
index 0000000..7e6d245
--- /dev/null
+++ b/debianpackage.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+
+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 info
+
+extracted_dir = '%s-%s' % (info.lower_name, info.version)
+tarball_name = '%s.tar.gz' % extracted_dir
+
+current_dir = os.environ['PWD']
+
+os.chdir('dist')
+
+if os.path.exists(extracted_dir):
+ os.system('rm -Rf %s' % extracted_dir)
+
+os.system('tar -xzf %s' % tarball_name)
+os.chdir(extracted_dir)
+os.system('dh_make -s -y -f ../%s' % tarball_name)
+os.chdir('debian')
+os.system('rm *ex *EX README*')
+
+debian_files = os.path.join(current_dir, 'makescripts', 'debian')
+input_control = open(os.path.join(debian_files, 'control'), 'r')
+control = input_control.read().format(
+ lower_name=info.lower_name,
+ maintainer='%s <%s>' % (os.environ['DEBFULLNAME'],
+ os.environ['DEBEMAIL']),
+ url=info.url,
+ git=info.git,
+ git_browser=info.git_browser,
+ deb_depends=', '.join(info.deb_depends),
+ description=info.description)
+input_control.close()
+output_control = open('control', 'w')
+output_control.write(control)
+output_control.close()
+
+input_copyright = open(os.path.join(debian_files, 'copyright'), 'r')
+copyright = input_copyright.read().format(
+ upstream_name=info.name,
+ name=os.environ['DEBFULLNAME'],
+ copyright_note=info.copyright_holder)
+input_copyright.close()
+output_copyright = open('copyright', 'w')
+output_copyright.write(copyright)
+output_copyright.close()
+
+input_changelog = open('changelog', 'r')
+changelog = input_changelog.read()
+changelog = changelog.replace(
+ 'Initial release (Closes: #nnnn) <nnnn is the bug number of your ITP>',
+ 'Package autogenerated with Sweetener')
+changelog = changelog.replace('unstable', 'precise')
+input_changelog.close()
+output_changelog = open('changelog', 'w')
+output_changelog.write(changelog)
+output_changelog.close()
+
+os.chdir('..')
+os.system('dpkg-buildpackage')