diff options
| author | Antony Lesuisse <lesuisse@gmail.com> | 2014-05-29 18:33:04 +0200 |
|---|---|---|
| committer | Antony Lesuisse <lesuisse@gmail.com> | 2014-05-29 18:33:04 +0200 |
| commit | d4624fa826a5e9542782f2c53c8ba2c766d093bc (patch) | |
| tree | be214779eb6d1f17157aa48e72fbcbf95405e38b /openerpcommand/common.py | |
| parent | 045ecc603e67911a5390c812cb6b5b123d9c190e (diff) | |
[IMP] repository cleanup
- move packaging stuff to setup
- remove historical stuff
- remove oe, odoo-cmd-fme will be merged with the convered commands
- add an odoo.py script to run odo and boostrap it
- simplify README
- prepare to move documentation to the github wiki
Diffstat (limited to 'openerpcommand/common.py')
| -rw-r--r-- | openerpcommand/common.py | 108 |
1 files changed, 0 insertions, 108 deletions
diff --git a/openerpcommand/common.py b/openerpcommand/common.py deleted file mode 100644 index 7572bb4efa6..00000000000 --- a/openerpcommand/common.py +++ /dev/null @@ -1,108 +0,0 @@ -""" -Define a few common arguments for server-side command-line tools. -""" -import argparse -import os -try: - from setproctitle import setproctitle -except ImportError: - setproctitle = lambda x: None -import sys - -def add_addons_argument(parser): - """ - Add a common --addons argument to a parser. - """ - parser.add_argument('--addons', metavar='ADDONS', - **required_or_default('ADDONS', - 'colon-separated list of paths to addons')) -def set_addons(args): - """ - Turn args.addons into a list instead of a column-separated strings. - Set openerp.toools.config accordingly. - """ - import openerp.tools.config - config = openerp.tools.config - - assert hasattr(args, 'addons') - if args.addons: - args.addons = args.addons.split(':') - else: - args.addons = [] - - config['addons_path'] = ','.join(args.addons) - -def get_addons_from_paths(paths, exclude): - """ - Build a list of available modules from a list of addons paths. - """ - exclude = exclude or [] - module_names = [] - for p in paths: - if os.path.exists(p): - names = [n for n in os.listdir(p) if os.path.isfile(os.path.join(p, n, '__openerp__.py')) and not n.startswith('.') and n not in exclude] - names = filter(lambda a: os.path.isdir(os.path.join(p, a)), names) - names = filter(lambda a: os.path.exists(os.path.join(p, a, '__openerp__.py')), names) - module_names.extend(names) - else: - print "The addons path `%s` doesn't exist." % p - sys.exit(1) - return module_names - -def required_or_default(name, h): - """ - Helper to define `argparse` arguments. If the name is the environment, - the argument is optional and draw its value from the environment if not - supplied on the command-line. If it is not in the environment, make it - a mandatory argument. - """ - if os.environ.get('OPENERP_' + name.upper()): - d = {'default': os.environ['OPENERP_' + name.upper()]} - else: - d = {'required': True} - d['help'] = h + '. The environment variable OPENERP_' + \ - name.upper() + ' can be used instead.' - return d - -class Command(object): - """ - Base class to create command-line tools. It must be inherited and the - run() method overriden. - """ - - command_name = 'stand-alone' - - def __init__(self, subparsers=None): - if subparsers: - self.parser = parser = subparsers.add_parser(self.command_name, - description=self.__class__.__doc__) - else: - self.parser = parser = argparse.ArgumentParser( - description=self.__class__.__doc__) - - parser.add_argument('-d', '--database', metavar='DATABASE', - **required_or_default('DATABASE', 'the database to connect to')) - parser.add_argument('-u', '--user', metavar='USER', - **required_or_default('USER', 'the user login or ID. When using ' - 'RPC, providing an ID avoid the login() step')) - parser.add_argument('-p', '--password', metavar='PASSWORD', - **required_or_default('PASSWORD', 'the user password')) # TODO read it from the command line or from file. - - parser.set_defaults(run=self.run_with_args) - - def run_with_args(self, args): - self.args = args - self.run() - - def run(self): - print 'Stub Command.run().' - - @classmethod - def stand_alone(cls): - """ - A single Command object is a complete command-line program. See - `openerp-command/stand-alone` for an example. - """ - command = cls() - args = command.parser.parse_args() - args.run(args) |
