Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/automake.py
diff options
context:
space:
mode:
Diffstat (limited to 'automake.py')
-rw-r--r--automake.py300
1 files changed, 300 insertions, 0 deletions
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"
+