Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* separated the main and basic functions

  * added generate scene method
  • Loading branch information...
commit 74a9465d09eca21d3e56159b5228b51717049232 1 parent 78c998d
@grundprinzip authored
View
121 pypalm/basic.py
@@ -0,0 +1,121 @@
+import json, os, subprocess, re
+import StringIO
+
+
+def call_and_return(args):
+ p = subprocess.Popen(args, stdout = subprocess.PIPE)
+ out = p.communicate()[0]
+ # Return the tuple of code and content
+ return (p.returncode, out)
+
+def parse_appinfo(dest_dir):
+ """Reads the content of the appinfo file and
+ decodes the json"""
+ content = open(os.path.join(dest_dir, "appinfo.json")).read()
+ appinfo = json.loads(content)
+ return appinfo
+
+def package(dest_dir, appinfo, quiet=True):
+ """ Packages the application"""
+ (ret_code, output) = call_and_return(["palm-package", dest_dir])
+
+ if ret_code < 0:
+ print "package was called and terminted with a failure code"
+
+ if not quiet:
+ print output
+
+ print "Packaged application with version %s" % appinfo["version"]
+
+def install(dest_dir, appinfo, version=None, device="tcp", quiet=True):
+ """ Installs version number xxx to the device"""
+ if not version:
+ version = appinfo["version"]
+
+ filename = appinfo["id"] + "_" + version + "_all.ipk"
+ if os.path.exists(os.path.join(dest_dir, filename)):
+ # Call the install process
+ args = ["palm-install"]
+
+ # add the device
+ args.append("-d")
+ args.append(device)
+
+ # Add the version
+ args.append(filename)
+
+ (ret_code, output) = call_and_return(args)
+ if ret_code < 0:
+ print "Could not install application %s" % appinfo["id"]
+
+ if not quiet:
+ print output
+
+ print "Installed application with version %s" % version
+
+ else:
+ print "could not find packaged file for version %s" % version
+
+
+def emulator():
+ """ Start the emulator """
+ call_and_return("palm-emulator")
+
+def debug(appinfo):
+ """Start the debugger """
+ # Directly start novaterm in the beginning
+ os.execl("/usr/bin/novaterm")
+
+def log(appinfo, device="tcp"):
+ """ Print the log output """
+ args = ["palm-log"]
+
+ # Set the device
+ args.append("-d")
+ args.append(device)
+
+ # Set the appid
+ args.append(appinfo["id"])
+
+ (ret_code, output) = call_and_return(args)
+ print output
+
+def clean(dest_dir, appinfo):
+ """ Clear IPK files"""
+ m = re.compile("%s.*\.ipk$" % appinfo["id"].replace(".", "\\."))
+ for f in os.listdir(dest_dir):
+ if m.search(f):
+ os.remove(f)
+
+
+def start(dest_dir, id, device='tcp'):
+ """ Lauch the app"""
+ args = ['palm-launch']
+
+ args.append('-d')
+ args.append(device)
+
+ args.append(id)
+
+ (ret_code, output) = call_and_return(args)
+ if ret_code < 0:
+ print output
+ print "There was an error"
+
+def remove(dest_dir, id, device='tcp', quiet=True):
+ args = ['palm-install']
+
+ args.append('-d')
+ args.append(device)
+
+ args.append('-r')
+
+ args.append(id)
+ (ret_code, output) = call_and_return(args)
+ if ret_code < 0:
+ print output
+ print "Could not remove the application"
+
+
+ if not quiet:
+ print output
View
23 pypalm/generate.py
@@ -0,0 +1,23 @@
+import basic
+
+def new_scene(dest_dir, name, quiet = True):
+ """Create a new scene in the app directory"""
+ args = ['palm-generate']
+ # now the template
+ args.append('-t')
+ args.append('new_scene')
+ args.append('-p')
+ args.append("name=%s"% name)
+
+ args.append(dest_dir)
+
+ print " ".join(args)
+
+ (code, output) = basic.call_and_return(args)
+ if code < 0:
+ print "Could not create new scene"
+ print output
+ elif not quiet:
+ print output
+
+ print "Generated scene %s in %s" % (name, dest_dir)
View
141 pypalm/pypalm.py
@@ -1,134 +1,18 @@
-import json, os, subprocess, re
-import StringIO
-
from optparse import OptionParser
-ACTIONS = ['install', 'debug', 'package', 'deploy', 'log',
- 'emulator', 'clean', 'start', 'remove']
-QUIET = True
-
-
-def is_app_dir(dest_dir):
- return os.path.exists(os.path.join(dest_dir, "appinfo.json"))
-
-
-def call_and_return(args):
- p = subprocess.Popen(args, stdout = subprocess.PIPE)
- out = p.communicate()[0]
- # Return the tuple of code and content
- return (p.returncode, out)
-
-def parse_appinfo(dest_dir):
- """Reads the content of the appinfo file and
- decodes the json"""
- content = open(os.path.join(dest_dir, "appinfo.json")).read()
- appinfo = json.loads(content)
- return appinfo
-
-def package(dest_dir, appinfo, quiet=True):
- """ Packages the application"""
- (ret_code, output) = call_and_return(["palm-package", dest_dir])
-
- if ret_code < 0:
- print "package was called and terminted with a failure code"
-
- if not quiet:
- print output
-
- print "Packaged application with version %s" % appinfo["version"]
-
-def install(dest_dir, appinfo, version=None, device="tcp", quiet=True):
- """ Installs version number xxx to the device"""
- if not version:
- version = appinfo["version"]
-
- filename = appinfo["id"] + "_" + version + "_all.ipk"
- if os.path.exists(os.path.join(dest_dir, filename)):
- # Call the install process
- args = ["palm-install"]
-
- # add the device
- args.append("-d")
- args.append(device)
-
- # Add the version
- args.append(filename)
-
- (ret_code, output) = call_and_return(args)
- if ret_code < 0:
- print "Could not install application %s" % appinfo["id"]
-
- if not quiet:
- print output
-
- print "Installed application with version %s" % version
-
- else:
- print "could not find packaged file for version %s" % version
-
-
-def emulator():
- """ Start the emulator """
- call_and_return("palm-emulator")
-
-def debug(appinfo):
- """Start the debugger """
- # Directly start novaterm in the beginning
- os.execl("/usr/bin/novaterm")
+from generate import new_scene
+from basic import *
-def log(appinfo, device="tcp"):
- """ Print the log output """
- args = ["palm-log"]
- # Set the device
- args.append("-d")
- args.append(device)
+VERSION = "0.2.4"
- # Set the appid
- args.append(appinfo["id"])
-
- (ret_code, output) = call_and_return(args)
- print output
-
-def clean(dest_dir, appinfo):
- """ Clear IPK files"""
- m = re.compile("%s.*\.ipk$" % appinfo["id"].replace(".", "\\."))
- for f in os.listdir(dest_dir):
- if m.search(f):
- os.remove(f)
-
-
-def start(dest_dir, id, device='tcp'):
- """ Lauch the app"""
- args = ['palm-launch']
-
- args.append('-d')
- args.append(device)
-
- args.append(id)
-
- (ret_code, output) = call_and_return(args)
- if ret_code < 0:
- print output
- print "There was an error"
-
-def remove(dest_dir, id, device='tcp', quiet=True):
- args = ['palm-install']
-
- args.append('-d')
- args.append(device)
-
- args.append('-r')
-
- args.append(id)
- (ret_code, output) = call_and_return(args)
- if ret_code < 0:
- print output
- print "Could not remove the application"
+ACTIONS = ['install', 'debug', 'package', 'deploy', 'log',
+ 'emulator', 'clean', 'start', 'remove', 'new_scene']
+QUIET = True
- if not quiet:
- print output
+def is_app_dir(dest_dir):
+ return os.path.exists(os.path.join(dest_dir, "appinfo.json"))
def main_func():
@@ -144,8 +28,10 @@ def main_func():
clean - remove old IPK files
remove - Uninstall the application
start - Start the application
+ new_scene - Create a new scene named 'name'
emulator - start the emulator """
+ usage += "\n\n v%s (c) Martin Grund\n" % VERSION
parser = OptionParser(usage)
parser.add_option("-d", "--device", dest='device',
@@ -195,6 +81,7 @@ def main_func():
package(current_dir, app_info, quiet=QUIET)
install(current_dir, app_info, version=options.version,
device=options.device, quiet=QUIET)
+ start(current_dir, app_info['id'], device=options.device)
elif args[0] == "debug":
debug(app_info)
elif args[0] == 'clean':
@@ -203,3 +90,9 @@ def main_func():
start(current_dir, app_info['id'], device=options.device)
elif args[0] == 'remove':
remove(current_dir, app_info['id'], device=options.device, quiet=QUIET)
+ elif args[0] == "new_scene":
+ if len(args) < 2:
+ print "new_scene needs an additional 'name' argument"
+ exit()
+
+ new_scene(current_dir, args[1], quiet=QUIET)
View
3  setup.py
@@ -1,8 +1,9 @@
from setuptools import setup, find_packages
+import pypalm.pypalm as pp
setup(
name = "PyPalm",
- version = "0.2.1",
+ version = pp.VERSION,
packages = find_packages(),
author = "Martin Grund",
View
3  upload.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+python setup.py build sdist upload
Please sign in to comment.
Something went wrong with that request. Please try again.