Changeset 200

Show
Ignore:
Timestamp:
08/24/08 09:05:11 (10 months ago)
Author:
rgrp
Message:

[shakespeare/misc][m]: fix up config registration, make associated changes to cli.py and move all tests to shakespeare/tests.

  • config setup:
    • conf() in init was confusing, out of date, and was magically defaulting to 'development.ini'
    • added new register_config and refactor conf to just look the config up
  • cli.py: refactored to take account of this adding new --config option to shakespeare-admin
  • tests: move all tests into shakespeare/tests so that config is properly set up for them
Location:
trunk
Files:
1 removed
3 modified
4 moved

Legend:

Unmodified
Added
Removed
  • trunk/shakespeare.egg-info/paste_deploy_config.ini_tmpl

    r169 r200  
    4747set debug = false 
    4848 
    49 # using sqlite in memory leads to thread issues when using db ... 
    50 # sqlobject.dburi = sqlite:///:memory: 
    51 sqlobject.dburi = postgres://<username>:<password>@localhost/<your-dbname> 
     49# We use sqlalchemy to connect and work with databases. 
     50# This default config using sqlite. 
     51sqlalchemy.url = sqlite:///%(here)s/shkspr.db 
     52# This is for postgres (obviously change the values to those for your system) 
     53# sqlalchemy.url = postgres://<username>:<password>@localhost/<your-dbname> 
    5254 
    5355# Logging configuration 
     
    7476format = %(asctime)s %(levelname)-5.5s [%(name)s] %(message)s 
    7577 
    76  
    77 [misc] 
    78 # directory where we can store all local copies of texts 
    79 cachedir = ./cache 
    80  
    81 [db] 
    82 # sqlobject database uri. see sqlobject documentation for details 
    83 # uri = postgres://user:pass@host/dbname 
    84 uri = sqlite:/:memory: 
    85  
    86 [web] 
    87 # directory where the templates used by web front end are kept 
    88 template_dir = ./src/shakespeare/template 
    89  
    90 [annotater] 
    91 # url at which marginalia files (css/js etc) should be mounted 
    92 marginalia_prefix = /marginalia 
  • trunk/shakespeare/__init__.py

    r185 r200  
    8181Run:: 
    8282 
    83     $ shakespeare-admin db create 
    8483    $ shakespeare-admin db init 
    8584 
     
    121120__application_name__ = 'shakespeare' 
    122121 
    123 def conf(): 
     122def register_config(config_path): 
    124123    import os 
    125     defaultPath = os.path.abspath('./development.ini') 
    126     envVarName = __application_name__.upper() + 'CONF' 
    127     confPath = os.environ.get(envVarName, defaultPath) 
    128     if not os.path.exists(confPath): 
    129         raise ValueError('No Configuration file exists at: %s' % confPath) 
    130  
    131     # register the config 
     124    # TODO: remove? 2008-08-24 not mentioned in docs any more 
     125    # envVarName = __application_name__.upper() + 'CONF' 
     126    # config_path = os.environ.get(envVarName, '') 
     127    config_path = os.path.abspath(config_path) 
    132128    import paste.deploy 
     129    pasteconf = paste.deploy.appconfig('config:' + config_path) 
    133130    import shakespeare.config.environment 
    134     pasteconf = paste.deploy.appconfig('config:' + confPath) 
    135  
    136131    shakespeare.config.environment.load_environment(pasteconf.global_conf, 
    137132        pasteconf.local_conf) 
     133 
     134 
     135# TODO: rename to get_config() 
     136def conf(): 
    138137    from pylons import config 
    139138    conf = config 
    140  
    141     # import ConfigParser 
    142     # conf = ConfigParser.SafeConfigParser() 
    143     # conf.read(confPath) 
    144  
    145139    return conf 
    146140      
  • trunk/shakespeare/cli.py

    r194 r200  
    1010    """ 
    1111 
    12     def __init__(self, verbose=False): 
     12    def __init__(self, config=None, verbose=False): 
    1313        # cmd.Cmd is not a new style class 
    1414        cmd.Cmd.__init__(self) 
     15        self.config = config 
    1516        self.verbose = verbose 
    1617 
     
    1920            print msg 
    2021 
    21     prompt = 'The Bard > ' 
    22  
    23     def run_interactive(self, line=None): 
    24         """Run an interactive session. 
    25         """ 
    26         print 'Welcome to shakespeare-admin interactive mode\n' 
    27         self.do_about() 
    28         print 'Type:  "?" or "help" for help on commands.\n' 
    29         while 1: 
    30             try: 
    31                 self.cmdloop() 
    32                 break 
    33             except KeyboardInterrupt: 
    34                 raise 
     22    def _register_config(self): 
     23        import sys 
     24        if not self.config: 
     25            msg = 'No configuration file has been specified. See -h help for details' 
     26            print msg 
     27            sys.exit(1) 
     28        import shakespeare 
     29        shakespeare.register_config(self.config) 
    3530 
    3631    def do_help(self, line=None): 
     
    5954 
    6055    def do_db(self, line=None): 
    61         actions = [ 'create', 'clean', 'rebuild', 'init' ] 
     56        actions = [ 'create', 'clean', 'init' ] 
    6257        if line is None or line not in actions: 
    6358            self.help_db() 
    6459            return 1 
     60        self._register_config() 
    6561        import shakespeare.model 
     62        import shakespeare 
    6663        if line == 'init': 
    6764            import pkg_resources 
     
    6966            meta = pkg_resources.resource_stream(pkg, 'texts/metadata.txt') 
    7067            shakespeare.model.Material.load_from_metadata(meta) 
    71         else: 
     68        elif line == 'clean': 
     69            config = shakespeare.conf() 
     70            shakespeare.model.metadata.drop_all(bind=config['pylons.g'].sa_engine) 
     71        elif line == 'create': 
    7272            print 'To create db use paster: paster setup-app {config-file}' 
     73        else: 
     74            print self.help_db() 
    7375 
    7476    def help_db(self, line=None): 
     
    7981     
    8082    def do_gutenberg(self, line=None): 
     83        self._register_config() 
    8184        import shakespeare.gutenberg 
    8285        helper = shakespeare.gutenberg.Helper(verbose=True) 
     
    109112 
    110113    def help_moby(self, line=None): 
     114        self._register_config() 
    111115        usage = \ 
    112116''' 
     
    115119 
    116120    def _init_index(self): 
     121        self._register_config() 
    117122        import shakespeare.index 
    118123        self._index = shakespeare.index.all 
     
    185190 
    186191    def do_search(self, line): 
     192        self._register_config() 
    187193        import shakespeare.search 
    188194        index = shakespeare.search.SearchIndex.default_index() 
     
    232238 
    233239    def do_stats(self, line): 
     240        self._register_config() 
    234241        action, extra = self._parse_line(line) 
    235242 
     
    277284'''%prog [options] <command> 
    278285 
    279 Run about or help for details.''' 
     286For list of the commands available run: 
     287 
     288    $ shakespeare-admin help 
     289 
     290For more general information run the about or info commands.''' 
    280291    parser = optparse.OptionParser(usage) 
    281292    parser.add_option('-v', '--verbose', dest='verbose', help='Be verbose', 
    282293            action='store_true', default=False)  
     294    parser.add_option('-c', '--config', dest='config', 
     295        help='Path to config file', default=None) 
    283296    options, args = parser.parse_args() 
    284297     
     
    287300        return 1 
    288301    else: 
    289         cmd = ShakespeareAdmin(verbose=options.verbose) 
     302        cmd = ShakespeareAdmin(verbose=options.verbose, config=options.config) 
    290303        args = ' '.join(args) 
    291304        args = args.replace('-','_')