Commits

Arnaud Grausem  committed 83f45e3

Dealing with version for setup of adama and adama's capability to display end users program's version with a new parameter of sir_yes_sir function

  • Participants
  • Parent commits ba2b663

Comments (0)

Files changed (6)

 """
 
 import sys
+import os
 from optparse import make_option
 
-from adama import sir_yes_sir
+from adama import sir_yes_sir, get_version
+
+name = os.path.split(__file__)[1]
 
 global_options = (
     make_option('--pythonpath', action='store', type='string', dest='pythonpath',
 )
 
 if __name__ == '__main__':
-	sys.exit(sir_yes_sir(doc=__doc__, options=global_options))
+    sys.exit(sir_yes_sir(doc=__doc__, options=global_options, version=get_version(name)))
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
+import os
+import sys
 from setuptools import setup, find_packages
 
-version = '0.3'
+path = '{0}/src'.format(os.path.dirname(os.path.abspath(__file__)))
+sys.path.append(path)
 
-# Dynamically calculate the version based on playlister VERSION.
+module = __import__("adama")
+version = module.get_version()
+project = module.__name__
 
 setup(
-    name = "adama",
+    name = project,
     version = version,
-    url = 'http://bitbucket.org/agrausem/adama',
-    download_url = 'http://bitbucket.org/agrausem/adama/files/',
+    url = 'http://bitbucket.org/agrausem/{0}'.format(project),
+    download_url = 'http://bitbucket.org/agrausem/{0}/files/'.format(project),
     author = 'Arnaud Grausem',
     author_email = 'arnaud.grausem@gmail.com',
     description = 'A light library to create command line python script for an application',

File src/adama/__init__.py

 from .commandment import Commander, OrderError, QG
 
 
-def sir_yes_sir(module='', doc='', options=(), argv=None):
+VERSION = ('0', '3', '1', 'beta')
+
+def get_version(command=''):
+    version = '.'.join(element for element in VERSION[:3])
+    return '{0} {1}'.format(command, version) if command else version
+
+
+def sir_yes_sir(module='', doc='', options=(), version='', argv=None):
     """
     """
     argv = argv if argv else sys.argv[:]
     module = module if module else command
     commander = Commander(command, module, doc)
 
-    # global options made available for the orders
+    # global options and app version made available for the orders
     QG.options = options
+    QG.version = version
 
     no_arg = len(argv) == 1
     needs_help = not no_arg and argv[1] == 'help'

File src/adama/commandment.py

 
 import sys
 
-from .utils import find_orders, get_version, AdamaOptionParser
+from .utils import find_orders, AdamaOptionParser
 
 
 class OrderError(Exception):
     args = ''
     options = ()
     examples = ''
+    version = ''
 
     def __init__(self, command, module):
         self.command = command
         """
         return AdamaOptionParser(prog=self.command, usage=self.usage(),
             description=self.__doc__, option_list=self.options,
-            version=get_version(command=self.command), epilog='')
+            version=self.version, epilog='')
 
     def explanations(self):
         """Help on command

File src/adama/templates/program.template

 )
 
 if __name__ == '__main__':
-    sys.exit(sir_yes_sir(module='{0}', doc=__doc__, options=global_options))
+    sys.exit(sir_yes_sir(module='{0}', doc=__doc__, options=global_options, version=''))

File src/adama/utils.py

         return self.description
 
 
-VERSION = '0.3'
-
-
-def get_version(command=''):
-    if command:
-        return '{0} {1}'.format(command, VERSION)
-    return VERSION
-
-
 def find_orders(path):
     """
     """