コード例 #1
0
ファイル: newkey.py プロジェクト: aquamatt/Peloton
def main():
    usage = "usage: %prog [options]"  # add 'arg1 arg2' etc as required
    parser = FilteredOptionParser(usage=usage, version="Peloton newkey version %s" % __VERSION__)
    parser.add_option(
        "--prefix",
        help="Path to directory containing configuration data, links to services etc. [default: %default]",
        default=peloton.getPlatformDefaultDir("config"),
    )

    parser.add_option(
        "-d",
        "--domain",
        help="""Specify the domain name for which to create a key [default: %default]""",
        default="Pelotonica",
    )

    parser.add_option(
        "-k", "--domainkey", help="""Domain key file [default: %default]""", default="$PREFIX/$DOMAIN.key"
    )

    parser.add_option("-c", "--console", help="""Send to console instead of file""", action="store_true", default=False)

    opts, args = parser.parse_args()
    if opts.console:
        outfile = None
    else:
        outfile = os.path.expanduser(opts.domainkey)
    f = makeKeyAndCookieFile(outfile, keylength, tokenlength)
    if opts.console:
        print f
    return 0
コード例 #2
0
ファイル: newservice.py プロジェクト: aquamatt/Peloton
def main(args):
    usage = "usage: %prog [options]" 
    parser = FilteredOptionParser(usage=usage, version="NEWSERVICE; Peloton version %s" % peloton.RELEASE_VERSION)

    parser.add_option("--prefix",
                     help="Directory in which to create this service [default: %default]",
                     default=os.getcwd())
    parser.add_option("--service", "-s",
                      help="Service name (camel case)")

    options, args = parser.parse_args()
    if not options.service:
        parser.error("You must provide a name for this service!")
    
    ServiceBuilder().makeService(options.prefix, options.service)
    
    return 0
コード例 #3
0
ファイル: psc.py プロジェクト: aquamatt/Peloton
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
コード例 #4
0
ファイル: testStructs.py プロジェクト: aquamatt/Peloton
 def setUp(self):
     self.fo = FilteredOptionParser()
     self.fo.add_option('--prefix', default='/etc/')
     self.fo.add_option('-c', dest='configdir', default='$PREFIX')
     self.fo.add_option('-o', dest='outputdir', default='/')
コード例 #5
0
ファイル: testStructs.py プロジェクト: aquamatt/Peloton
class Test_FilteredOptionParser(TestCase):
    def setUp(self):
        self.fo = FilteredOptionParser()
        self.fo.add_option('--prefix', default='/etc/')
        self.fo.add_option('-c', dest='configdir', default='$PREFIX')
        self.fo.add_option('-o', dest='outputdir', default='/')
        
    def tearDown(self):
        pass
    
    def test_noOpts(self):
        o,a = self.fo.parse_args([])
        self.assertEquals(o.prefix, '/etc/')
        self.assertEquals(o.configdir, '/etc/')
        self.assertEquals(o.outputdir, '/')
        
    def test_overidePrefix(self):
        o,a = self.fo.parse_args(['--prefix=/tmp'])
        self.assertEquals(o.prefix, '/tmp')
        self.assertEquals(o.configdir, '/tmp')
        self.assertEquals(o.outputdir, '/')
        
    def test_manualUse(self):
        o,a = self.fo.parse_args(['--prefix=/tmp', '-o', '$PREFIX/output'])
        self.assertEquals(o.prefix, '/tmp')
        self.assertEquals(o.configdir, '/tmp')
        self.assertEquals(o.outputdir, '/tmp/output')
        
    def test_filterArgs(self):
        o, a = self.fo.parse_args(['--prefix=/tmp', '$PREFIX/test.xml'])
        self.assertEquals(a[0], '/tmp/test.xml')
        
    def test_argsOnly(self):
        o, a = self.fo.parse_args(['$PREFIX/test.xml', '$PREFIX'])
        self.assertEquals(a[0], '/etc//test.xml')
        self.assertEquals(a[1], '/etc/')
        
    def test_overideSubstitutions(self):
        self.fo.setSubstitutions(prefix='/var')
        o,a = self.fo.parse_args(['-o', '$PREFIX/output'])
        self.assertEquals(o.prefix, '/var')
        self.assertEquals(o.configdir, '/var')
        self.assertEquals(o.outputdir, '/var/output')
        
    def test_complexOverideSubstitutions(self):
        self.fo.setSubstitutions(prefix='/var/$OUTPUTDIR/test')
        o,a = self.fo.parse_args(['-o','/usr/local'])
        self.assertEquals(o.prefix, '/var//usr/local/test')
        self.assertEquals(o.configdir, '/var//usr/local/test')
        self.assertEquals(o.outputdir, '/usr/local')
コード例 #6
0
ファイル: evtap.py プロジェクト: aquamatt/Peloton
def main():
    global tapConn, options, outputMessage
    usage = "usage: %prog [options]"
    parser = FilteredOptionParser(usage=usage, version="EVTAP version %s" % VERSION)

    parser.add_option("--host", "-H", help="Host for PSC to contact [default %default]", default="localhost")
    parser.add_option(
        "--key",
        "-k",
        help="""Message key - may include the wildcards 
 # (match zero or more tokens) or * (match a single token) as defined in the
 AMQP specification [default %default]""",
        default="psc.logging",
    )
    parser.add_option("--port", "-p", help="Port on which to connect [default %default]", default="9100")

    parser.add_option("--exchange", "-x", help="Exchange [default %default]", default="logging")

    parser.add_option("--enableirc", "-i", help="Enable IRC server output", action="store_true")

    parser.add_option("--irchost", help="IRC Server Hostname [default %default]", default="192.168.25.32")

    parser.add_option("--ircport", help="IRC Server port [default %default]", default="6667")

    parser.add_option(
        "--ircchannel", help="IRC channel on which to publish messages [default %default]", default="#peloton"
    )

    parser.add_option("--ircnick", help="IRC nickname [default %default]", default="peloton")

    options, args = parser.parse_args()

    if options.enableirc:
        outputMessage = connectIRC(options.irchost, int(options.ircport), options.ircchannel, options.ircnick)
        outputMessage("Bus2IRC bridge connected.")

    tapConn = tapcore.TAPConnector(options.host, int(options.port), "tap", "tap")
    tapConn.addListener("loggedin", tapConnected)
    tapConn.addListener("profileReceived", setProfile)
    tapConn.addListener("masterProfileReceived", setMasterProfile)
    tapConn.addListener("disconnected", disconnected)
    tapConn.start()
    return 0