]> git.nothing2do.fr Git - get-hack-src.git/commitdiff
updated a few canari commands
authorallfro <ndouba@gmail.com>
Wed, 10 Oct 2012 16:07:36 +0000 (12:07 -0400)
committerallfro <ndouba@gmail.com>
Wed, 10 Oct 2012 16:07:36 +0000 (12:07 -0400)
src/canari/commands/common.py
src/canari/commands/create_package.py
src/canari/commands/create_transform.py
src/canari/commands/help.py
src/scripts/canari

index 94c358a09c6f21aaf545120a7ff1c5a95beec256..7e19c3d6be752db8d4f8beb5cae2d6ddc020a671 100644 (file)
@@ -1,10 +1,14 @@
 #!/usr/bin/env python
 
-from os import path, listdir, sep, environ, mkdir, pathsep
+from canari.config import CanariConfigParser
+
+from os import path, listdir, sep, environ, mkdir, pathsep, getcwd
 from pkg_resources import resource_filename
 from sys import path as pypath, platform
+from datetime import datetime
 from string import Template
 
+
 __author__ = 'Nadeem Douba'
 __copyright__ = 'Copyright 2012, Canari Project'
 __credits__ = []
@@ -143,4 +147,34 @@ def console_message(msg, tab=-1):
             tab += 1
             console_message(sc, tab)
             tab -= 1
-    tab -= 1
\ No newline at end of file
+    tab -= 1
+
+
+def init_pkg():
+
+    conf = '.canari'
+
+    for i in range(0, 5):
+        if path.exists(conf):
+            c = CanariConfigParser()
+            c.read(conf)
+            return {
+                'author' : c['metadata/author'],
+                'email' : c['metadata/email'],
+                'maintainer' : c['metadata/maintainer'],
+                'project' : c['metadata/project'],
+                'year' : datetime.now().year,
+                'dir' : getcwd()
+            }
+        conf = '..%s%s' % (sep, conf)
+
+    return {
+        'author' : '',
+        'email' : '',
+        'maintainer' : '',
+        'project' : '',
+        'year' : datetime.now().year
+    }
+
+
+
index a2f2f21cb06f9ff2917aefdca1933ad45221f377..101ba7b65a0c7f5dd5e92d536fadc6ef6d97e944 100644 (file)
@@ -3,6 +3,7 @@
 from common import read_template, write_template, generate_all, build_skeleton, cmd_name
 
 from argparse import ArgumentParser
+from datetime import datetime
 from getpass import getuser
 from os import path, sep
 
@@ -31,6 +32,7 @@ parser.add_argument(
 
 
 def write_setup(package_name, values):
+    write_template(sep.join([package_name, '.canari']), read_template('_canari', values))
     write_template(sep.join([package_name, 'setup.py']), read_template('setup', values))
     write_template(sep.join([package_name, 'README.md']), read_template('README', values))
 
@@ -65,15 +67,22 @@ def write_resources(package_name, resources, init, values):
 
 
 def write_common(transforms, init, values):
-    write_template(
-        sep.join([transforms, '__init__.py']),
-        init + generate_all('common', 'helloworld')
-    )
 
-    write_template(
-        sep.join([transforms, 'helloworld.py']),
-        read_template('transform', values)
-    )
+    if values['example']:
+        write_template(
+            sep.join([transforms, '__init__.py']),
+            init + generate_all('common', 'helloworld')
+        )
+
+        write_template(
+            sep.join([transforms, 'helloworld.py']),
+            read_template('transform', values)
+        )
+    else:
+        write_template(
+            sep.join([transforms, '__init__.py']),
+            init + generate_all('common')
+        )
 
     write_template(
         sep.join([transforms, 'common', '__init__.py']),
@@ -94,6 +103,33 @@ def description():
     return parser.description
 
 
+def parse_bool(ans, default='y'):
+
+    while True:
+        ans = raw_input(ans).lower() or default
+        if ans.startswith('y'):
+            return True
+        elif ans.startswith('n'):
+            return False
+
+
+def ask_user(defaults):
+
+    print('Welcome to the Canari transform package wizard.')
+
+    if not parse_bool('Would you like to specify authorship information? [Y/n]: '):
+        return
+
+    defaults['description'] = raw_input('Project description [%s]: ' % defaults['description']) or defaults['description']
+    defaults['example'] = parse_bool('Generate an example transform? [Y/n]: ')
+    defaults['author'] = raw_input('Author name [%s]: ' % defaults['author']) or defaults['author']
+    defaults['email'] = raw_input('Author email []: ') or ''
+    defaults['maintainer'] = raw_input('Maintainer name [%s]: ' % defaults['author']) or defaults['author']
+
+    if not parse_bool('Are you satisfied with this information? [Y/n]: '):
+        return ask_user(defaults)
+
+
 def run(args):
 
     opts = parser.parse_args(args)
@@ -105,12 +141,18 @@ def run(args):
         'package' : package_name,
         'entity' : 'My%sEntity' % capitalized_package_name,
         'base_entity' : '%sEntity' % capitalized_package_name,
-        'author' : getuser(),
-        'year' : 2012,
         'project' : capitalized_package_name,
-        'namespace' : package_name
+        'author' : getuser(),
+        'year' : datetime.now().year,
+        'namespace' : package_name,
+        'email' : '',
+        'maintainer' : getuser(),
+        'example' : True,
+        'description' : ''
     }
 
+    ask_user(values)
+
     base = sep.join([package_name, 'src', package_name])
     transforms = sep.join([base, 'transforms'])
     resources = sep.join([base, 'resources'])
index f620be3358bb534ec09dee981b2f3a488221669f..e1a5b842911a3a43b0f371aa32ea0721f8d86921 100644 (file)
@@ -1,10 +1,10 @@
 #!/usr/bin/env python
 
-from common import write_template, read_template, cmd_name
+from common import write_template, read_template, cmd_name, init_pkg
+
 
 from argparse import ArgumentParser
 from os import path, sep, getcwd
-from getpass import getuser
 from re import sub
 
 
@@ -68,10 +68,7 @@ def run(args):
         print ('Transform %s already exists... quitting' % repr(transformf))
         exit(-1)
 
-    values = {
-        'author' : getuser(),
-        'year' : 2012
-    }
+    values = init_pkg()
 
     write_template(
         transformf,
index 273738b3584e823538aeed7f887e6dc49b3037f9..416b2324908f9dc8eb3ff41c706fc7d1d0200353 100644 (file)
@@ -27,6 +27,8 @@ parser.add_argument(
     'command',
     metavar='<command>',
     choices=cmds,
+    default='help',
+    nargs='?',
     help='The canari command you want help for (%s)' % ', '.join(cmds)
 )
 
index 72affe940e5aa87e9e6104f7e353c44eb2ab7fb2..8083f9373a4cfce9b202038d6854df3db23564d5 100644 (file)
@@ -20,7 +20,8 @@ cmds = get_commands()
 
 def parse_args():
     parser = ArgumentParser(
-        description='Centralized Canari Management System'
+        description='Centralized Canari Management System',
+        add_help=False
     )
     parser.add_argument(
         'command',