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)
Beispiel #4
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)
Beispiel #5
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))
Beispiel #6
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)
 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')
Beispiel #8
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()
Beispiel #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()
 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)
 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')
Beispiel #12
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])
Beispiel #13
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())
Beispiel #14
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])
 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)
Beispiel #16
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)
Beispiel #17
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))
 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())
Beispiel #19
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
Beispiel #20
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()
Beispiel #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())