Пример #1
0
    def test_deCompound(self):
        master = ['a','b','c','d','e','f']
        testa = ['a','b','c,d,e','f']
        testb = ['a','b,c','d,e','f']
        testc = ['a','b','c','d','e','f']

        for i in [testa, testb, testc]:
            self.assertEquals(deCompound(i), master)
            
Пример #2
0
def main():
    # Let's read the command line
    usage = "usage: %prog [options]" # add 'arg1 arg2' etc as required
    parser = FilteredOptionParser(usage=usage, version="Peloton version %s" % peloton.RELEASE_VERSION)
#    parser.set_defaults(nodetach=False)
    parser.add_option("--prefix",
                     help="Prefix directory to help with setting paths")
    
    parser.add_option("--nodetach",
                      action="store_true",
                      default=False,
                      help="Prevent PSC detaching from terminal [default: %default]")
    
    parser.add_option("-c", "--configfile",
                      help="Path to configuration file for the PSC [default: %default].",
                      dest="configfile",
                      default='psc.pcfg')
    
    parser.add_option("-b", "--bind", 
                      help="""specify the host:port to which this instance should bind. Overides
values set in configuration.""",
                      dest='bindhost')
    
    parser.add_option("--anyport",
                      action="store_true",
                      default=False,
                      help="""When set, this permits the PSC to seek a free port if the 
configured port is not available.""")
    
    parser.add_option("-s", "--servicepath",
                      help="""Directory containing peloton services. You may specify several
such directories with multiple instances of this option [default: %default]""",
                      action="append",
                      default=["$PREFIX/service"])
        
    parser.add_option("--loglevel",
                      help="""Set the logging level to one of critical, fatal, error(uat, prod), warning, info(test), debug(dev).
(defaults for each run mode indicated in brackets).""",
                      choices=['critical', 'fatal', 'error', 'warning', 'info', 'debug'])
    
    parser.add_option("--logdir", 
                      help="""Directory to which log files should be written. By setting this argument
the logging-to-file system will be enabled.""")
    parser.add_option("--disable",
                      help="""Comma delimited list of plugins to prevent starting even if configuration has them enabled""",
                      action="append")
    parser.add_option("--enable",
                      help="""Comma delimited list of plugins to start even if configuration has them disabled""",
                      action="append")
    
    parser.add_option("--flags",
                      help="""Comma delimited list of flags to add to this PSC.""",
                      action="append")
    
    
    options, args = parser.parse_args()
    # Handling errors and pumping back through the system
    #if len(args) != 1:
    #    parser.error("incorrect number of arguments")

    # add any sevice directories to sys.path if not already there
    for sd in options.servicepath:
        if sd not in sys.path:
            sys.path.append(sd)


    # enable, disable and flags are all 'append' types, but allow
    # comma delimited entries as well so we need to turn the list of
    # n potentially compound entries into a single list
    
    if options.enable:
        options.enable = deCompound(options.enable)
    else:
        options.enable=[]
        
    if options.disable:
        options.disable = deCompound(options.disable)
    else:
        options.disable=[]

    if options.flags:
        options.flags = deCompound(options.flags)
    else:
        options.flags=[]

    # determine the appropriate log-level for the root logger based
    # on supplied arguments.
    if options.loglevel:
        options.loglevel = options.loglevel.upper()
    else:
        options.loglevel = "ERROR"

    # Load configuration from file
    pc = PelotonSettings()
    try:
        pc.load(options.configfile)
    except IOError:
        sys.stderr.write("There is no profile for the PSC!\n")
        return 1
    
    if pc.profile.has_key('flags'):
        pc.profile.flags.extend(options.flags)
    else:
        pc.profile.flags = options.flags
        
    # copy in the necessary from options to config
    keys =['configfile', 'nodetach', 'bindhost', 
           'anyport', 'servicepath', 
           'loglevel', 'logdir', 
           'enable', 'disable']
    for k in keys:
        pc[k] = getattr(options, k)
        
    try:
        exitCode = start(pc)
    except:
        logging.getLogger().exception('Untrapped error in PSC: ')
        exitCode = 99
        
    return exitCode