Skip to content

Commit 1689fb8

Browse files
author
Jonathan Feinberg
committed
Use real flags in pde2py
1 parent 6e54deb commit 1689fb8

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

.pydevproject

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<?eclipse-pydev version="1.0"?>
3-
4-
<pydev_project>
2+
<?eclipse-pydev version="1.0"?><pydev_project>
53
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
6-
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">jython 2.5</pydev_property>
4+
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">jython 2.7</pydev_property>
75
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
86
<path>/processing.py/buildtime/lib/jython/Lib</path>
97
<path>/processing.py/buildtime/py</path>

buildtime/py/pde2py.py

+28-7
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,54 @@
55
"""
66
from __future__ import with_statement
77

8+
import logging
9+
from optparse import OptionParser
810
import os
911
import re
1012
import shutil
1113
import sys
1214

13-
src, dest = sys.argv[1:]
15+
def usage():
16+
print >> sys.stderr, 'Usage: pde2py [-f|--force] srcdir destdir'
17+
sys.exit(1)
18+
19+
parser = OptionParser()
20+
parser.add_option("-f", "--force",
21+
action="store_true", dest="force", default=False,
22+
help="don't print status messages to stdout")
23+
24+
(opts, args) = parser.parse_args()
25+
26+
if len(args) < 2:
27+
usage()
28+
29+
src, dest = args
1430
if not (os.path.exists(src) and os.path.isdir(src)):
15-
raise Exception("I expect the first argument to be the source directory.")
31+
usage()
1632
if os.path.exists(dest):
1733
shutil.rmtree(dest)
1834
os.makedirs(dest)
1935

2036
def copy_dir(s, d):
2137
if not os.path.exists(d):
2238
os.mkdir(d)
23-
for file in os.listdir(s):
24-
if file[0] == '.':
39+
for f in os.listdir(s):
40+
if f[0] == '.':
2541
continue
26-
copy(os.path.join(s, file), os.path.join(d, file))
42+
copy(os.path.join(s, f), os.path.join(d, f))
2743

2844
def copy_file(s, d, xform=None):
2945
with open(s, 'rb') as f:
3046
text = f.read()
3147
if xform:
3248
(d, text) = xform(d, text)
3349
if os.path.exists(d):
34-
raise Exception("I refuse to overwrite %s." % d)
50+
if opts.force:
51+
logging.info('Overwriting %s.' % d)
52+
else:
53+
logging.warning('Not overwriting %s.' % d)
54+
else:
55+
logging.info('Writing %s.' % d)
3556
with open(d, 'wb') as f:
3657
f.write(text)
3758

@@ -54,7 +75,7 @@ def xform_py(d, text):
5475
text = text.replace('new ', '')
5576
text = text.replace('true', 'True')
5677
text = text.replace('false', 'False')
57-
text=text.replace('this.', 'self.')
78+
text = text.replace('this.', 'self.')
5879
return (d, text)
5980

6081
def copy(s, d):

0 commit comments

Comments
 (0)