Commits

Arnaud Grausem  committed b2fa79d

Repository organization

  • Participants
  • Parent commits 89442b2

Comments (0)

Files changed (17)

File adama/__init__.py

-# -*- coding: utf-8 -*-
-
-"""
-"""
-
-import sys
-import os
-
-from .commandment import Commander, OrderError
-
-
-def sir_yes_sir(module='', argv=None):
-    """
-    """
-    argv = argv if argv else sys.argv[:]
-    command = os.path.basename(argv[0])
-    module = module if module else command
-    commander = Commander(command, module)
-
-    no_arg = len(argv) == 1
-    needs_help = not no_arg and argv[1] == 'help'
-    global_help = needs_help and len(argv) == 2
-    order_help = needs_help and len(argv) > 2
-
-    if no_arg or global_help:
-        return commander.explanations()
-    else:
-        order_name = argv[1] if not order_help else argv[2]
-        try:
-            order = commander[order_name]
-        except KeyError as e:
-            return commander(argv[1:])
-        else:
-            if order_help:
-                return order.explanations()
-            else:
-                return order(argv[1:])

File adama/commandment.py

-# -*- coding: utf-8 -*-
-
-import sys
-
-from .utils import find_orders, get_version, AdamaOptionParser
-
-
-class OrderError(Exception):
-    """
-    """
-    pass
-
-
-
-class QG(object):
-    """Base class for the adama library
-    """
-
-    arg = ''
-    help = ''
-    options = ()
-
-    def __init__(self, command, module):
-        self.command = command
-        self.module = module
-
-    def usage(self):
-        """Usage of the command
-        """
-        return 'Usage: %prog order [options] [args]'
-
-    @property
-    def decrypter(self):
-        """Gives the parser
-        """
-        return AdamaOptionParser(prog=self.command, usage=self.usage(),
-            description=self.__doc__, option_list=self.options,
-            version=get_version(command=self.command), epilog='')
-
-    def explanations(self):
-        """Help on command
-        """
-        self.decrypter.print_help()
-        return 1
-
-    def decrypt(self):
-        """Parse command args and options
-        """
-        return self.decrypter.parse_args()
-
-    def run(self, *args, **kwargs):
-        """The implementation of the command or order comes here
-        """
-        raise NotImplementedError()
-
-    def __call__(self, args):
-        """Executes the command
-        """
-        options, args = self.decrypt()
-        try:
-            result = self.run(*args, **options.__dict__)
-        except OrderError, e:
-            sys.stderr.write(str(e))
-            sys.exit(1)
-
-
-class Commander(QG):
-    """Program class
-    """
-
-    __orders = {}
-
-    def __init__(self, command, module):
-        super(Commander, self).__init__(command, module)
-
-    @property
-    def orders(self):
-        """Lists the available orders
-        """
-        app_orders = '{0}.orders'.format(self.module)
-        package = __import__(app_orders) if app_orders not in sys.modules \
-            else sys.modules[app_orders]
-
-        if not self.__orders:
-            for name in find_orders(package.__path__[0]):
-                subpackage = '{0}.{1}'.format(app_orders, name)
-                if subpackage not in sys.modules:
-                    __import__(subpackage)
-                self.__orders[name] = sys.modules[subpackage].Order(
-                    self.command, self.module)
-
-        return self.__orders
-
-    @property
-    def decrypter(self):
-        decrypter = super(Commander, self).decrypter
-        epilog = """
-Type '{0} help <order>' for help on a specific order.
-
-Available orders:
-{1}
-
-"""
-        decrypter.epilog = epilog.format(self.command,
-            '\n'.join('  {0}'.format(order) for order in self.orders)
-        )
-        return decrypter
-
-    def get_order(self, name):
-        """Gives an order by name
-        """
-        return self.orders[name]
-
-    def __getitem__(self, key):
-        return self.get_order(key)
-
-    def run(self, *args, **kwargs):
-        """Bad use of command so we print usage
-        """
-        return self.explanations()
-
-
-class BaseOrder(QG):
-    """The base class of a program that needs an implementation
-    to define a command
-    """
-
-    args = ''
-    help = ''
-    options = ()
-
-    def __init__(self, command, module):
-        super(BaseOrder, self).__init__(command, module)
-        self.name = self.__class__.__module__.split('.')[-1] \
-
-    def usage(self):
-        """Usage of a command
-        """
-        return '%prog {0.name} [options] {0.args}'.format(self)

File adama/orders/__init__.py

-# -*- coding: utf-8
-
-import os
-
-def get_template(name):
-    template_path = os.path.join(
-        os.path.dirname(__path__[0]), 'templates', '{0}.template'.format(name)
-    )
-    with open(template_path) as template:
-        return template.read()

File adama/orders/create_order.py

-# -*- coding: utf-8 -*-
-
-"""This script allows you to adding data to the listen file that contains
-all the data for generating playlist
-"""
-
-import os
-from optparse import make_option
-
-from adama.commandment import BaseOrder, OrderError
-from adama.orders import get_template
-
-class Order(BaseOrder):
-    """
-    """
-
-    options = BaseOrder.options
-
-    help = __doc__
-    args = "project_path library_name order_name"
-
-    def __init__(self, commander, module):
-        super(Order, self).__init__(commander, module)
-
-    def run(self, *args, **options):
-        if len(args) != 4:
-            raise OrderError('The create_program needs three arguments')
-
-        project_path = args[1]
-        library_name = args[2]
-        order_name = args[3]
-
-        if not os.path.isdir(project_path):
-            raise OrderError(
-                'The project {0} does not exist'.format(project_path)
-            )
-
-        orders_path = os.path.join(project_path, library_name, 'orders')
-        if not os.path.isdir(orders_path):
-            os.mkdir(orders_path)
-
-        if not order_name.endswith('.py'):
-            order_name = '{0}.py'.format(order_name)
-        order_path = os.path.join(orders_path, order_name)
-
-        with open(order_path, "w") as order:
-            order.write(get_template('order'))
-
-        return 0

File adama/orders/create_program.py

-# -*- coding: utf-8 -*-
-
-"""This script allows you to adding data to the listen file that contains
-all the data for generating playlist
-"""
-
-import sys
-import os
-from optparse import make_option
-
-from adama.commandment import BaseOrder, OrderError
-from adama.orders import get_template
-
-class Order(BaseOrder):
-
-    options = BaseOrder.options
-
-    help = __doc__
-    args = "project_path name"
-
-    def __init__(self, commander, module):
-        super(Order, self).__init__(commander, module)
-
-    def run(self, *args, **options):
-        if len(args) != 3:
-            raise OrderError('The create_program needs two arguments')
-
-        project_path = args[1]
-        prog_name = args[2]
-
-        if not os.path.isdir(project_path):
-            raise OrderError(
-                'The project {0} does not exist'.format(project_path)
-            )
-
-        bin_path = os.path.join(project_path, 'bin')
-        if not os.path.isdir(bin_path):
-            os.mkdir(bin_path)
-
-        script_path = os.path.join(bin_path, prog_name)
-
-        with open(script_path, "w") as program:
-            program.write(get_template('program'))
-
-        return 0

File adama/templates/order.template

-# -*- coding: utf-8 -*-
-
-"""
-"""
-
-from adama.commander import BaseOrder, OrderError
-
-
-class Order(BaseOrder):
-    """
-    """
-
-    options = BaseOrder.options
-        # options for order come here
-
-    help = 'help for the order (ex: __doc__)'
-    args = 'args of the order (ex: [options] arg1 arg2'
-
-    def __init__(self, command, module):
-        super(Order, self).__init__(command, module)
-
-    def run(self, *args, **options):
-        # the logic of the order comes here
-        return 0

File adama/templates/program.template

-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-import sys
-from adama import sir_yes_sir
-
-if __name__ == '__main__':
-    sys.exit(sir_yes_sir())

File adama/utils.py

-# -*- coding: utf-8 -*-
-
-"""Some utils functions and classes
-"""
-
-import os
-from optparse import OptionParser
-
-
-class AdamaOptionParser(OptionParser):
-    """Adama own option parser
-    """
-
-    def format_epilog(self, formatter):
-        """Initial format_epilog function stris newline
-        """
-        return self.epilog
-
-
-VERSION = '0.2'
-
-
-def get_version(command=''):
-    if command:
-        return '{0} {1}'.format(command, VERSION)
-    return VERSION
-
-
-def find_orders(path):
-    """
-    """
-    order_path = os.path.join(path, 'orders')
-    try:
-        return [order[:-3] for order in os.listdir(order_path)
-            if not order.startswith('_') and order.endswith('.py')]
-    except OSError:
-        return []
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
-from distutils.core import setup
+from setuptools import setup, find_packages
+
+version = '0.2'
 
 # Dynamically calculate the version based on playlister VERSION.
 
 setup(
     name = "adama",
-    version = "0.1",
-    url = 'http://bitbucket.org/agrausem/commander',
-    download_url = 'http://bitbucket.org/agrausem/commander/files/',
+    version = version,
+    url = 'http://bitbucket.org/agrausem/adama',
+    download_url = 'http://bitbucket.org/agrausem/adama/files/',
     author = 'Arnaud Grausem',
     author_email = 'arnaud.grausem@gmail.com',
     description = 'A light library to create command line python script for an application',
-    packages = ['adama', 'adama.orders'],
+    packages = find_packages('src'),
+    package_dir = {'': 'src'},
+    package_data = {
+            'adama': [
+                'templates/*.template'
+            ]
+    },
+    scripts = ['bin/adama'],
     classifiers = ['Development Status :: 3 - Alpha',
                    'Environment :: Console',
                    'Intended Audience :: Developers',

File src/adama/__init__.py

+# -*- coding: utf-8 -*-
+
+"""
+"""
+
+import sys
+import os
+
+from .commandment import Commander, OrderError
+
+
+def sir_yes_sir(module='', argv=None):
+    """
+    """
+    argv = argv if argv else sys.argv[:]
+    command = os.path.basename(argv[0])
+    module = module if module else command
+    commander = Commander(command, module)
+
+    no_arg = len(argv) == 1
+    needs_help = not no_arg and argv[1] == 'help'
+    global_help = needs_help and len(argv) == 2
+    order_help = needs_help and len(argv) > 2
+
+    if no_arg or global_help:
+        return commander.explanations()
+    else:
+        order_name = argv[1] if not order_help else argv[2]
+        try:
+            order = commander[order_name]
+        except KeyError as e:
+            return commander(argv[1:])
+        else:
+            if order_help:
+                return order.explanations()
+            else:
+                return order(argv[1:])

File src/adama/commandment.py

+# -*- coding: utf-8 -*-
+
+import sys
+
+from .utils import find_orders, get_version, AdamaOptionParser
+
+
+class OrderError(Exception):
+    """
+    """
+    pass
+
+
+
+class QG(object):
+    """Base class for the adama library
+    """
+
+    arg = ''
+    help = ''
+    options = ()
+
+    def __init__(self, command, module):
+        self.command = command
+        self.module = module
+
+    def usage(self):
+        """Usage of the command
+        """
+        return 'Usage: %prog order [options] [args]'
+
+    @property
+    def decrypter(self):
+        """Gives the parser
+        """
+        return AdamaOptionParser(prog=self.command, usage=self.usage(),
+            description=self.__doc__, option_list=self.options,
+            version=get_version(command=self.command), epilog='')
+
+    def explanations(self):
+        """Help on command
+        """
+        self.decrypter.print_help()
+        return 1
+
+    def decrypt(self):
+        """Parse command args and options
+        """
+        return self.decrypter.parse_args()
+
+    def run(self, *args, **kwargs):
+        """The implementation of the command or order comes here
+        """
+        raise NotImplementedError()
+
+    def __call__(self, args):
+        """Executes the command
+        """
+        options, args = self.decrypt()
+        try:
+            result = self.run(*args, **options.__dict__)
+        except OrderError, e:
+            sys.stderr.write(str(e))
+            sys.exit(1)
+
+
+class Commander(QG):
+    """Program class
+    """
+
+    __orders = {}
+
+    def __init__(self, command, module):
+        super(Commander, self).__init__(command, module)
+
+    @property
+    def orders(self):
+        """Lists the available orders
+        """
+        app_orders = '{0}.orders'.format(self.module)
+        package = __import__(app_orders) if app_orders not in sys.modules \
+            else sys.modules[app_orders]
+
+        if not self.__orders:
+            for name in find_orders(package.__path__[0]):
+                subpackage = '{0}.{1}'.format(app_orders, name)
+                if subpackage not in sys.modules:
+                    __import__(subpackage)
+                self.__orders[name] = sys.modules[subpackage].Order(
+                    self.command, self.module)
+
+        return self.__orders
+
+    @property
+    def decrypter(self):
+        decrypter = super(Commander, self).decrypter
+        epilog = """
+Type '{0} help <order>' for help on a specific order.
+
+Available orders:
+{1}
+
+"""
+        decrypter.epilog = epilog.format(self.command,
+            '\n'.join('  {0}'.format(order) for order in self.orders)
+        )
+        return decrypter
+
+    def get_order(self, name):
+        """Gives an order by name
+        """
+        return self.orders[name]
+
+    def __getitem__(self, key):
+        return self.get_order(key)
+
+    def run(self, *args, **kwargs):
+        """Bad use of command so we print usage
+        """
+        return self.explanations()
+
+
+class BaseOrder(QG):
+    """The base class of a program that needs an implementation
+    to define a command
+    """
+
+    args = ''
+    help = ''
+    options = ()
+
+    def __init__(self, command, module):
+        super(BaseOrder, self).__init__(command, module)
+        self.name = self.__class__.__module__.split('.')[-1] \
+
+    def usage(self):
+        """Usage of a command
+        """
+        return '%prog {0.name} [options] {0.args}'.format(self)

File src/adama/orders/__init__.py

+# -*- coding: utf-8
+
+import os
+
+def get_template(name):
+    template_path = os.path.join(
+        os.path.dirname(__path__[0]), 'templates', '{0}.template'.format(name)
+    )
+    with open(template_path) as template:
+        return template.read()

File src/adama/orders/create_order.py

+# -*- coding: utf-8 -*-
+
+"""This script allows you to adding data to the listen file that contains
+all the data for generating playlist
+"""
+
+import os
+from optparse import make_option
+
+from adama.commandment import BaseOrder, OrderError
+from adama.orders import get_template
+
+class Order(BaseOrder):
+    """
+    """
+
+    options = BaseOrder.options
+
+    help = __doc__
+    args = "project_path library_name order_name"
+
+    def __init__(self, commander, module):
+        super(Order, self).__init__(commander, module)
+
+    def run(self, *args, **options):
+        if len(args) != 4:
+            raise OrderError('The create_program needs three arguments')
+
+        project_path = args[1]
+        library_name = args[2]
+        order_name = args[3]
+
+        if not os.path.isdir(project_path):
+            raise OrderError(
+                'The project {0} does not exist'.format(project_path)
+            )
+
+        orders_path = os.path.join(project_path, library_name, 'orders')
+        if not os.path.isdir(orders_path):
+            os.mkdir(orders_path)
+
+        if not order_name.endswith('.py'):
+            order_name = '{0}.py'.format(order_name)
+        order_path = os.path.join(orders_path, order_name)
+
+        with open(order_path, "w") as order:
+            order.write(get_template('order'))
+
+        return 0

File src/adama/orders/create_program.py

+# -*- coding: utf-8 -*-
+
+"""This script allows you to adding data to the listen file that contains
+all the data for generating playlist
+"""
+
+import sys
+import os
+from optparse import make_option
+
+from adama.commandment import BaseOrder, OrderError
+from adama.orders import get_template
+
+class Order(BaseOrder):
+
+    options = BaseOrder.options
+
+    help = __doc__
+    args = "project_path name"
+
+    def __init__(self, commander, module):
+        super(Order, self).__init__(commander, module)
+
+    def run(self, *args, **options):
+        if len(args) != 3:
+            raise OrderError('The create_program needs two arguments')
+
+        project_path = args[1]
+        prog_name = args[2]
+
+        if not os.path.isdir(project_path):
+            raise OrderError(
+                'The project {0} does not exist'.format(project_path)
+            )
+
+        bin_path = os.path.join(project_path, 'bin')
+        if not os.path.isdir(bin_path):
+            os.mkdir(bin_path)
+
+        script_path = os.path.join(bin_path, prog_name)
+
+        with open(script_path, "w") as program:
+            program.write(get_template('program'))
+
+        return 0

File src/adama/templates/order.template

+# -*- coding: utf-8 -*-
+
+"""
+"""
+
+from adama.commander import BaseOrder, OrderError
+
+
+class Order(BaseOrder):
+    """
+    """
+
+    options = BaseOrder.options
+        # options for order come here
+
+    help = 'help for the order (ex: __doc__)'
+    args = 'args of the order (ex: [options] arg1 arg2'
+
+    def __init__(self, command, module):
+        super(Order, self).__init__(command, module)
+
+    def run(self, *args, **options):
+        # the logic of the order comes here
+        return 0

File src/adama/templates/program.template

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import sys
+from adama import sir_yes_sir
+
+if __name__ == '__main__':
+    sys.exit(sir_yes_sir())

File src/adama/utils.py

+# -*- coding: utf-8 -*-
+
+"""Some utils functions and classes
+"""
+
+import os
+from optparse import OptionParser
+
+
+class AdamaOptionParser(OptionParser):
+    """Adama own option parser
+    """
+
+    def format_epilog(self, formatter):
+        """Initial format_epilog function stris newline
+        """
+        return self.epilog
+
+
+VERSION = '0.2'
+
+
+def get_version(command=''):
+    if command:
+        return '{0} {1}'.format(command, VERSION)
+    return VERSION
+
+
+def find_orders(path):
+    """
+    """
+    order_path = os.path.join(path, 'orders')
+    try:
+        return [order[:-3] for order in os.listdir(order_path)
+            if not order.startswith('_') and order.endswith('.py')]
+    except OSError:
+        return []