Esempio n. 1
0
 def testFlagHelpInXML_MultiInt(self):
     gflags.DEFINE_multi_int('cols', [5, 7, 23],
                             'Columns to select',
                             flag_values=self.fv)
     expected_output = (
         ' <flag>\n'
         '   <file>tool</file>\n'
         '   <name>cols</name>\n'
         '   <meaning>Columns to select;\n    '
         'repeat this option to specify a list of values</meaning>\n'
         '   <default>[5, 7, 23]</default>\n'
         '   <current>[5, 7, 23]</current>\n'
         '   <type>multi int</type>\n'
         ' </flag>\n')
     self._CheckFlagHelpInXML('cols', 'tool', expected_output)
Esempio n. 2
0
File: trade.py Progetto: aw1n/testeo
#!/usr/bin/python
import os
import sys

import gflags
import pandas as pd
import numpy as np

from market import market
from portfolio import portfolio
from simulations_code import simulate

gflags.DEFINE_multi_int('hour', 24, 'Hours in between market')
gflags.DEFINE_float(
    'min_percentage_change', 0.1,
    "Minimum variation in 'balance' needed to place an order."
    "1 is 100%")
gflags.DEFINE_string('state_csv', None, "path to csv containing a 'state'")
FLAGS = gflags.FLAGS
gflags.RegisterValidator('min_percentage_change', lambda x: x >= 0,
                         'Should be positive or 0')
#gflags.RegisterValidator('state_csv', os.path.isfile)

if __name__ == "__main__":
    try:
        argv = FLAGS(sys.argv)
    except gflags.FlagsError as e:
        print "%s\nUsage: %s ARGS\n%s" % (e, sys.argv[0], FLAGS)
        sys.exit(1)

    print '*' * 80
Esempio n. 3
0
    from urlparse import parse_qsl
except ImportError:
    from cgi import parse_qsl

FLAGS = gflags.FLAGS

gflags.DEFINE_boolean('auth_local_webserver', True,
                      ('Run a local web server to handle redirects during '
                       'OAuth authorization.'))

gflags.DEFINE_string('auth_host_name', 'localhost',
                     ('Host name to use when running a local web server to '
                      'handle redirects during OAuth authorization.'))

gflags.DEFINE_multi_int('auth_host_port', [8080, 8090],
                        ('Port to use when running a local web server to '
                         'handle redirects during OAuth authorization.'))


class ClientRedirectServer(BaseHTTPServer.HTTPServer):
    """A server to handle OAuth 2.0 redirects back to localhost.

  Waits for a single request and parses the query parameters
  into query_params and then stops serving.
  """
    query_params = {}


class ClientRedirectHandler(BaseHTTPServer.BaseHTTPRequestHandler):
    """A handler for OAuth 2.0 redirects back to localhost.
Esempio n. 4
0
    def testWriteHelpInXMLFormat(self):
        fv = gflags.FlagValues()
        # Since these flags are defined by the top module, they are all key.
        gflags.DEFINE_integer('index', 17, 'An integer flag', flag_values=fv)
        gflags.DEFINE_integer('nb_iters',
                              17,
                              'An integer flag',
                              lower_bound=5,
                              upper_bound=27,
                              flag_values=fv)
        gflags.DEFINE_string('file_path',
                             '/path/to/my/dir',
                             'A test string flag.',
                             flag_values=fv)
        gflags.DEFINE_boolean('use_hack',
                              False,
                              'Use performance hack',
                              flag_values=fv)
        gflags.DEFINE_enum('cc_version',
                           'stable', ['stable', 'experimental'],
                           'Compiler version to use.',
                           flag_values=fv)
        gflags.DEFINE_list('files',
                           'a.cc,a.h,archive/old.zip',
                           'Files to process.',
                           flag_values=fv)
        gflags.DEFINE_list('allow_users', ['alice', 'bob'],
                           'Users with access.',
                           flag_values=fv)
        gflags.DEFINE_spaceseplist('dirs',
                                   'src libs bins',
                                   'Directories to create.',
                                   flag_values=fv)
        gflags.DEFINE_multistring('to_delete', ['a.cc', 'b.h'],
                                  'Files to delete',
                                  flag_values=fv)
        gflags.DEFINE_multi_int('cols', [5, 7, 23],
                                'Columns to select',
                                flag_values=fv)
        # Define a few flags in a different module.
        module_bar.DefineFlags(flag_values=fv)
        # And declare only a few of them to be key.  This way, we have
        # different kinds of flags, defined in different modules, and not
        # all of them are key flags.
        gflags.DECLARE_key_flag('tmod_bar_z', flag_values=fv)
        gflags.DECLARE_key_flag('tmod_bar_u', flag_values=fv)

        # Generate flag help in XML format in the StringIO sio.
        sio = StringIO.StringIO()
        fv.WriteHelpInXMLFormat(sio)

        # Check that we got the expected result.
        expected_output_template = EXPECTED_HELP_XML_START
        main_module_name = gflags._GetMainModule()
        module_bar_name = module_bar.__name__

        if main_module_name < module_bar_name:
            expected_output_template += EXPECTED_HELP_XML_FOR_FLAGS_FROM_MAIN_MODULE
            expected_output_template += EXPECTED_HELP_XML_FOR_FLAGS_FROM_MODULE_BAR
        else:
            expected_output_template += EXPECTED_HELP_XML_FOR_FLAGS_FROM_MODULE_BAR
            expected_output_template += EXPECTED_HELP_XML_FOR_FLAGS_FROM_MAIN_MODULE

        expected_output_template += EXPECTED_HELP_XML_END

        # XML representation of the whitespace list separators.
        whitespace_separators = _ListSeparatorsInXMLFormat(string.whitespace,
                                                           indent='    ')
        expected_output = (expected_output_template % {
            'usage_doc': sys.modules['__main__'].__doc__,
            'main_module_name': main_module_name,
            'module_bar_name': module_bar_name,
            'whitespace_separators': whitespace_separators
        })

        actual_output = sio.getvalue()
        self.assertMultiLineEqual(actual_output, expected_output)

        # Also check that our result is valid XML.  minidom.parseString
        # throws an xml.parsers.expat.ExpatError in case of an error.
        xml.dom.minidom.parseString(actual_output)