diff --git a/psa b/psa index d598907..76e29ae 100755 --- a/psa +++ b/psa @@ -1,4 +1,6 @@ -#!/usr/bin/python +#!/usr/bin/env python +# -*- coding: 'utf-8' -*- + # This file is part of the PySide project. # # Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). @@ -51,6 +53,7 @@ import tempfile import subprocess import glob import pwd +import fileinput from contextlib import contextmanager from ConfigParser import ConfigParser @@ -439,8 +442,7 @@ class DebProject(QmlProject): cmd = 'python setup.py --command-packages=stdeb.command sdist_dsc' args = cmd.split() - execute_with_log(args, 'sdist-dsc.log', - on_error=BuildError('Failed to build initial package.')) + execute_with_log(args, 'sdist-dsc.log', on_error=BuildError('Failed to build initial package.')) # store packaging directory files = os.listdir(os.path.join(self.projectdir, 'deb_dist')) @@ -698,6 +700,11 @@ class Harmattan(DebProject): '''Overriden from DebProject''' abs_debfile = super(Harmattan, self).execute_build() + # rename deb file to reflect target architecture + if subprocess.call(['mv', os.path.join(self.projectdir, 'deb_dist', abs_debfile), os.path.join(self.projectdir, 'deb_dist', abs_debfile[:-10] + '_armel.deb')]): + raise BuildError('Failed to repackage.') + abs_debfile = abs_debfile[:-10] + '_armel.deb' + self.add_credentials(abs_debfile) def add_credentials(self, abs_debfile): @@ -714,6 +721,26 @@ class Harmattan(DebProject): if not os.path.isfile(os.path.join(abs_tempdir, 'DEBIAN', 'control')): raise BuildError('Failed to find the control file for icon insertion') + # optify package + if subprocess.call(['mv', os.path.join(abs_tempdir, 'usr', 'bin'), os.path.join(abs_tempdir, 'opt', self.slug)]): + raise BuildError('Failed to optify the package') + if subprocess.call(['mkdir', '-p', os.path.join(abs_tempdir, 'opt', 'usr', 'share')]): + raise BuildError('Failed to optify the package') + if subprocess.call(['mv', os.path.join(abs_tempdir, 'usr', 'share', 'pyshared'), os.path.join(abs_tempdir, 'opt', 'usr', 'share')]): + raise BuildError('Failed to optify the package') + if subprocess.call(['mv', os.path.join(abs_tempdir, 'usr', 'share', 'python-support'), os.path.join(abs_tempdir, 'opt', 'usr', 'share')]): + raise BuildError('Failed to optify the package') + + checksum_file = os.path.join(abs_tempdir, 'DEBIAN', 'md5sums') + with open(checksum_file, 'r') as f: + fcontent = f.read() + + fcontent = fcontent.replace('usr/bin/', 'opt/' + self.slug + '/bin/') + fcontent = fcontent.replace('usr/share/pyshared/', 'opt/usr/share/pyshared/') + fcontent = fcontent.replace('usr/share/python-support/', 'opt/usr/share/python-support/') + with open(checksum_file, 'w') as f: + f.write(fcontent) + self.create_digsums(abs_tempdir) if subprocess.call(['fakeroot', 'dpkg', '-b', abs_tempdir, abs_debfile]): @@ -804,6 +831,58 @@ class Fremantle(DebProject): DebProject.pre_build(self) self.check_py25() + def execute_build(self): + '''Overriden from DebProject''' + + abs_debfile = super(Fremantle, self).execute_build() + + # rename deb file to reflect target architecture + if subprocess.call(['mv', os.path.join(self.projectdir, 'deb_dist', abs_debfile), os.path.join(self.projectdir, 'deb_dist', abs_debfile[:-10] + '_armel.deb')]): + raise BuildError('Failed to repackage.') + abs_debfile = abs_debfile[:-10] + '_armel.deb' + + self.optify(abs_debfile) + + def optify(self, abs_debfile): + '''changes directory structure''' + abs_tempdir = tempfile.mkdtemp(prefix='psatmp') + + try: + if subprocess.call(['dpkg', '-x', abs_debfile, abs_tempdir]): + raise BuildError('Failed to extract the deb file for icon insertion') + + if subprocess.call(['dpkg-deb', '--control', abs_debfile, os.path.join(abs_tempdir, 'DEBIAN')]): + raise BuildError('Failed to extract the control file for icon insertion') + + if not os.path.isfile(os.path.join(abs_tempdir, 'DEBIAN', 'control')): + raise BuildError('Failed to find the control file for icon insertion') + + # optify package + if subprocess.call(['mv', os.path.join(abs_tempdir, 'usr', 'bin'), os.path.join(abs_tempdir, 'opt', self.slug)]): + raise BuildError('Failed to optify the package') + if subprocess.call(['mkdir', '-p', os.path.join(abs_tempdir, 'opt', 'usr', 'share')]): + raise BuildError('Failed to optify the package') + if subprocess.call(['mv', os.path.join(abs_tempdir, 'usr', 'share', 'pyshared'), os.path.join(abs_tempdir, 'opt', 'usr', 'share')]): + raise BuildError('Failed to optify the package') + if subprocess.call(['mv', os.path.join(abs_tempdir, 'usr', 'share', 'python-support'), os.path.join(abs_tempdir, 'opt', 'usr', 'share')]): + raise BuildError('Failed to optify the package') + + checksum_file = os.path.join(abs_tempdir, 'DEBIAN', 'md5sums') + with open(checksum_file, 'r') as f: + fcontent = f.read() + + fcontent = fcontent.replace('usr/bin/', 'opt/' + self.slug + '/bin/') + fcontent = fcontent.replace('usr/share/pyshared/', 'opt/usr/share/pyshared/') + fcontent = fcontent.replace('usr/share/python-support/', 'opt/usr/share/python-support/') + with open(checksum_file, 'w') as f: + f.write(fcontent) + + if subprocess.call(['fakeroot', 'dpkg', '-b', abs_tempdir, abs_debfile]): + raise BuildError('Failed to repackage.') + + finally: + shutil.rmtree(abs_tempdir) + def check_py25(self): '''Is python 2.5 available?''' try: diff --git a/templates/fremantle/setup.py.template b/templates/fremantle/setup.py.template index 64dd2bc..5fdc831 100644 --- a/templates/fremantle/setup.py.template +++ b/templates/fremantle/setup.py.template @@ -13,4 +13,4 @@ setup(name="${PROJECT}", long_description=read('${PROJECT}.longdesc'), data_files=[('share/applications/hildon',['${PROJECT}.desktop']), ('share/icons', ['${PROJECT}.png']), - ('/opt/usr/share/${PROJECT}/qml', glob.glob('qml/*.qml')), ],) + ('/opt/${PROJECT}/qml', glob.glob('qml/*.qml')), ],) diff --git a/templates/fremantle/templateproject.desktop.template b/templates/fremantle/templateproject.desktop.template index cba0d88..4354dec 100644 --- a/templates/fremantle/templateproject.desktop.template +++ b/templates/fremantle/templateproject.desktop.template @@ -4,7 +4,7 @@ Version=1.0 Type=Application Terminal=false Name=${APPNAME} -Exec=/usr/bin/${PROJECT} +Exec=/opt/${PROJECT}/bin/${PROJECT} Icon=${PROJECT} X-Window-Icon= X-HildonDesk-ShowInToolbar=true diff --git a/templates/fremantle/templateproject.template b/templates/fremantle/templateproject.template index 0d0a909..08d3478 100755 --- a/templates/fremantle/templateproject.template +++ b/templates/fremantle/templateproject.template @@ -15,8 +15,8 @@ def main(): engine = view.engine() engine.quit.connect(sys.exit) - if os.path.exists('/opt/usr/share/${PROJECT}/qml'): - view.setSource('/opt/usr/share/${PROJECT}/qml/main.qml') + if os.path.exists('/opt/${PROJECT}/qml'): + view.setSource('/opt/${PROJECT}/qml/main.qml') else: view.setSource(os.path.join('qml','main.qml')) diff --git a/templates/harmattan/setup.py.template b/templates/harmattan/setup.py.template index 2b96df8..d72c97d 100644 --- a/templates/harmattan/setup.py.template +++ b/templates/harmattan/setup.py.template @@ -11,6 +11,6 @@ setup(name="${PROJECT}", maintainer_email="${EMAIL}", description="${DESC}", long_description=read('${PROJECT}.longdesc'), - data_files=[('share/applications',['${PROJECT}.desktop']), - ('share/icons/hicolor/64x64/apps', ['${PROJECT}.png']), - ('share/${PROJECT}/qml', glob.glob('qml/*.qml')), ],) + data_files=[('/usr/share/applications',['${PROJECT}.desktop']), + ('/usr/share/icons/hicolor/64x64/apps', ['${PROJECT}.png']), + ('/opt/${PROJECT}/qml', glob.glob('qml/*.qml')), ],) diff --git a/templates/harmattan/templateproject.desktop.template b/templates/harmattan/templateproject.desktop.template index 435985d..91f12b0 100644 --- a/templates/harmattan/templateproject.desktop.template +++ b/templates/harmattan/templateproject.desktop.template @@ -3,6 +3,6 @@ Encoding=UTF-8 Version=1.0 Type=Application Name=${APPNAME} -Exec=invoker --single-instance --type=e /usr/bin/${PROJECT} +Exec=invoker --single-instance --type=e /opt/${PROJECT}/bin/${PROJECT} Icon=/usr/share/icons/hicolor/64x64/apps/${PROJECT}.png Categories=${CATEGORY}; diff --git a/templates/harmattan/templateproject.template b/templates/harmattan/templateproject.template index 05bdde6..e7f916b 100755 --- a/templates/harmattan/templateproject.template +++ b/templates/harmattan/templateproject.template @@ -18,8 +18,8 @@ def main(): glw = QtOpenGL.QGLWidget() view.setViewport(glw) - if os.path.exists('/usr/share/${PROJECT}/qml'): - view.setSource('/usr/share/${PROJECT}/qml/main.qml') + if os.path.exists('/opt/${PROJECT}/qml'): + view.setSource('/opt/${PROJECT}/qml/main.qml') else: view.setSource(os.path.join('qml','main.qml')) diff --git a/tests/psa_commands_test.py b/tests/psa_commands_test.py index 6277e5f..948080d 100644 --- a/tests/psa_commands_test.py +++ b/tests/psa_commands_test.py @@ -186,8 +186,10 @@ def testInitCommandParameters(self): class BuildTest(PySideAssistantCommandsTest): + template = '' def init_project(self, project, templatename): + self.template = templatename with working_directory(self.path): command = 'psa init %s %s > /dev/null' % (project, templatename) self.runShellCommand(command) @@ -195,7 +197,10 @@ def init_project(self, project, templatename): return os.path.join(self.path, project) def build_deb(self, project, path): - expected_deb = os.path.join(path, 'deb_dist', ('%s_0.1.0-1_all.deb' % project)) + if (self.template == 'harmattan') or (self.template == 'fremantle'): + expected_deb = os.path.join(path, 'deb_dist', ('%s_0.1.0-1_armel.deb' % project)) + else: + expected_deb = os.path.join(path, 'deb_dist', ('%s_0.1.0-1_all.deb' % project)) with working_directory(os.path.join(self.path, project)): command = 'psa build-deb > /dev/null' self.runShellCommand(command) @@ -264,11 +269,11 @@ def testBuildHarmattan(self): deb_contents['root'].append('./_aegis') deb_contents['control'].append('./digsigsums') - deb_contents['data'].append('./usr/bin/%s' % project) + deb_contents['data'].append('./opt/%s/bin/%s' % (project, project)) deb_contents['data'].append('./usr/share/applications/%s.desktop' % project) deb_contents['data'].append('./usr/share/icons/hicolor/64x64/apps/%s.png' % project) - deb_contents['data'].append('./usr/share/%s/qml/main.qml' % project) - deb_contents['data'].append('./usr/share/%s/qml/MainPage.qml' % project) + deb_contents['data'].append('./opt/%s/qml/main.qml' % project) + deb_contents['data'].append('./opt/%s/qml/MainPage.qml' % project) self.check_deb_contents(deb, deb_contents) @@ -281,10 +286,10 @@ def testBuildFremantle(self): deb_contents = self.base_debian_components() - deb_contents['data'].append('./usr/bin/%s' % project) + deb_contents['data'].append('./opt/%s/bin/%s' % (project, project)) deb_contents['data'].append('./usr/share/applications/hildon/%s.desktop' % project) deb_contents['data'].append('./usr/share/icons/%s.png' % project) - deb_contents['data'].append('./opt/usr/share/%s/qml/main.qml' % project) + deb_contents['data'].append('./opt/%s/qml/main.qml' % project) self.check_deb_contents(deb, deb_contents)