Browse Source

Converted to use optparse. Patch from Pete Burgers.

Dan Helfman 8 years ago
parent
commit
13aae6f996
2 changed files with 61 additions and 8 deletions
  1. 2
    1
      NEWS
  2. 59
    7
      luminotes.py

+ 2
- 1
NEWS View File

@@ -9,7 +9,8 @@
9 9
    of Luminotes notebooks. These characters could show up when copy and pasted
10 10
    into another application.
11 11
  * New "-w" option to luminotes.py that prevents web browser from opening when
12
-   Luminotes Desktop is started. Patch from Pete Burgers.
12
+   Luminotes Desktop is started. Also added "--help" to show other available
13
+   options. Patches from Pete Burgers.
13 14
 
14 15
 1.6.17: July 26, 2009
15 16
  * Fixed a bug that caused ever-growing notes in Internet Explorer 8.

+ 59
- 7
luminotes.py View File

@@ -6,6 +6,7 @@ import stat
6 6
 import socket
7 7
 import os.path
8 8
 import urllib2 as urllib
9
+import optparse
9 10
 import cherrypy
10 11
 import webbrowser
11 12
 from controller.Database import Database
@@ -32,16 +33,15 @@ def change_to_main_dir():
32 33
     os.chdir( path )
33 34
 
34 35
 
35
-def main( args ):
36
+def main( options ):
36 37
   change_to_main_dir()
37 38
 
38 39
   cherrypy.config.update( Common.settings )
39 40
 
40
-  if args and "-d" in args:
41
+  if options.development:
41 42
     from config import Development
42 43
     settings = Development.settings
43
-  # sys.frozen is from py2exe
44
-  elif args and "-l" in args or hasattr( sys, "frozen" ):
44
+  elif options.desktop:
45 45
     from config import Desktop
46 46
     settings = Desktop.settings
47 47
   else:
@@ -51,7 +51,7 @@ def main( args ):
51 51
   cherrypy.config.update( settings )
52 52
 
53 53
   # Don't launch web browser if -w flag is set
54
-  if args and "-w" in args:
54
+  if options.no_webbrowser:
55 55
     launch_browser = False
56 56
   else:
57 57
     launch_browser = cherrypy.config.configMap[ u"global" ].get( u"luminotes.launch_browser" )
@@ -64,7 +64,7 @@ def main( args ):
64 64
   server_present = True
65 65
 
66 66
   # if requested, attempt to shutdown an existing server and exit
67
-  if args and "-k" in args:
67
+  if options.kill:
68 68
     try:
69 69
       urllib.urlopen( "%sshutdown" % server_url )
70 70
     except urllib.URLError:
@@ -146,4 +146,56 @@ def callback( log_access_file, log_file, server_url, port_filename, socket_port,
146 146
 
147 147
 
148 148
 if __name__ == "__main__":
149
-  main( sys.argv[ 1: ] )
149
+
150
+  # sys.frozen is from py2exe
151
+  desktop_default = hasattr( sys, "frozen" )
152
+
153
+  parser = optparse.OptionParser(
154
+    usage = "usage: %prog [OPTIONS]\n" +
155
+            "   OR: %prog --help",
156
+    version = VERSION,
157
+  )
158
+
159
+  parser.add_option(
160
+    "-l", "--desktop", 
161
+    dest = "desktop",
162
+    action = "store_true",
163
+    default = desktop_default,
164
+    help = "Run in Desktop mode %s" %
165
+           ( "(DEFAULT)" if desktop_default else "" ),
166
+  )
167
+
168
+  parser.add_option(
169
+    "-s", "--server", 
170
+    dest = "desktop",
171
+    action = "store_false",
172
+    help = "Run in Server mode %s" %
173
+           ( "(DEFAULT)" if not desktop_default else "" ),
174
+  )
175
+
176
+  parser.add_option(
177
+    "-d", "--developement", 
178
+    dest = "development",
179
+    action = "store_true",
180
+    help = "Run in Development mode",
181
+  )
182
+
183
+  parser.add_option(
184
+    "-k", "--kill",
185
+    dest = "kill",
186
+    action = "store_true",
187
+    help = "Attempt to shutdown existing server and exit",
188
+  )
189
+
190
+  parser.add_option(
191
+    "-w", "--no_webbrowser",
192
+    dest = "no_webbrowser",
193
+    action = "store_true",
194
+    help = "Don't autolaunch web browser in Desktop mode",
195
+  )
196
+
197
+  ( options, args ) = parser.parse_args()
198
+  if args != []:
199
+    parser.error( "Unrecognised options: %s" % " ".join( args ) )
200
+
201
+  main(options)