Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

merged Poromenos/master

  • Loading branch information...
commit 902d8e642dec0b1f77c6e86884af3b422fbd6e15 2 parents ccc3868 + 5a7c927
@wrboyce authored
Showing with 38 additions and 18 deletions.
  1. +0 −9 bin/mkproject
  2. +26 −6 mkproject.py
  3. +12 −3 setup.py
View
9 bin/mkproject
@@ -1,9 +0,0 @@
-#!/usr/bin/env python
-import sys
-
-from mkproject import mkproject
-
-
-if len(sys.argv) != 3:
- exit("USAGE: mkproject TYPE NAME")
-mkproject(*sys.argv[1:3])
View
32 mkproject.py
@@ -1,11 +1,20 @@
#!/usr/bin/env python
+
+from optparse import OptionParser
import ConfigParser
import os
import shutil
import sys
+def get_file_list(directory):
+ """Returns a list of the files in a directory and its subdirectories."""
+ files = []
+ for root, subfolders, subfiles in os.walk(directory):
+ files += [os.path.join(root,file) for file in subfiles]
+
+ return files
-def mkproject(type, name):
+def mkproject(type, name, basedir=None):
""" ``mkproject`` """
skel = _get_projectdir(type)
try:
@@ -15,7 +24,8 @@ def mkproject(type, name):
sys.path = syspath
except ImportError:
conf = object()
- basedir = os.environ.get('MKPROJECT_ROOT', '%s/Dev' % os.environ['HOME'])
+ if not basedir:
+ basedir = os.environ.get('MKPROJECT_ROOT', '.')
if os.path.isdir(os.path.join(basedir, name)):
raise ProjectAlreadyExists
os.chdir(basedir)
@@ -42,7 +52,7 @@ def mkproject(type, name):
target = os.path.join(basedir, name, getattr(conf, 'path', './') % vars)
shutil.copytree(skel, target, symlinks=True)
os.chdir(target)
- files = [filename.strip() for filename in os.popen('find %s -type f' % target).read().split('\n') if filename.strip()]
+ files = get_file_list(".")
# replace project variables
for (search, replace) in vars.iteritems():
@@ -73,7 +83,17 @@ class UnknownProjectType(Exception):
class ProjectAlreadyExists(Exception):
pass
+def main():
+ parser = OptionParser(usage="usage: %prog [options] <type> <name>")
+ parser.add_option("-d", "--directory", dest="dir",
+ metavar="DIR", help="create project in DIR")
+ (options, args) = parser.parse_args()
+ if len(args) != 2:
+ parser.print_help()
+ sys.exit(1)
+ else:
+ mkproject(args[0], args[1], options.dir)
+
if __name__ == '__main__':
- if len(sys.argv) != 3:
- exit("USAGE: mkproject TYPE NAME")
- mkproject(*sys.argv[1:3])
+ main()
+
View
15 setup.py 100644 → 100755
@@ -1,5 +1,9 @@
#!/usr/bin/env python
-from distutils.core import setup
+try:
+ from setuptools import setup
+except ImportError:
+ from distutils.core import setup
+
from distutils.dir_util import copy_tree
import os
@@ -11,7 +15,10 @@
author_email='me@willboyce.com',
url='http://github.com/wrboyce/mkproject',
py_modules=['mkproject'],
- scripts=['bin/mkproject'],
+ entry_points = {
+ 'console_scripts':[
+ 'mkproject = mkproject:main'
+ ]},
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
@@ -20,4 +27,6 @@
'Operating System :: POSIX',
]
)
-copy_tree(os.path.join(os.path.realpath(os.path.dirname(__file__)), 'templates'), '/etc/mkproject/')
+template_path = "/etc/mkproject/"
+if not os.path.exists(template_path):
+ copy_tree(os.path.join(os.path.realpath(os.path.dirname(__file__)), 'templates'), template_path)
Please sign in to comment.
Something went wrong with that request. Please try again.