Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

* separated the main and basic functions

  * added generate scene method
  • Loading branch information...
commit 74a9465d09eca21d3e56159b5228b51717049232 1 parent 78c998d
Martin Grund authored December 29, 2009
121  pypalm/basic.py
... ...
@@ -0,0 +1,121 @@
  1
+import json, os, subprocess, re
  2
+import StringIO
  3
+
  4
+
  5
+def call_and_return(args):
  6
+    p = subprocess.Popen(args, stdout = subprocess.PIPE)
  7
+    out = p.communicate()[0]
  8
+    # Return the tuple of code and content
  9
+    return (p.returncode, out)
  10
+
  11
+def parse_appinfo(dest_dir):
  12
+    """Reads the content of the appinfo file and
  13
+    decodes the json"""
  14
+    content = open(os.path.join(dest_dir, "appinfo.json")).read()
  15
+    appinfo = json.loads(content)
  16
+    return appinfo
  17
+
  18
+def package(dest_dir, appinfo, quiet=True):
  19
+    """ Packages the application"""
  20
+    (ret_code, output) = call_and_return(["palm-package", dest_dir])
  21
+    
  22
+    if ret_code < 0:
  23
+        print "package was called and terminted with a failure code"
  24
+
  25
+    if not quiet:
  26
+        print output
  27
+
  28
+    print "Packaged application with version %s" % appinfo["version"]
  29
+        
  30
+def install(dest_dir, appinfo, version=None, device="tcp", quiet=True):
  31
+    """ Installs version number xxx to the device"""
  32
+    if not version:
  33
+        version = appinfo["version"]
  34
+
  35
+    filename = appinfo["id"] + "_" + version + "_all.ipk"
  36
+    if os.path.exists(os.path.join(dest_dir, filename)):
  37
+        # Call the install process
  38
+        args = ["palm-install"]
  39
+
  40
+        # add the device
  41
+        args.append("-d")
  42
+        args.append(device)
  43
+
  44
+        # Add the version
  45
+        args.append(filename)
  46
+        
  47
+        (ret_code, output) = call_and_return(args)
  48
+        if ret_code < 0:
  49
+            print "Could not install application %s" % appinfo["id"]
  50
+
  51
+        if not quiet:
  52
+            print output
  53
+
  54
+        print "Installed application with version %s" % version
  55
+        
  56
+    else:
  57
+        print "could not find packaged file for version %s" % version
  58
+
  59
+
  60
+def emulator():
  61
+    """ Start the emulator """
  62
+    call_and_return("palm-emulator")
  63
+
  64
+def debug(appinfo):
  65
+    """Start the debugger """
  66
+    # Directly start novaterm in the beginning
  67
+    os.execl("/usr/bin/novaterm")
  68
+
  69
+def log(appinfo, device="tcp"):
  70
+    """ Print the log output """
  71
+    args = ["palm-log"]
  72
+
  73
+    # Set the device
  74
+    args.append("-d")
  75
+    args.append(device)
  76
+
  77
+    # Set the appid
  78
+    args.append(appinfo["id"])
  79
+
  80
+    (ret_code, output) = call_and_return(args)
  81
+    print output
  82
+
  83
+def clean(dest_dir, appinfo):
  84
+    """ Clear IPK files"""
  85
+    m = re.compile("%s.*\.ipk$" % appinfo["id"].replace(".", "\\."))
  86
+    for f in os.listdir(dest_dir):
  87
+        if m.search(f):
  88
+            os.remove(f)
  89
+
  90
+
  91
+def start(dest_dir, id, device='tcp'):
  92
+    """ Lauch the app"""
  93
+    args = ['palm-launch']
  94
+    
  95
+    args.append('-d')
  96
+    args.append(device)
  97
+
  98
+    args.append(id)
  99
+
  100
+    (ret_code, output) = call_and_return(args)
  101
+    if ret_code < 0:
  102
+        print output
  103
+        print "There was an error"
  104
+
  105
+def remove(dest_dir, id, device='tcp', quiet=True):
  106
+    args = ['palm-install']
  107
+
  108
+    args.append('-d')
  109
+    args.append(device)
  110
+
  111
+    args.append('-r')
  112
+
  113
+    args.append(id)
  114
+    (ret_code, output) = call_and_return(args)
  115
+    if ret_code < 0:
  116
+        print output
  117
+        print "Could not remove the application"
  118
+
  119
+
  120
+    if not quiet:
  121
+        print output
23  pypalm/generate.py
... ...
@@ -0,0 +1,23 @@
  1
+import basic
  2
+
  3
+def new_scene(dest_dir, name, quiet = True):
  4
+    """Create a new scene in the app directory"""
  5
+    args = ['palm-generate']
  6
+    # now the template
  7
+    args.append('-t')
  8
+    args.append('new_scene')
  9
+    args.append('-p')
  10
+    args.append("name=%s"% name)
  11
+
  12
+    args.append(dest_dir)
  13
+
  14
+    print " ".join(args)
  15
+
  16
+    (code, output) = basic.call_and_return(args)
  17
+    if code < 0:
  18
+        print "Could not create new scene"
  19
+        print output
  20
+    elif not quiet:
  21
+        print output
  22
+
  23
+    print "Generated scene %s in %s" % (name, dest_dir)
141  pypalm/pypalm.py
... ...
@@ -1,134 +1,18 @@
1  
-import json, os, subprocess, re
2  
-import StringIO
3  
-
4 1
 from optparse import OptionParser
5 2
 
6  
-ACTIONS = ['install', 'debug', 'package', 'deploy', 'log',
7  
-           'emulator', 'clean', 'start', 'remove']
8  
-QUIET = True
9  
-
10  
-
11  
-def is_app_dir(dest_dir):
12  
-    return os.path.exists(os.path.join(dest_dir, "appinfo.json"))
13  
-
14  
-
15  
-def call_and_return(args):
16  
-    p = subprocess.Popen(args, stdout = subprocess.PIPE)
17  
-    out = p.communicate()[0]
18  
-    # Return the tuple of code and content
19  
-    return (p.returncode, out)
20  
-
21  
-def parse_appinfo(dest_dir):
22  
-    """Reads the content of the appinfo file and
23  
-    decodes the json"""
24  
-    content = open(os.path.join(dest_dir, "appinfo.json")).read()
25  
-    appinfo = json.loads(content)
26  
-    return appinfo
27  
-
28  
-def package(dest_dir, appinfo, quiet=True):
29  
-    """ Packages the application"""
30  
-    (ret_code, output) = call_and_return(["palm-package", dest_dir])
31  
-    
32  
-    if ret_code < 0:
33  
-        print "package was called and terminted with a failure code"
34  
-
35  
-    if not quiet:
36  
-        print output
37  
-
38  
-    print "Packaged application with version %s" % appinfo["version"]
39  
-        
40  
-def install(dest_dir, appinfo, version=None, device="tcp", quiet=True):
41  
-    """ Installs version number xxx to the device"""
42  
-    if not version:
43  
-        version = appinfo["version"]
44  
-
45  
-    filename = appinfo["id"] + "_" + version + "_all.ipk"
46  
-    if os.path.exists(os.path.join(dest_dir, filename)):
47  
-        # Call the install process
48  
-        args = ["palm-install"]
49  
-
50  
-        # add the device
51  
-        args.append("-d")
52  
-        args.append(device)
53  
-
54  
-        # Add the version
55  
-        args.append(filename)
56  
-        
57  
-        (ret_code, output) = call_and_return(args)
58  
-        if ret_code < 0:
59  
-            print "Could not install application %s" % appinfo["id"]
60  
-
61  
-        if not quiet:
62  
-            print output
63  
-
64  
-        print "Installed application with version %s" % version
65  
-        
66  
-    else:
67  
-        print "could not find packaged file for version %s" % version
68  
-
69  
-
70  
-def emulator():
71  
-    """ Start the emulator """
72  
-    call_and_return("palm-emulator")
73  
-
74  
-def debug(appinfo):
75  
-    """Start the debugger """
76  
-    # Directly start novaterm in the beginning
77  
-    os.execl("/usr/bin/novaterm")
  3
+from generate import new_scene
  4
+from basic import *
78 5
 
79  
-def log(appinfo, device="tcp"):
80  
-    """ Print the log output """
81  
-    args = ["palm-log"]
82 6
 
83  
-    # Set the device
84  
-    args.append("-d")
85  
-    args.append(device)
  7
+VERSION = "0.2.4"
86 8
 
87  
-    # Set the appid
88  
-    args.append(appinfo["id"])
89  
-
90  
-    (ret_code, output) = call_and_return(args)
91  
-    print output
92  
-
93  
-def clean(dest_dir, appinfo):
94  
-    """ Clear IPK files"""
95  
-    m = re.compile("%s.*\.ipk$" % appinfo["id"].replace(".", "\\."))
96  
-    for f in os.listdir(dest_dir):
97  
-        if m.search(f):
98  
-            os.remove(f)
99  
-
100  
-
101  
-def start(dest_dir, id, device='tcp'):
102  
-    """ Lauch the app"""
103  
-    args = ['palm-launch']
104  
-    
105  
-    args.append('-d')
106  
-    args.append(device)
107  
-
108  
-    args.append(id)
109  
-
110  
-    (ret_code, output) = call_and_return(args)
111  
-    if ret_code < 0:
112  
-        print output
113  
-        print "There was an error"
114  
-
115  
-def remove(dest_dir, id, device='tcp', quiet=True):
116  
-    args = ['palm-install']
117  
-
118  
-    args.append('-d')
119  
-    args.append(device)
120  
-
121  
-    args.append('-r')
122  
-
123  
-    args.append(id)
124  
-    (ret_code, output) = call_and_return(args)
125  
-    if ret_code < 0:
126  
-        print output
127  
-        print "Could not remove the application"
  9
+ACTIONS = ['install', 'debug', 'package', 'deploy', 'log',
  10
+           'emulator', 'clean', 'start', 'remove', 'new_scene']
128 11
 
  12
+QUIET = True
129 13
 
130  
-    if not quiet:
131  
-        print output
  14
+def is_app_dir(dest_dir):
  15
+    return os.path.exists(os.path.join(dest_dir, "appinfo.json"))
132 16
 
133 17
 def main_func():
134 18
 
@@ -144,8 +28,10 @@ def main_func():
144 28
     clean - remove old IPK files
145 29
     remove - Uninstall the application
146 30
     start - Start the application
  31
+    new_scene - Create a new scene named 'name'
147 32
     emulator - start the emulator """
148 33
 
  34
+    usage += "\n\n    v%s (c) Martin Grund\n" % VERSION
149 35
     
150 36
     parser = OptionParser(usage)
151 37
     parser.add_option("-d", "--device", dest='device',
@@ -195,6 +81,7 @@ def main_func():
195 81
         package(current_dir, app_info, quiet=QUIET)
196 82
         install(current_dir, app_info, version=options.version,
197 83
                 device=options.device, quiet=QUIET)
  84
+        start(current_dir, app_info['id'], device=options.device)
198 85
     elif args[0] == "debug":
199 86
         debug(app_info)
200 87
     elif args[0] == 'clean':
@@ -203,3 +90,9 @@ def main_func():
203 90
         start(current_dir, app_info['id'], device=options.device)
204 91
     elif args[0] == 'remove':
205 92
         remove(current_dir, app_info['id'], device=options.device, quiet=QUIET)
  93
+    elif args[0] == "new_scene":
  94
+        if len(args) < 2:
  95
+            print "new_scene needs an additional 'name' argument"
  96
+            exit()
  97
+            
  98
+        new_scene(current_dir, args[1], quiet=QUIET)
3  setup.py
... ...
@@ -1,8 +1,9 @@
1 1
 from setuptools import setup, find_packages
  2
+import pypalm.pypalm as pp
2 3
 
3 4
 setup(
4 5
     name = "PyPalm",
5  
-    version = "0.2.1",
  6
+    version = pp.VERSION,
6 7
     packages = find_packages(),
7 8
 
8 9
     author = "Martin Grund",
3  upload.sh
... ...
@@ -0,0 +1,3 @@
  1
+#!/bin/bash
  2
+
  3
+python setup.py build sdist upload

0 notes on commit 74a9465

Please sign in to comment.
Something went wrong with that request. Please try again.