Changeset 12812 for trunk


Ignore:
Timestamp:
04/07/11 15:09:37 (13 years ago)
Author:
sil
Message:
  • Improved init of parser, logger, and (default) settings
  • Removed some commented code
  • Refactoring
  • ...
Location:
trunk/sara_cmt
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sara_cmt/cmt.py

    r12664 r12812  
    3636from sara_cmt.django_cli import ModelExtension, ObjectManager, QueryManager, \
    3737    logger, parser
    38 from sara_cmt.parser import Parser
    3938
    4039import sara_cmt.cluster.models
     
    8079
    8180# Instantiate ConfigParser
    82 #configfile = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'config/cmt.cfg')
    8381configfile = os.path.join(settings.PROJECT_BASE, 'config/cmt.cfg')
    8482config_parser = ConfigParser.ConfigParser()
     
    10098CMTSARA_DESCRIPTION = config_parser.get('info', 'description').strip("'")
    10199
    102 parse_object = Parser()
    103 parser = parse_object.getParser()
    104 
    105 # Get and set the defaults
    106 DRYRUN = config_parser.getboolean('defaults', 'DRYRUN')
    107 INTERACTIVE = config_parser.getboolean('defaults', 'INTERACTIVE')
    108100#
    109101# </CMT-specific settings from file>
     
    392384
    393385    parser.add_option('-n', '--dry-run',
    394                     action='store_true',
    395                     dest='DRYRUN',
    396                     default=config_parser.getboolean('defaults', 'DRYRUN'),
    397                     help="""This flag has to be given before -[aclmr]""")
     386        action='store_true',
     387        dest='DRYRUN',
     388        default=config_parser.getboolean('defaults', 'DRYRUN'),
     389        help="""This flag has to be given before -[aclmr]""")
    398390    parser.add_option('--script',
    399                     action='store_false',
    400                     dest='INTERACTIVE',
    401                     default=config_parser.getboolean('defaults',
    402                                                      'INTERACTIVE'))
     391        action='store_false',
     392        dest='INTERACTIVE',
     393        default=config_parser.getboolean('defaults', 'INTERACTIVE'))
    403394    parser.add_option('-a', '--add',
    404                     action='callback',
    405                     callback=add,
    406                     type='string',
    407                     metavar='ENTITY',
    408                     nargs=1,
    409                     help="""Add an object of given ENTITY.
    410 
    411                         arguments:   set <ASSIGNMENTS>
    412 
    413                         The object will get values according to the given
    414                         assignments. Assignments could be formed like
    415                         [<FK>__]<attr>=<value>""")
     395        action='callback',
     396        callback=add,
     397        type='string',
     398        metavar='ENTITY',
     399        nargs=1,
     400        help="""Add an object of given ENTITY.
     401
     402            arguments:   set <ASSIGNMENTS>
     403
     404            The object will get values according to the given assignments.
     405            Assignments could be formed like [<FK>__]<attr>=<value>""")
    416406    parser.add_option('-c', '--change',
    417                     action='callback',
    418                     callback=change,
    419                     type='string',
    420                     metavar='ENTITY',
    421                     nargs=1,
    422                     help="""Change value(s) of object(s) of given ENTITY.
    423 
    424                         arguments:   get <QUERY> set <ASSIGNMENTS>
    425 
    426                         The query, which consists out of one or more terms, is
    427                         used to make a selection of objects to change. These
    428                         objects will be changed according to the given
    429                         assignments.""")
     407        action='callback',
     408        callback=change,
     409        type='string',
     410        metavar='ENTITY',
     411        nargs=1,
     412        help="""Change value(s) of object(s) of given ENTITY.
     413
     414            arguments:   get <QUERY> set <ASSIGNMENTS>
     415
     416            The query, which consists out of one or more terms, is used to make
     417            a selection of objects to change. These objects will be changed
     418            according to the given assignments.""")
    430419    parser.add_option('-g', '--generate',
    431                     action='callback',
    432                     callback=generate,
    433                     type='string',
    434                     metavar='TEMPLATE',
    435                     nargs=1,
    436                     help='Render the given template')
     420        action='callback',
     421        callback=generate,
     422        type='string',
     423        metavar='TEMPLATE',
     424        nargs=1,
     425        help='Render the given template')
    437426    parser.add_option('-l', '--list',
    438                     action='callback',
    439                     callback=show,
    440                     type='string',
    441                     metavar='ENTITY [ATTRIBUTE=VALUE]',
    442                     nargs=1,
    443                     help="""List object(s) of the given ENTITY.
    444 
    445                         arguments:   get <QUERY>
    446 
    447                         The query, which consists out of one or more terms, is
    448                         used to make a selection of objects to list.""")
     427        action='callback',
     428        callback=show,
     429        type='string',
     430        metavar='ENTITY [ATTRIBUTE=VALUE]',
     431        nargs=1,
     432        help="""List object(s) of the given ENTITY.
     433
     434            arguments:   get <QUERY>
     435
     436            The query, which consists out of one or more terms, is used to make
     437            a selection of objects to list.""")
    449438    parser.add_option('-r', '--remove',
    450                     action='callback',
    451                     callback=remove,
    452                     type='string',
    453                     metavar='ENTITY [ATTRIBUTE=VALUE]',
    454                     nargs=1,
    455                     help='Remove objects which reflect the given query')
     439        action='callback',
     440        callback=remove,
     441        type='string',
     442        metavar='ENTITY [ATTRIBUTE=VALUE]',
     443        nargs=1,
     444        help='Remove objects which reflect the given query')
    456445
    457446    # TODO: implement the following option(s)
    458447    parser.add_option('-v', '--verbose',
    459                     action='store_true',
    460                     dest='VERBOSE',
    461                     default=config_parser.getboolean('defaults',
    462                                                      'VERBOSE'))
     448        action='store_true',
     449        dest='VERBOSE',
     450        default=config_parser.getboolean('defaults', 'VERBOSE'))
    463451
    464452    (options, args) = parser.parse_args()
  • trunk/sara_cmt/sara_cmt/django_cli.py

    r12655 r12812  
    140140        """
    141141        m2ms = [] # to collect M2Ms (which should be done at last)
     142
    142143        for arg in arg_dict:
    143144            field = self._meta.get_field(arg)
     
    151152                continue
    152153
    153             #if type(field) == ForeignKey:
    154             #    self._setfk(field, arg_dict[arg])
    155 
    156             #elif type(field) == ManyToManyField:
    157             #    # Leave M2Ms for later, because they need an object's id
    158             #    m2ms.append([field, arg_dict[arg]])
     154            # Leave M2Ms for later, because they need an object's id
    159155            elif type(field) == ManyToManyField:
    160156                m2ms.append([field,arg_dict[arg]])
    161157
    162             #else:
    163             #    logger.debug("Assuming '%s' is a regular field" % arg)
    164             #    self._setattr(field=arg, value=arg_dict[arg])
    165158            self._setattr(field=arg, value=arg_dict[arg])
    166159
     
    236229            except AssertionError, err:
    237230                logger.error(err)
    238             except sqlite3.IntegrityError, err:
     231            except sqlite3.IntegrityError, err: # ??? what if using non-sqlite db? ???
    239232                logger.error('IntegrityError:', err)
    240233
  • trunk/sara_cmt/sara_cmt/settings.py

    r12458 r12812  
    1010PROJECT_BASE = os.path.normpath(os.path.join(SARACMT_BASE, os.path.pardir))
    1111
    12 #DEBUG = False
    1312DEBUG = True
    14 TEMPLATE_DEBUG = DEBUG
    1513
    1614ADMINS = (
     
    2523# excluded from the SVN repository. An example of the needed info for database
    2624# configuration is commented out.
     25# DATABASE_ENGINE    = 'postgresql_psycopg2'
     26# DATABASE_NAME      = 'my_database'
     27# DATABASE_USER      = 'db_user'
     28# DATABASE_PASSWORD  = 'secret'
     29# DATABASE_HOST      = 'database.example.com'
    2730from settings_db import *
    28 #TEST_DATABASE_NAME = ''
    2931
    3032
     
    140142ROOT_URLCONF = 'sara_cmt.urls'
    141143
     144# Templates for the CMT command line interface.
     145# (thus, the templates for our configfiles, etc)
     146CMT_TEMPLATES_DIR = '/etc/sara_cmt/templates'
     147
    142148# Templates for the CMT web-frontend.
    143149TEMPLATE_DIRS = (
     
    147153    # Don't forget to use absolute paths, not relative paths.
    148154    os.path.normpath(os.path.join(os.path.dirname(__file__), 'cluster/templates')),
     155    CMT_TEMPLATES_DIR,
    149156)
    150 
    151 # Templates for the CMT command line interface.
    152 # (thus, the templates for our configfiles, etc)
    153 CMT_TEMPLATES_DIR = '/etc/sara_cmt/templates'
    154157
    155158FIXTURE_DIRS = (
Note: See TracChangeset for help on using the changeset viewer.