def testDefaultValueInHelp(self):
        parser = ParseArguments()
        parser.addOption('', '--option', help='Option with a default value of {default}', default=42)

        with stdout_replaced() as out:
            parser.print_help()
            self.assertTrue("Option with a default value of 42" in out.getvalue(), out.getvalue())
 def testDescription(self):
     description = "Very nice program."
     parser = ParseArguments(description=description)
     parser.addOption('', '--option')
     with stdout_replaced() as out:
         parser.print_help()
         s = out.getvalue()
         self.assertEquals(['Usage: _alltests.py [options]', '', description, '', 'Options:'], s.splitlines()[:5])
 def testEpilog(self):
     epilog = 'And this is how they lived happily ever after.'
     parser = ParseArguments(epilog=epilog)
     parser.addOption('', '--option')
     with stdout_replaced() as out:
         parser.print_help()
         s = out.getvalue()
         self.assertTrue(s.endswith('--option=<string>  \n\n{}\n'.format(epilog)), s)
Exemplo n.º 4
0
 def parse(cls):
     parser = ParseArguments()
     parser._parser.set_description("""Configures elasticsearch to start from given stateDir""")
     keys = ['default']
     keys.append('admin' if getuid() == 0 else 'user')
     for option in (o for k in keys for o in cls.options[k]):
         parser.addOption(option.shortOpt, option.longOpt, **option.kwargs)
     options, arguments = parser.parse()
     return cls(**vars(options))
 def testError(self):
     parser = ParseArguments()
     parser.addOption('', '--option')
     with stderr_replaced() as err:
         try:
             parser.error('error msg.')
             self.fail()
         except SystemExit, e:
             self.assertEquals(2, e.code)
         lines = err.getvalue().split('\n')
 def testAdditionalOptions_optional(self):
     argv = ['script', '--name', 'TestServer']
     parser = ParseArguments()
     parser.addOption('', '--name', help='Naam', mandatory=True)
     parser.addOption('', '--port', help='Port', type='int')
     parser.addOption('', '--withDefault', help='Default', default="default", type='str')
     options, arguments = parser.parse(argv)
     self.assertEquals('TestServer', options.name)
     self.assertEquals(None, options.port)
     self.assertEquals('default', options.withDefault)
Exemplo n.º 7
0
 def testAdditionalOptions_optional(self):
     argv = ['script', '--name', 'TestServer']
     parser = ParseArguments()
     parser.addOption('', '--name', help='Naam', mandatory=True)
     parser.addOption('', '--port', help='Port', type='int')
     parser.addOption('',
                      '--withDefault',
                      help='Default',
                      default="default",
                      type='str')
     options, arguments = parser.parse(argv)
     self.assertEqual('TestServer', options.name)
     self.assertEqual(None, options.port)
     self.assertEqual('default', options.withDefault)
Exemplo n.º 8
0
 def testMandatoryKey(self):
     parser = ParseArguments()
     parser.addOption('', '--name', help='Naam', mandatory=True)
     parser.addOption('', '--port', help='Port', type='int', mandatory=True)
     argv = ['script', '--name', 'TestServer', '--port', '1234']
     options, arguments = parser.parse(argv)
     self.assertEqual(1234, options.port)
     self.assertEqual('TestServer', options.name)
     argv = ['script', '--port', '1234']
     self.assertRaises(ValueError, parser._parse, argv)
Exemplo n.º 9
0
def main():
    parser = ParseArguments()
    parser.addOption('', '--port', type='int', mandatory=True)
    parser.addOption('', '--solrPort', type='int', mandatory=True)
    options, arguments = parser.parse()

    reactor = Reactor()
    server = createServer(reactor, **vars(options))
    list(compose(server.once.observer_init()))
    reactor.loop()
Exemplo n.º 10
0
 def testEpilog(self):
     epilog = 'And this is how they lived happily ever after.'
     parser = ParseArguments(epilog=epilog)
     parser.addOption('', '--option')
     with stdout_replaced() as out:
         parser.print_help()
         s = out.getvalue()
         self.assertTrue(
             s.endswith('--option=<string>  \n\n{}\n'.format(epilog)), s)
 def testError(self):
     parser = ParseArguments()
     parser.addOption('', '--option')
     with stderr_replaced() as err:
         try:
             parser.error('error msg.')
             self.fail()
         except SystemExit, e:
             self.assertEquals(2, e.code)
         lines = err.getvalue().split('\n')
Exemplo n.º 12
0
def main():
    parser = ParseArguments()
    parser.addOption('', '--port', type='int', mandatory=True)
    parser.addOption('', '--solrPort', type='int', mandatory=True)
    options, arguments = parser.parse()

    reactor = Reactor()
    server = createServer(reactor, **vars(options))
    list(compose(server.once.observer_init()))
    reactor.loop()
Exemplo n.º 13
0
 def testMandatoryKey(self):
     parser = ParseArguments()
     parser.addOption('', '--name', help='Naam', mandatory=True)
     parser.addOption('', '--port', help='Port', type='int', mandatory=True)
     argv = ['script', '--name', 'TestServer', '--port', '1234']
     options, arguments = parser.parse(argv)
     self.assertEquals(1234, options.port)
     self.assertEquals('TestServer', options.name)
     argv = ['script', '--port', '1234']
     self.assertRaises(ValueError, parser._parse, argv)
Exemplo n.º 14
0
 def testDescription(self):
     description = "Very nice program."
     parser = ParseArguments(description=description)
     parser.addOption('', '--option')
     with stdout_replaced() as out:
         parser.print_help()
         s = out.getvalue()
         self.assertEqual([
             'Usage: _alltests.py [options]', '', description, '',
             'Options:'
         ],
                          s.splitlines()[:5])
Exemplo n.º 15
0
    def testDefaultValueInHelp(self):
        parser = ParseArguments()
        parser.addOption('',
                         '--option',
                         help='Option with a default value of {default}',
                         default=42)

        with stdout_replaced() as out:
            parser.print_help()
            self.assertTrue(
                "Option with a default value of 42" in out.getvalue(),
                out.getvalue())
Exemplo n.º 16
0
    def testUsage(self):
        # default
        parser = ParseArguments()
        with stdout_replaced() as out:
            parser.print_help()
            s = out.getvalue()
            self.assertEquals(['Usage: _alltests.py [options]', ''], s.splitlines()[:2])

        # explicit default: "%prog [options]"
        usage = "%prog [options]"
        parser = ParseArguments(usage=usage)
        with stdout_replaced() as out:
            parser.print_help()
            s = out.getvalue()
            self.assertEquals(['Usage: _alltests.py [options]', ''], s.splitlines()[:2])

        # decidedly different
        usage = "|before| %prog [options] [more-stuff]"
        parser = ParseArguments(usage=usage)
        with stdout_replaced() as out:
            parser.print_help()
            s = out.getvalue()
            self.assertEquals(['Usage: |before| _alltests.py [options] [more-stuff]', ''], s.splitlines()[:2])
Exemplo n.º 17
0
    def testError(self):
        parser = ParseArguments()
        parser.addOption('', '--option')
        with stderr_replaced() as err:
            try:
                parser.error('error msg.')
                self.fail()
            except SystemExit as e:
                self.assertEqual(2, e.code)
            lines = err.getvalue().split('\n')

        self.assertEqual(4, len(lines))
        self.assertTrue(lines[0].startswith('Usage: '))
        self.assertEqual('', lines[1])
        self.assertTrue(lines[2].endswith(': error: error msg.'))
        self.assertEqual('', lines[3])
Exemplo n.º 18
0
def startServer(stateDir, **kwargs):
    setSignalHandlers()
    print 'Firing up Meresco Lucene Server.'
    reactor = Reactor()
    databasePath = realpath(abspath(stateDir))

    #main
    dna = main(reactor, databasePath=databasePath, **kwargs)
    #/main

    server = be(dna)
    list(compose(server.once.observer_init()))

    print "Ready to rumble"
    stdout.flush()
    reactor.loop()

if __name__ == '__main__':
    parser = ParseArguments()
    parser.addOption('', '--port',
        mandatory=True,
        type='int',
        help="Port at which webpages are served.")
    parser.addOption('', '--stateDir', mandatory=True, type='str', help='Directory for state')
    parser.addOption('', '--serverPort', mandatory=True, type='int', help='Lucene server port')
    parser.addOption('', '--autocompletePort', mandatory=True, type='int', help='Autocomplete server port')
    options, arguments = parser.parse()

    startServer(**vars(options))
Exemplo n.º 19
0
    def testUsage(self):
        # default
        parser = ParseArguments()
        with stdout_replaced() as out:
            parser.print_help()
            s = out.getvalue()
            self.assertEqual(['Usage: _alltests.py [options]', ''],
                             s.splitlines()[:2])

        # explicit default: "%prog [options]"
        usage = "%prog [options]"
        parser = ParseArguments(usage=usage)
        with stdout_replaced() as out:
            parser.print_help()
            s = out.getvalue()
            self.assertEqual(['Usage: _alltests.py [options]', ''],
                             s.splitlines()[:2])

        # decidedly different
        usage = "|before| %prog [options] [more-stuff]"
        parser = ParseArguments(usage=usage)
        with stdout_replaced() as out:
            parser.print_help()
            s = out.getvalue()
            self.assertEqual(
                ['Usage: |before| _alltests.py [options] [more-stuff]', ''],
                s.splitlines()[:2])
Exemplo n.º 20
0
 def testMetaVars(self):
     parser = ParseArguments()
     parser.addOption('', '--option')
     parser.addOption('', '--defaultValue', default='default')
     parser.addOption('', '--noneValue', default=None)
     parser.addOption('', '--port', help='Port', type='int')
     parser.addOption('', '--otherPort', help='Port', type='int', default=10000)
     parser.addOption('', '--quiet', action='store_false', default=True, dest='verbose')
     with stdout_replaced() as out:
         parser.print_help()
         self.assertTrue("--option=<string>" in out.getvalue(), out.getvalue())
         self.assertTrue("--defaultValue='default'" in out.getvalue(), out.getvalue())
         self.assertTrue("--noneValue=<string>" in out.getvalue(), out.getvalue())
         self.assertTrue("--port=<int>" in out.getvalue(), out.getvalue())
         self.assertTrue("--otherPort=10000" in out.getvalue(), out.getvalue())
Exemplo n.º 21
0
 def testMetaVars(self):
     parser = ParseArguments()
     parser.addOption('', '--option')
     parser.addOption('', '--defaultValue', default='default')
     parser.addOption('', '--noneValue', default=None)
     parser.addOption('', '--port', help='Port', type='int')
     parser.addOption('',
                      '--otherPort',
                      help='Port',
                      type='int',
                      default=10000)
     parser.addOption('',
                      '--quiet',
                      action='store_false',
                      default=True,
                      dest='verbose')
     with stdout_replaced() as out:
         parser.print_help()
         self.assertTrue("--option=<string>" in out.getvalue(),
                         out.getvalue())
         self.assertTrue("--defaultValue='default'" in out.getvalue(),
                         out.getvalue())
         self.assertTrue("--noneValue=<string>" in out.getvalue(),
                         out.getvalue())
         self.assertTrue("--port=<int>" in out.getvalue(), out.getvalue())
         self.assertTrue("--otherPort=10000" in out.getvalue(),
                         out.getvalue())
Exemplo n.º 22
0
 def createParserWithDefaults(nameMandatory=False):
     parser = ParseArguments()
     parser.addOption('', '--adminHostname', help='Admin hostname', mandatory=True)
     parser.addOption('', '--adminPort', help='Admin port', default=10000, type='int')
     parser.addOption('-q', '--quiet', help="Disable apache logging.", action="store_false", default=True, dest="verbose")
     if nameMandatory:
         parser.addOption('-n', '--name', help='Service name', mandatory=True)
     else:
         parser.addOption('-n', '--name', default='', help='Service name, defaults to ""')
     parser.addOption('', '--nginxReload', type='str', help='The command to reload nginx (default: "{default}")', default=defaultNginxReloadCmd)
     parser.addOption('', '--sharedSecret', help='Shared secret for updating as a service in admin', mandatory=True)
     return parser
Exemplo n.º 23
0
                ),
                (PathFilter("/ready"),
                    (StringServer('yes', ContentTypePlainText),)
                )
            )
        )
    )
    list(compose(server.once.observer_init()))
    for i in range(1,16):
        if i == 2:
            identifier = 'oai:record:02/&gkn'
        else:
            identifier = 'oai:record:%02d' % i
        oaiStorage.addData(identifier=identifier, name='oai_dc', data='''<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dc="http://purl.org/dc/elements/1.1/" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"><dc:identifier>%s</dc:identifier></oai_dc:dc>''' % escapeXml(identifier))
        oaiJazz.addOaiRecord(identifier=identifier, metadataFormats=[('oai_dc', 'http://www.openarchives.org/OAI/2.0/oai_dc.xsd', 'http://www.openarchives.org/OAI/2.0/oai_dc/')])
        if i in [3,6]:
            list(compose(oaiJazz.delete(identifier=identifier)))

if __name__== '__main__':
    parser = ParseArguments()
    parser.addOption('', '--port', mandatory=True, type=int)
    parser.addOption('', '--directory', mandatory=True)
    options, arguments = parser.parse()

    reactor = Reactor()
    main(reactor, **vars(options))
    print 'Ready to rumble the dumpserver at', options.port
    print '  - dumps are written to', join(options.directory, 'dump')
    stdout.flush()
    reactor.loop()