Skip to content

Fixed bug #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 82 additions & 3 deletions psa
Original file line number Diff line number Diff line change
@@ -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).
Expand Down Expand Up @@ -51,6 +53,7 @@ import tempfile
import subprocess
import glob
import pwd
import fileinput

from contextlib import contextmanager
from ConfigParser import ConfigParser
Expand Down Expand Up @@ -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'))
Expand Down Expand Up @@ -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):
Expand All @@ -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]):
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion templates/fremantle/setup.py.template
Original file line number Diff line number Diff line change
Expand Up @@ -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')), ],)
2 changes: 1 addition & 1 deletion templates/fremantle/templateproject.desktop.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions templates/fremantle/templateproject.template
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand Down
6 changes: 3 additions & 3 deletions templates/harmattan/setup.py.template
Original file line number Diff line number Diff line change
Expand Up @@ -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')), ],)
2 changes: 1 addition & 1 deletion templates/harmattan/templateproject.desktop.template
Original file line number Diff line number Diff line change
Expand Up @@ -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};
4 changes: 2 additions & 2 deletions templates/harmattan/templateproject.template
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand Down
17 changes: 11 additions & 6 deletions tests/psa_commands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,21 @@ 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)

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)
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down