First stab at buildozer osx

This commit is contained in:
akshayaurora 2015-12-26 15:31:42 +05:30
parent 658a485e09
commit 45b3e10949
2 changed files with 256 additions and 0 deletions

View file

@ -158,6 +158,10 @@ class Buildozer(object):
self.info('Check requirements for {0}'.format(self.targetname))
self.target.check_requirements()
if self.targetname == 'osx':
self.target.build_package()
return
self.info('Install platform')
self.target.install_platform()

252
buildozer/targets/osx.py Normal file
View file

@ -0,0 +1,252 @@
'''
OSX target, based on kivy-sdk-packager
'''
import sys
if sys.platform != 'darwin':
raise NotImplementedError('This will only work on osx')
#Global variables
#Global imports
import traceback
import os
import io
from pipes import quote
from sys import platform, executable
from buildozer import BuildozerException
from buildozer import IS_PY3
from buildozer.target import Target
from os import environ
from os.path import (exists, join, realpath, expanduser,
basename, relpath, abspath, dirname)
from shutil import copyfile
from glob import glob
from subprocess import check_call, check_output
from buildozer.libs.version import parse
class TargetOSX(Target):
def ensure_sdk(self):
self.buildozer.info('Check if kivy-sdk-packager exists')
if exists(
join(self.buildozer.platform_dir, 'kivy-sdk-packager-master')):
self.buildozer.info(
'kivy-sdk-packager found at '\
'{}'.format(self.buildozer.platform_dir))
return
self.buildozer.info('kivy-sdk-packager does not exist, clone it')
platdir = self.buildozer.platform_dir
check_call(
('curl', '-O', '-L',
'https://github.com/kivy/kivy-sdk-packager/archive/master.zip'),
cwd=platdir)
check_call(('unzip', 'master.zip'), cwd=platdir)
check_call(('rm', 'master.zip'), cwd=platdir)
def ensure_kivyapp(self):
self.buildozer.info('check if Kivy.app exists in local dir')
kivy_app_dir = join(
self.buildozer.platform_dir,
'kivy-sdk-packager-master', 'osx')
if exists(join(kivy_app_dir, 'Kivy.app')):
self.buildozer.info('Kivy.app found at ' + kivy_app_dir)
return
# check if Kivy.app exists in /Applications
if not exists('/Applications/Kivy.app'):
# download kivy.app
#TODO: Fix ME
check_call(
"curl -O -L http://github.com/kivy/kivy/files/Kivy.app",
cwd=kivy_app_dir)
return
else:
self.buildozer.info('Kivy.app found at /Applications/Kivy.app')
self.buildozer.info('copying it to platform dir')
check_call(
('cp', '-a', '/Applications/Kivy.app',
join(kivy_app_dir, 'Kivy.app')))
return
def check_requirements(self):
self.ensure_sdk()
self.ensure_kivyapp()
def check_configuration_tokens(self, errors=None):
if errors:
self.buildozer.info('Check target configuration tokens')
self.buildozer.error(
'{0} error(s) found in the buildozer.spec'.format(
len(errors)))
for error in errors:
print(error)
exit(1)
# check
def build_package(self):
self.buildozer.info('Building package')
kivy_app_dir = join(
self.buildozer.platform_dir,
'kivy-sdk-packager-master', 'osx', 'Kivy.app')
bc = self.buildozer.config
bcg = bc.get
bcgl = bc.getlist
package_name = bcg('app', 'package.name')
domain = bcg('app', 'package.domain')
source_dir = abspath(bcg('app', 'source.dir'))
title = bcg('app', 'title')
app_deps = bcgl('app', 'requirements', '')
garden_deps = bcgl('app', 'garden_requirements', '')
icon = bc.getdefault('app', 'icon.filename', '')
version = self.buildozer.get_version()
author = bc.getdefault('app', 'author', '')
#print(title, package_name, domain, version,
# source_dir, app_deps, garden_deps, icon, author)
#return
self.buildozer.info('Create {}.app'.format(package_name))
cwd = join(self.buildozer.platform_dir,'kivy-sdk-packager-master', 'osx')
check_output(
('python', 'package_app.py', source_dir,
'--icon={}'.format(icon),
'--author={}'.format(author),
'--appname={}'.format(package_name),
'--bundlename={}'.format(title),
'--bundleid={}'.format(domain),
'--bundleversion={}'.format(version),
#'--deps={}'.format(app_deps),
'--displayname={}'.format(title)
),
cwd=cwd)
self.buildozer.info('{}.app created.'.format(package_name))
self.buildozer.info('Creating {}.dmg'.format(package_name))
check_output(
('sh', '-x', 'create-osx-dmg.sh', package_name + '.app'),
cwd=cwd)
self.buildozer.info('{}.dmg created'.format(package_name))
self.buildozer.info('moving {}.dmg to bin.'.format(package_name))
binpath = join(
self.buildozer.builddir or
dirname(abspath(self.buildozer.specfilename)), 'bin')
print binpath
check_output(
('cp', '-a', package_name+'.dmg', binpath),
cwd=cwd)
self.buildozer.info('All Done!')
def compile_platform(self):
print('compile_platform')
pass
def install_platform(self):
print('install_platform')
# cmd = self.buildozer.cmd
# self.pa_dir = pa_dir = join(self.buildozer.platform_dir,
# 'cpython')
# source = self.buildozer.config.getdefault('app', 'python.branch')
# if source:
# cmd('git checkout %s' % (source), cwd=pa_dir)
# ultimate configuration check.
# some of our configuration cannot be check without platform.
# self.check_configuration_tokens()
#
# self.buildozer.environ.update({
# 'PACKAGES_PATH': self.buildozer.global_packages_dir,
# })
def get_custom_commands(self):
print('get custom commands')
result = []
for x in dir(self):
if not x.startswith('cmd_'):
continue
if x[4:] in self.buildozer.standard_cmds:
continue
result.append((x[4:], getattr(self, x).__doc__))
return result
def get_available_packages(self):
print('get_available_packages')
return ['kivy']
def run_commands(self, args):
if not args:
self.buildozer.error('Missing target command')
self.buildozer.usage()
exit(1)
result = []
last_command = []
for arg in args:
if not arg.startswith('--'):
if last_command:
result.append(last_command)
last_command = []
last_command.append(arg)
else:
if not last_command:
self.buildozer.error('Argument passed without a command')
self.buildozer.usage()
exit(1)
last_command.append(arg)
if last_command:
result.append(last_command)
config_check = False
for item in result:
command, args = item[0], item[1:]
if not hasattr(self, 'cmd_{0}'.format(command)):
self.buildozer.error('Unknown command {0}'.format(command))
exit(1)
func = getattr(self, 'cmd_{0}'.format(command))
need_config_check = not hasattr(func, '__no_config')
if need_config_check and not config_check:
config_check = True
self.check_configuration_tokens()
func(args)
def check_build_prepared(self):
self._build_prepared = False
def cmd_clean(self, *args):
self.buildozer.clean_platform()
def cmd_update(self, *args):
self.platform_update = True
self.buildozer.prepare_for_build()
def cmd_debug(self, *args):
self.buildozer.prepare_for_build()
self.build_mode = 'debug'
self.check_build_prepared()
#self.buildozer.build()
def cmd_release(self, *args):
self.buildozer.prepare_for_build()
self.build_mode = 'release'
self.buildozer.build()
def cmd_deploy(self, *args):
self.buildozer.prepare_for_build()
def cmd_run(self, *args):
self.buildozer.prepare_for_build()
def cmd_serve(self, *args):
self.buildozer.cmd_serve()
def get_target(buildozer):
return TargetOSX(buildozer)