def _DefineFlagAndValidators(self, first_validator, second_validator):
   local_flags = gflags.FlagValues()
   gflags.DEFINE_integer('test_flag', 2, 'test flag', flag_values=local_flags)
   gflags.RegisterValidator('test_flag',
                           first_validator,
                           message='',
                           flag_values=local_flags)
   gflags.RegisterValidator('test_flag',
                           second_validator,
                           message='',
                           flag_values=local_flags)
   argv = ('./program')
   local_flags(argv)
Ejemplo n.º 2
0
def DEFINE_linspace(name,
                    default,
                    help_string,
                    nonempty=False,
                    increasing=False,
                    flag_values=gflags.FLAGS,
                    **kwargs):  # pylint: disable=invalid-name
    """Defines a 'linspace' flag.

  The flag value should be specified as <lower>,<upper>,<count>.  The
  components are used as arguments to numpy.linspace, so they must be
  parsable as float, float, and int, respectively.  The parsed flag
  value will be a 1-dimensional numpy.ndarray.

  Args:
    name: Name of the flag.
    default: Default value (as unparsed string), or None if flag is unset by
        default.
    help_string: Helpful description of the flag.
    nonempty: Indicates whether the flag value is required to be nonempty.  If
        True, None is still an allowable default.  Use gflags.MarkFlagAsRequired
        to disallow None.
    increasing: Indicates whether the flag value should be an increasing array.
        This is only enforced if the parsed value has >=2 elements.
    flag_values: The gflags.FlagValues object in which to define the flag.
    **kwargs: See gflags.DEFINE.
  """
    gflags.DEFINE(_LinspaceParser(),
                  name,
                  default,
                  help_string,
                  flag_values=flag_values,
                  **kwargs)

    if nonempty:
        # numpy.array can't be implicitly converted to a boolean.
        # pylint: disable=g-explicit-length-test
        gflags.RegisterValidator(name,
                                 lambda v: len(v) > 0,
                                 '--%s must specify a nonempty range.' % name,
                                 flag_values=flag_values)

    if increasing:
        gflags.RegisterValidator(name,
                                 lambda v: len(v) < 2 or v[-1] > v[0],
                                 '--%s must specify an increasing range.',
                                 flag_values=flag_values)
Ejemplo n.º 3
0
def main(argv):
    """Entry point."""

    gflags.RegisterValidator('ccx_file',
                             lambda f: f.endswith('.ccx'),
                             message='Expected a .ccx file.')
    try:
        argv = FLAGS(argv)
    except gflags.FlagsError, e:
        print '{}\nUsage: {} ARGS\n{}'.format(e, sys.argv[0], FLAGS)
        sys.exit(1)
Ejemplo n.º 4
0
def main(argv):
  """Implement a simple demo for computing error CDFs."""
  # Input/output flags.
  gflags.DEFINE_string('input_file', None, 'Full path to wing HDF5 log file.')
  gflags.MarkFlagAsRequired('input_file')
  gflags.DEFINE_string('output_file', None, 'Full path to output MAT file.')
  gflags.MarkFlagAsRequired('output_file')

  # Segment processing flags.
  gflags.DEFINE_integer('increment', 100,
                        'Integer number of messages between segments.')
  gflags.DEFINE_integer('seg_length', 1000,
                        'Integer number of messages in each segment.')

  # Evaluate segments over a specific time interval.
  gflags.DEFINE_float('start_time', -float('inf'),
                      'Start time to evaluate segment errors.')
  gflags.DEFINE_float('end_time', float('inf'),
                      'End time to evaluate segment errors.')

  # Override default parameters.
  gflags.DEFINE_list('params', [],
                     'A comma-separated list of param=value tokens, where '
                     'each param describes the dot path to a parameter in '
                     'EstimatorParams.')
  gflags.RegisterValidator('params',
                           lambda l: all(len(s.split('=')) == 2 for s in l),
                           message='Invalid key=value parameter syntax.')

  # Scenarios to process.
  gflags.DEFINE_bool('scenario_pure_inertial', False,
                     'Process pure inertial scenario.')
  gflags.DEFINE_bool('scenario_gps_dropout', False,
                     'Process GPS dropout scenario.')

  # Common faults to introduce.
  gflags.DEFINE_bool('fault_weather', False,
                     'Fault weather subsystems to avoid an assert when '
                     'reprocessing historical data.')
  gflags.DEFINE_bool('fault_glas', False, 'Fault GLAS subsystems.')

  # Specify flight for special handling.
  gflags.DEFINE_string('flight', None,
                       'Fix known issues associated with the given flight.')

  try:
    argv = gflags.FLAGS(argv)
  except gflags.FlagsError, e:
    print '{}\nUsage: {} ARGS\n{}'.format(e, sys.argv[0], gflags.FLAGS)
    sys.exit(1)
  def testDefaultValueNotUsedSuccess(self):
    def Checker(x):
      self.call_args.append(x)
      return True
    gflags.DEFINE_integer('test_flag', None, 'Usual integer flag',
                         flag_values=self.flag_values)
    gflags.RegisterValidator('test_flag',
                            Checker,
                            message='Errors happen',
                            flag_values=self.flag_values)

    argv = ('./program', '--test_flag=1')
    self.flag_values(argv)
    self.assertEquals(1, self.flag_values.test_flag)
    self.assertEquals([1], self.call_args)
  def testErrorMessageWhenCheckerRaisesExceptionOnStart(self):
    def Checker(x):
      self.call_args.append(x)
      raise gflags_validators.Error('Specific message')
    gflags.DEFINE_integer('test_flag', None, 'Usual integer flag',
                         flag_values=self.flag_values)
    gflags.RegisterValidator('test_flag',
                            Checker,
                            message='Errors happen',
                            flag_values=self.flag_values)

    argv = ('./program', '--test_flag=1')
    try:
      self.flag_values(argv)
      raise AssertionError('IllegalFlagValue expected')
    except gflags.IllegalFlagValue, e:
      self.assertEquals('flag --test_flag=1: Specific message', str(e))
  def testValidatorNotCalledWhenOtherFlagIsChanged(self):
    def Checker(x):
      self.call_args.append(x)
      return True
    gflags.DEFINE_integer('test_flag', 1, 'Usual integer flag',
                         flag_values=self.flag_values)
    gflags.DEFINE_integer('other_flag', 2, 'Other integer flag',
                         flag_values=self.flag_values)
    gflags.RegisterValidator('test_flag',
                            Checker,
                            message='Errors happen',
                            flag_values=self.flag_values)

    argv = ('./program')
    self.flag_values(argv)
    self.assertEquals(1, self.flag_values.test_flag)
    self.flag_values.other_flag = 3
    self.assertEquals([1], self.call_args)
Ejemplo n.º 8
0
  def testSuccess(self):
    def Checker(x):
      self.call_args.append(x)
      return True
    gflags.DEFINE_integer('test_flag', None, 'Usual integer flag',
                         flag_values=self.flag_values)
    gflags.RegisterValidator('test_flag',
                            Checker,
                            message='Errors happen',
                            flag_values=self.flag_values)

    argv = ('./program')
    self.flag_values(argv)
    self.assertEquals(None, self.flag_values.test_flag)
    self.flag_values.test_flag = 2
    self.assertEquals(2, self.flag_values.test_flag)
    self.assertEquals([None, 2][0], self.call_args[0])
    self.assertEquals([None, 2][1], self.call_args[1])
  def testExceptionRaisedIfCheckerFails(self):
    def Checker(x):
      self.call_args.append(x)
      return x == 1
    gflags.DEFINE_integer('test_flag', None, 'Usual integer flag',
                         flag_values=self.flag_values)
    gflags.RegisterValidator('test_flag',
                            Checker,
                            message='Errors happen',
                            flag_values=self.flag_values)

    argv = ('./program', '--test_flag=1')
    self.flag_values(argv)
    try:
      self.flag_values.test_flag = 2
      raise AssertionError('gflags.IllegalFlagValue expected')
    except gflags.IllegalFlagValue, e:
      self.assertEquals('flag --test_flag=2: Errors happen', str(e))
Ejemplo n.º 10
0
  def testExceptionRaisedIfCheckerRaisesException(self):
    def Checker(x):
      self.call_args.append(x)
      if x == 1:
        return True
      raise gflags_validators.Error('Specific message')
    gflags.DEFINE_integer('test_flag', None, 'Usual integer flag',
                         flag_values=self.flag_values)
    gflags.RegisterValidator('test_flag',
                            Checker,
                            message='Errors happen',
                            flag_values=self.flag_values)

    argv = ('./program', '--test_flag=1')
    self.flag_values(argv)
    try:
      self.flag_values.test_flag = 2
      raise AssertionError('gflags.IllegalFlagValue expected')
    except gflags.IllegalFlagValue as e:
      self.assertEquals('flag --test_flag=2: Specific message', str(e))
    self.assertEquals([1, 2], self.call_args)
Ejemplo n.º 11
0
    def testErrorMessageWhenCheckerReturnsFalseOnStart(self):
        def Checker(x):
            self.call_args.append(x)
            return False

        gflags.DEFINE_integer('test_flag',
                              None,
                              'Usual integer flag',
                              flag_values=self.flag_values)
        gflags.RegisterValidator('test_flag',
                                 Checker,
                                 message='Errors happen',
                                 flag_values=self.flag_values)

        argv = ('./program', '--test_flag=1')
        try:
            self.flag_values(argv)
            raise AssertionError('gflags.IllegalFlagValue expected')
        except gflags.IllegalFlagValue as e:
            self.assertEqual('flag --test_flag=1: Errors happen', str(e))
        self.assertEqual([1], self.call_args)
Ejemplo n.º 12
0
import boto
import boto.sqs
import boto.sdb
import boto.s3
import json
import gflags
from fractions import Fraction
FLAGS = gflags.FLAGS

gflags.DEFINE_string('source', None, 'Source SQS queue to read from')
gflags.RegisterValidator('source', lambda x: x is not None,
                         'You must specify a source queue')
gflags.DEFINE_multistring('targets', [], 'Select SQS queue target')
gflags.DEFINE_string('region', 'us-west-1', 'AWS region to connect to')
gflags.DEFINE_string('bucket', 'wnyc.org-foliage-exif', 'bucket to read from')
gflags.RegisterValidator('bucket', lambda x: x is not None,
                         'You must specify a bucket')
gflags.DEFINE_string('domain', None, 'Domain')
gflags.DEFINE_float('threshold', 5.0, 'Brightness threshold for outdoors')


def main(argv=None, stdin=None, stdout=None, stderr=None):
    import sys
    argv = argv or sys.argv
    stdin = stdin or sys.stdin
    stdout = stdout or sys.stdout
    stderr = stderr or sys.stderr

    try:
        argv = FLAGS(argv)[1:]
    except gflags.FlagsError, e:
Ejemplo n.º 13
0
                                override_method='derived')

    # Write parameters to the output_file or to stdout.
    if FLAGS.output_file is None:
        print params
    else:
        if FLAGS.type == 'json':
            WriteJsonParams(params, FLAGS.output_file)
        elif FLAGS.type == 'control':
            WriteDefaultControlParams(params, FLAGS.output_file)
        elif FLAGS.type == 'monitor':
            WriteDefaultMonitorParams(params, FLAGS.output_file)
        elif FLAGS.type == 'sim':
            WriteDefaultSimParams(params, FLAGS.output_file)
        elif FLAGS.type == 'system':
            WriteDefaultSystemParams(params, FLAGS.output_file)
        else:
            assert False, '--type was not properly validated.'


if __name__ == '__main__':
    gflags.RegisterValidator('input_file',
                             lambda f: f is None or os.path.isfile(f),
                             message='input_file does not exist.')
    gflags.RegisterValidator(
        'input_file',
        lambda f: f is None or (f.startswith('config/') and f.endswith('.py')),
        message='input_file must be a .py file under the config/ directory.')

    main(sys.argv)
Ejemplo n.º 14
0
    u"Backend type for MinQL server")

gflags.DEFINE_string('dbname', u"dbname",
    u"Backend db name for MinQL server")

gflags.DEFINE_string('dbuser', u"dbuser",
    u"Backend db user for MinQL server")

gflags.DEFINE_string('dbpass', u"dbpass",
    u"Backend db password for MinQL server")

gflags.DEFINE_integer('workers', 10,
    u"Number of proxy Workers",
    short_name='w')
gflags.RegisterValidator('workers',
    lambda workers: 1 <= workers <= 50,
    message=u"Number of workers must be between 1 and 50.")

gflags.DEFINE_string('schema', u"",
    u"Schema for MinQL server")

gflags.DEFINE_string('dataset', u"",
    u"Dataset for MinQL server")

try:
    import sys
    argv = gflags.FLAGS(sys.argv)
except gflags.FlagsError, e:
    print('%s\n\nUsage %s ARGS \n%s' % (e, sys.argv[0], gflags.FLAGS))
    sys.exit(0)
FLAGS = gflags.FLAGS
Ejemplo n.º 15
0
from makani.sim.physics import physics
from matplotlib import pyplot
import numpy as np

FLAGS = gflags.FLAGS

flag_types.DEFINE_linspace('alphas_deg', '-10.0, 10.0, 20',
                           'Linspace range of angle-of-attack values [deg].')
flag_types.DEFINE_linspace('betas_deg', '-15.0, 15.0, 20',
                           'Linspace range of sideslip angles [deg].')
gflags.DEFINE_boolean('plot_sim', False,
                      'Whether to display the sim aero model.')
gflags.DEFINE_list('flaps_deg', [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                   'Flap deflections [deg].')
gflags.RegisterValidator('flaps_deg',
                         lambda x: len(x) == system_types.kNumFlaps,
                         'Wrong number of flaps in input.')
gflags.DEFINE_float('reynolds_number', 1e6,
                    'Reynolds number for the simulator.')
gflags.DEFINE_float('p_hat', 0.0, 'Normalized roll rate.')
gflags.DEFINE_float('q_hat', 0.0, 'Normalized pitch rate.')
gflags.DEFINE_float('r_hat', 0.0, 'Normalized yaw rate.')
gflags.DEFINE_float('thrust_coeff', 0.0, 'Total thrust coefficient.')


def _SwigVec3ToArray(v):
    """Converts a Swig Vec3 data structure to an array."""
    return np.array([v.x, v.y, v.z])


def _ArrayToSwigVec3(a):
Ejemplo n.º 16
0
    # Within the cache directory, the path is the GCS path with "gs://" stripped
    # off.
    cached_file = os.path.join(cache_dir, FLAGS.gcs_path[5:])

    for i in range(5):
        try:
            DownloadFileIfNecessary(cached_file, FLAGS.sha256, FLAGS.gcs_path)
        except ValueError:
            continue  # retry
        else:
            break

    if FLAGS.gunzip:
        with gzip.open(cached_file, 'rb') as source:
            with open(FLAGS.output_path, 'wb') as dest:
                dest.write(source.read())
    else:
        shutil.copyfile(cached_file, FLAGS.output_path)


if __name__ == '__main__':
    gflags.MarkFlagAsRequired('gcs_path')
    gflags.RegisterValidator('gcs_path', lambda p: p.startswith('gs://'))
    gflags.MarkFlagAsRequired('package')
    gflags.MarkFlagAsRequired('target')
    gflags.MarkFlagAsRequired('sha256')
    gflags.MarkFlagAsRequired('output_path')

    main(sys.argv)
Ejemplo n.º 17
0
gflags.DEFINE_multistring(
    'empty_root_dir',
    [],
    'An empty root directory to add to the layer.  This will create a directory that'
    'is a peer of "root_directory".  "empty_dir" creates an empty directory inside of'
    '"root_directory"')

gflags.DEFINE_multistring('tar', [], 'A tar file to add to the layer')

gflags.DEFINE_multistring('deb', [], 'A debian package to add to the layer')

gflags.DEFINE_multistring(
    'link', [],
    'Add a symlink a inside the layer ponting to b if a:b is specified')
gflags.RegisterValidator(
    'link',
    lambda l: all(value.find(':') > 0 for value in l),
    message='--link value should contains a : separator')

gflags.DEFINE_string(
    'directory', None, 'Directory in which to store the file inside the layer')

gflags.DEFINE_string(
    'compression', None, 'Compression (`gz` or `bz2`), default is none.')

gflags.DEFINE_multistring(
    'modes', None,
    'Specific mode to apply to specific file (from the file argument),'
    ' e.g., path/to/file=0o455.')

gflags.DEFINE_multistring('owners', None,
                          'Specify the numeric owners of individual files, '
Ejemplo n.º 18
0
gflags.DEFINE_bool("plot", True,
                   "Enable/disable plotting of the resulting data.")

gflags.DEFINE_bool("verbose", False,
                   "Verbose mode: print extra details.",
                   short_name='v')
gflags.DEFINE_bool("api", True,
                   ("Use http API rather than 'bq' executable, say --noapi "+
                    "to use 'bq' command-line tool instead."))

gflags.DEFINE_string('priority', 'INTERACTIVE',
                     'Priority at which to run the query',
                     short_name = 'p')
gflags.RegisterValidator('priority',
                         lambda value: value in [ 'BATCH', 'INTERACTIVE' ],
                         message='--priority must be "BATCH" or "INTERACTIVE"')

def cmd_exists(cmd):
    """ Returns: bool, True if 'cmd' is in PATH, False otherwise."""
    return subprocess.call("type " + cmd, shell=True, 
                           stdout=subprocess.PIPE, 
                           stderr=subprocess.PIPE) == 0

def bigquery_exec(query_string, output_filename, options):
    """ A wrapper for the 'bq' command line tool.
        Args:
            query_string - a bigquery-SQL query. Since this must be passed to
                          'bq' via the command line, mind your use of quotes.
                          TODO: find a way to call the bq python function.
            output_filename - filename to save results.  If None, a temporary
Ejemplo n.º 19
0
import boto
import boto.sdb
from boto.sqs.connection import SQSConnection
from boto.sqs.message import Message

import gflags
import time
import datetime
import json

FLAGS = gflags.FLAGS

gflags.DEFINE_multistring('targets', [], 'Select SQS queue target')
gflags.DEFINE_string('region', 'us-west-1', 'AWS region to connect to')
gflags.DEFINE_string('bucket', None, 'bucket to read from')
gflags.RegisterValidator('bucket', lambda x: x is not None,
                         'You must specify a bucket')
gflags.DEFINE_string('domain', 'foliage', 'Domain')


def main(argv=None, stdin=None, stdout=None, stderr=None):
    import sys
    argv = argv or sys.argv
    stdin = stdin or sys.stdin
    stdout = stdout or sys.stdout
    stderr = stderr or sys.stderr

    try:
        argv = FLAGS(argv)[1:]
    except gflags.FlagsError, e:
        stderr.write("%s\\nUsage: %s update_id_addresses\\n%s\n" %
                     (e, sys.argv[0], FLAGS))
Ejemplo n.º 20
0
FLAGS = gflags.FLAGS
gflags.DEFINE_bool("subject", False,
                   "Print option: prints certificate subject")
gflags.DEFINE_bool("issuer", False, "Print option: prints certificate issuer")
gflags.DEFINE_bool("fingerprint", False, "Print option: prints certificate "
                   "fingerprint")
gflags.DEFINE_string("digest", "sha1",
                     "Print option: fingerprint digest to use")
gflags.DEFINE_bool("debug", False,
                   "Print option: prints full ASN.1 debug information")
gflags.DEFINE_string(
    "filetype", "", "Read option: specify an input file "
    "format (pem or der). If no format is specified, the "
    "parser attempts to detect the format automatically.")
gflags.RegisterValidator(
    "filetype",
    lambda value: not value or value.lower() in {"pem", "der"},
    message="--filetype must be one of pem or der")


def print_cert(certificate):
    if not FLAGS.subject and not FLAGS.issuer and not FLAGS.fingerprint:
        if FLAGS.debug:
            print "%r" % certificate
        else:
            print certificate
    else:
        if FLAGS.subject:
            print "subject:\n%s" % certificate.print_subject_name()
        if FLAGS.issuer:
            print "issuer:\n%s" % certificate.print_issuer_name()
        if FLAGS.fingerprint:
Ejemplo n.º 21
0
from makani.lib.python import wing_flag
from makani.lib.python.batch_sim import batch_sim_util
from makani.lib.python.batch_sim import gcloud_constants
from makani.lib.python.batch_sim import gcloud_util

wing_flag.AppeaseLintWhenImportingFlagOnly()

gflags.DEFINE_boolean('upload_worker_package', True, 'Upload worker package.')

gflags.DEFINE_integer('num_workers', None, 'Number of worker instances.')

gflags.DEFINE_integer(
    'max_jobs_per_worker', None,
    'Set number of workers to assign at most this many '
    'configs per worker.')
gflags.RegisterValidator('max_jobs_per_worker', lambda m: m is None or m > 0)

gflags.DEFINE_bool(
    'delete_old_workers', False,
    'Delete workers left from a previous run. Do not run '
    'a new batch sim.')

gflags.DEFINE_string(
    'sim_name', None, 'Name of the batch simulation.  This must not match the '
    'name of any currently-running batch simulation, as it '
    'identifies file paths on Cloud Storage and worker '
    'instances on Compute Engine.')

gflags.DEFINE_string(
    'local_output_dir', None, 'Directory in which to store local output.  If '
    'unspecified, a temp directory will be used.')
Ejemplo n.º 22
0
gflags.DEFINE_integer(
    'N',
    300,
    'Number of samples to use',
)

gflags.DEFINE_string(
    'metric',
    'rbf',
    'Kernel metric',
)

gflags.RegisterValidator(
    'metric', lambda x: x in
    ['rbf', 'sigmoid', 'polynomial', 'poly', 'linear', 'cosine'],
    "metric must be in ['rbf', 'sigmoid', 'polynomial', 'poly', 'linear', 'cosine']"
)

gflags.DEFINE_float(
    'xmax',
    16.0,
    'Heatmap plot limit',
)
gflags.DEFINE_float(
    'gamma',
    0.2,
    'Kernel size parameter, as in exp(-gamma d^2) for RBF',
)
gflags.DEFINE_string(
    'dataset',
Ejemplo n.º 23
0
                      'maximum dimension for uploaded encrypted image',
                      short_name='m')
gflags.DEFINE_boolean('enable_diff', False, 'slow diff coordinates image')
gflags.DEFINE_string('password',
                     None,
                     'Password to encrypt image with.',
                     short_name='p')
gflags.DEFINE_integer('threads', 1, 'number of threads', short_name='t')
gflags.DEFINE_boolean('extra_logs', False, 'write extra logs')

gflags.DEFINE_boolean('ecc', False, 'Use ECC encoding.')
gflags.DEFINE_integer('ecc_n', 128, 'codeword length', short_name='n')
gflags.DEFINE_integer('ecc_k', 64, 'message byte length', short_name='k')

gflags.RegisterValidator('encrypted_image_quality',
                         lambda x: x > 0 and x <= 95,
                         message='jpeg quality range',
                         flag_values=FLAGS)
gflags.RegisterValidator('scale',
                         lambda x: x > 0,
                         message='image scaling fraction',
                         flag_values=FLAGS)
gflags.RegisterValidator('ecc_n',
                         lambda x: x <= 255 and x > FLAGS.ecc_k,
                         message='Reed Solomon boundaries',
                         flag_values=FLAGS)
gflags.RegisterValidator('ecc_k',
                         lambda x: x > 0,
                         message='Reed Solomon boundaries',
                         flag_values=FLAGS)

gflags.MarkFlagAsRequired('password')
Ejemplo n.º 24
0
flags.DEFINE_boolean(
    'experimental_capitalize_enums', False,
    'Dangerous: attempt to rewrite enum values to be uppercase.')
flags.DEFINE_enum('experimental_name_convention',
                  util.Names.DEFAULT_NAME_CONVENTION,
                  util.Names.NAME_CONVENTIONS,
                  'Dangerous: use a particular style for generated names.')
flags.DEFINE_boolean('experimental_proto2_output', False,
                     'Dangerous: also output a proto2 message file.')

FLAGS = flags.FLAGS

flags.MarkFlagAsRequired('client_id')
flags.MarkFlagAsRequired('client_secret')
flags.RegisterValidator('infile', lambda i: not (i and FLAGS.discovery_url),
                        'Cannot specify both --infile and --discovery_url')
flags.RegisterValidator('discovery_url', lambda i: not (i and FLAGS.infile),
                        'Cannot specify both --infile and --discovery_url')


def _CopyLocalFile(filename):
    with contextlib.closing(open(filename, 'w')) as out:
        src_data = pkgutil.get_data('apitools.base.py', filename)
        if src_data is None:
            raise exceptions.GeneratedClientError('Could not find file %s' %
                                                  filename)
        out.write(src_data)


def _GetCodegenFromFlags():
    """Create a codegen object from flags."""
Ejemplo n.º 25
0
        dirpath = os.path.dirname(FLAGS.source_path)
        existing_dest_paths, gcs = auto_upload.PrepareToUpload(
            dirpath, FLAGS.destination_path)
        if gcs is None:
            return
        rename_template = None
        result = auto_upload.TryUploadFile(filename, dirpath,
                                           FLAGS.destination_path,
                                           existing_dest_paths, file_regex,
                                           rename_template, gcs,
                                           FLAGS.preserve_local, False)
        if result:
            uploaded_files.append(result)
    else:
        logging.error('Cannot upload %s. Must be a file or a directory.',
                      FLAGS.source_path)
        return
    # Report results.
    for local_path, dest_path in uploaded_files:
        logging.info('Uploaded %s to %s', local_path, dest_path)


if __name__ == '__main__':
    gflags.MarkFlagAsRequired('destination_path')
    gflags.MarkFlagAsRequired('source_path')
    gflags.RegisterValidator(
        'source_path', lambda p: os.path.isfile(p) or os.path.isdir(p),
        '--source_path must point to a file or directory.')

    _Upload(sys.argv)
Ejemplo n.º 26
0
from makani.lib.python import os_util
import numpy

# Angle [rad] over which to blend the XFOIL parameters with the high
# angle-of-attack parameters after stall.
_STALL_BLENDING_ANGLE = 5.0 * numpy.pi / 180.0

# Full path to the XFOIL binary.
_XFOIL_BIN = os.path.join(makani.HOME, 'third_party/xfoil/xfoil')

# Name of temporary file that XFOIL will use to store airfoils.
_TEMP_FILENAME = 'tmp_xfoil'

gflags.DEFINE_string('airfoil_file', None,
                     'Name of the airfoil definition file.')
gflags.RegisterValidator('airfoil_file', lambda x: not x or os.path.exists(x),
                         'airfoil_file does not exist.')

gflags.DEFINE_boolean('display_log', False, 'Displays output of XFOIL.')
gflags.DEFINE_boolean('display_input', False, 'Displays input to XFOIL.')

gflags.DEFINE_string('json_output_file', None, 'Name of output JSON file.')
gflags.RegisterValidator('json_output_file',
                         lambda f: f and os.path.basename(f),
                         'json_output_file mush have a valid file name.')

flag_types.DEFINE_linspace('flap_deflections_deg', '0.0, 0.0, 1',
                           'Linspace range of flap deflections [deg].')
flag_types.DEFINE_linspace('alphas_deg', '-10.0, 10.0, 20',
                           'Linspace range of angles-of-attack [deg].')

# TODO: Support 5 digit NACA airfoils.  This requires a
Ejemplo n.º 27
0
from multiprocessing import Process
import socket
from subprocess import Popen, PIPE
import sys
import time

gflags.DEFINE_integer("loglevel", 20,
                      "The level for logging. 20 for INFO and 10 for DEBUG.")
gflags.DEFINE_string(
    "launch", "local",
    "The launch mode. See mincepie.launcher.launch() for details.")
gflags.DEFINE_integer(
    "num_clients", 1,
    "The number of clients. Does not apply in the case of MPI.")
gflags.RegisterValidator('num_clients',
                         lambda x: x > 0,
                         message='--num_clients must be positive.')
# slurm flags
gflags.DEFINE_string("slurm_shebang", "#!/bin/bash",
                     "The shebang of the slurm batch script")
gflags.DEFINE_string("slurm_python_bin", "python",
                     "The command to call python")
gflags.DEFINE_string("sbatch_bin", "sbatch", "The command to call sbatch")
gflags.DEFINE_string("scancel_bin", "scancel", "The command to call scancel")
gflags.DEFINE_multistring("sbatch_args", [], "The sbatch arguments")
# easy access to FLAGS
FLAGS = gflags.FLAGS


def process_argv(argv):
    """processes the arguments using gflags
Ejemplo n.º 28
0
'''

import cPickle as pickle
import cProfile
import gflags
import logging
from iceberk import mpi, visiondata, pipeline, classifier, datasets, mathutil
from iceberk.experimental import pinker
import numpy as np
import os
import sys

gflags.DEFINE_string("root", "",
                     "The root to the cifar dataset (python format)")
gflags.RegisterValidator('root',
                         lambda x: x != "",
                         message='--root must be provided.')
gflags.DEFINE_string(
    "output_dir", ".", "The output directory that stores dumped feature and"
    "classifier files.")
gflags.DEFINE_string("model_file", "conv.pickle",
                     "The filename to output the CNN model.")
gflags.DEFINE_string("feature_file", "cnn_features",
                     "The filename to output the features.")
gflags.DEFINE_string("svm_file", "svm.pickle",
                     "The filename to output the trained svm parameters.")
gflags.DEFINE_string(
    "profile_file", "", "If set, do cProfile analysis, and output the result"
    "to the filename given by the flag.")

gflags.DEFINE_integer("patch", 0, "")
Ejemplo n.º 29
0
Archivo: trade.py Proyecto: aw1n/testeo
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
    print 'FLAGS.simulating:', FLAGS.simulating
    # currently we have only XRP in bittrex, start a portfolio with 'desired' state given only by 'XRP' and 'ETH'
    desired_state = portfolio.state_from_currencies([
        'ADA', 'TRIG', 'OK', 'RISE', 'IOP', 'NAV', 'MONA', 'EMC2', 'ADX',
        'VTC', 'MCO', 'XVG', 'SYS', 'XLM', 'KMD', 'TKN'
Ejemplo n.º 30
0
                for output in outputs if output['sim_success'] == success_val
            ], plot_style)
        pylab.xlabel('Wind speed [m/s]')
        pylab.ylabel('Joystick throttle')
        pylab.ylim([0.0, 1.1])
        pylab.legend(['successful simulations', 'crashed simulations'],
                     loc='lower right')
        pylab.savefig(FLAGS.output_dir + '/sim_success_param_space.svg')

        # Copy HTML file that displays the charts to the output directory.
        dashboard_file = os.path.join(
            makani.HOME, 'analysis/power_curve/power_curve_dashboard.html')
        final_output_file = os.path.join(FLAGS.output_dir, 'index.html')
        shutil.copyfile(dashboard_file, final_output_file)
        logging.info('Output may be viewed at file://%s.',
                     os.path.abspath(final_output_file))


def main(argv):
    client_base.InitMain(argv)
    client = PowerCurveSimClient()
    client.Run()


if __name__ == '__main__':
    gflags.RegisterValidator(
        'output_dir', lambda o: not os.path.exists(o) or os.path.isdir(o),
        '--output_dir cannot refer to an existing, non-directory object.')

    main(sys.argv)