Skip to content
Browse files

Use real flags in pde2py

  • Loading branch information...
1 parent 6e54deb commit 1689fb8215f31d5beee4b38ad19dbd4e05d4f6f8 @jdf committed Jan 25, 2014
Showing with 30 additions and 11 deletions.
  1. +2 −4 .pydevproject
  2. +28 −7 buildtime/py/pde2py.py
View
6 .pydevproject
@@ -1,9 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<?eclipse-pydev version="1.0"?>
-
-<pydev_project>
+<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
-<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">jython 2.5</pydev_property>
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">jython 2.7</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/processing.py/buildtime/lib/jython/Lib</path>
<path>/processing.py/buildtime/py</path>
View
35 buildtime/py/pde2py.py
@@ -5,33 +5,54 @@
"""
from __future__ import with_statement
+import logging
+from optparse import OptionParser
import os
import re
import shutil
import sys
-src, dest = sys.argv[1:]
+def usage():
+ print >> sys.stderr, 'Usage: pde2py [-f|--force] srcdir destdir'
+ sys.exit(1)
+
+parser = OptionParser()
+parser.add_option("-f", "--force",
+ action="store_true", dest="force", default=False,
+ help="don't print status messages to stdout")
+
+(opts, args) = parser.parse_args()
+
+if len(args) < 2:
+ usage()
+
+src, dest = args
if not (os.path.exists(src) and os.path.isdir(src)):
- raise Exception("I expect the first argument to be the source directory.")
+ usage()
if os.path.exists(dest):
shutil.rmtree(dest)
os.makedirs(dest)
def copy_dir(s, d):
if not os.path.exists(d):
os.mkdir(d)
- for file in os.listdir(s):
- if file[0] == '.':
+ for f in os.listdir(s):
+ if f[0] == '.':
continue
- copy(os.path.join(s, file), os.path.join(d, file))
+ copy(os.path.join(s, f), os.path.join(d, f))
def copy_file(s, d, xform=None):
with open(s, 'rb') as f:
text = f.read()
if xform:
(d, text) = xform(d, text)
if os.path.exists(d):
- raise Exception("I refuse to overwrite %s." % d)
+ if opts.force:
+ logging.info('Overwriting %s.' % d)
+ else:
+ logging.warning('Not overwriting %s.' % d)
+ else:
+ logging.info('Writing %s.' % d)
with open(d, 'wb') as f:
f.write(text)
@@ -54,7 +75,7 @@ def xform_py(d, text):
text = text.replace('new ', '')
text = text.replace('true', 'True')
text = text.replace('false', 'False')
- text=text.replace('this.', 'self.')
+ text = text.replace('this.', 'self.')
return (d, text)
def copy(s, d):

0 comments on commit 1689fb8

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