How to use the twitter.common.app function in twitter

To help you get started, we’ve selected a few twitter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apache / aurora / src / main / python / apache / thermos / bin / thermos.py View on Github external
def generate_usage():
  usage = """
thermos

commands:
"""

  for (command, doc) in app.get_commands_and_docstrings():
    usage += '    ' + '%-10s' % command + '\t' + doc.split('\n')[0].strip() + '\n'
  app.set_usage(usage)
github apache / aurora / src / main / python / apache / aurora / admin / help.py View on Github external
def add_verbosity_options():
  def set_quiet(option, _1, _2, parser):
    setattr(parser.values, option.dest, 'quiet')
    LogOptions.set_stderr_log_level('NONE')

  def set_verbose(option, _1, _2, parser):
    setattr(parser.values, option.dest, 'verbose')
    LogOptions.set_stderr_log_level('DEBUG')

  app.add_option('-v',
                 dest='verbosity',
                 default='normal',
                 action='callback',
                 callback=set_verbose,
                 help='Verbose logging. (default: %default)')

  app.add_option('-q',
                 dest='verbosity',
                 default='normal',
                 action='callback',
                 callback=set_quiet,
                 help='Quiet logging. (default: %default)')
github twitter / zktraffic / zktraffic / cli / fle.py View on Github external
def setup():
  LogOptions.set_stderr_log_level('NONE')

  app.add_option('--iface', default='eth0', type=str)
  app.add_option('--port', default=3888, type=int)
  app.add_option('-c', '--colors', default=False, action='store_true')
  app.add_option('--dump-bad-packet', default=False, action='store_true')
  app.add_option('--version', default=False, action='store_true')
github apache / aurora / src / python / twitter / mesos / bin / mesos_client.py View on Github external
def generate_terse_usage():
  docs_to_commands = collections.defaultdict(list)
  for (command, doc) in app.get_commands_and_docstrings():
    docs_to_commands[doc].append(command)
  usage = '\n    '.join(sorted(map(make_commands_str, docs_to_commands.values())))
  return """
Available commands:
    %s

For more help on an individual command:
    %s help 
""" % (usage, app.name())
github wickman / rainman / rainman / bin / make_torrent.py View on Github external
import os

from rainman.metainfo import MetaInfoBuilder
from rainman.torrent import Torrent

from twitter.common import app, log


app.set_usage(
'''
make_torrent [-r relpath]   path1 path2 ...

Paths may be either filenames or directories.  If a directory is specified,
its contents will be recursively walked and stored in the torrent.

If relpath is specified, all files in the torrent will be relative to that
path.
''')

app.add_option('-r', dest='relpath', default=None,
               help='The relative path for all files within the torrent.')


def main(args, options):
  if len(args) <= 2:
github wickman / rainman / rainman / bin / tracker.py View on Github external
from collections import defaultdict

from rainman.codec import BEncoder

from twitter.common import app, log
from twitter.common.http import HttpServer
from twitter.common.quantity import Amount, Time


app.add_option(
    '--port',
    dest='port',
    default=8080,
    type=int,
    help='The port on which the torrent tracker should be run.')


class TrackerRequest(object):
  class Error(Exception): pass
  class MalformedRequestError(Error): pass

  REQUIRED_KEYS = frozenset([
    'info_hash',
    'peer_id',
    'port',
    'uploaded',
github apache / aurora / src / python / twitter / thermos / bin / thermos_run.py View on Github external
from twitter.common import app, options
from twitter.thermos.config.loader import ThermosConfigLoader
from twitter.thermos.runner import TaskRunner

app.add_option("--thermos", dest = "thermos",
               help = "read thermos job description from .thermos file")
app.add_option("--thermos_json", dest = "thermos_json",
               help = "read a thermos Task from a serialized json blob")

app.add_option("--task", dest = "task", metavar = "NAME", default=None,
               help = "run the task by the name of NAME")

app.add_option("--sandbox", dest = "sandbox", metavar = "PATH",
               help = "the sandbox in which this task should run")
app.add_option("--checkpoint_root", dest = "checkpoint_root", metavar = "PATH",
               help = "the path where we will store task logs and checkpoints")

app.add_option("--task_id", dest = "task_id", metavar = "STRING", default = None,
               help = "The id to which this task should be bound, created if it does not exist.")

app.add_option("--action", dest = "action", metavar = "ACTION", default = "run",
               help = "the action for this task runner: run, kill")
github apache / aurora / src / main / python / apache / thermos / runner / thermos_runner.py View on Github external
def get_task_from_options(opts):
  tasks = ThermosConfigLoader.load_json(opts.thermos_json)
  if len(tasks.tasks()) == 0:
    app.error("No tasks specified!")
  if len(tasks.tasks()) > 1:
    app.error("Multiple tasks in config but no task name specified!")
  task = tasks.tasks()[0]
  if not task.task.check().ok():
    app.error(task.task.check().message())
  return task
github twitter / zktraffic / zktraffic / cli / zk.py View on Github external
help='Measure latency of N pairs of requests and replies (default: group by path')
  app.add_option('--group-by', default='path', type=str, metavar='',
                 help='Used with --count-requests or --measure-latency. Possible values: path, type or client')
  app.add_option('--sort-by', default='avg', type=str, metavar='',
                 help='Used with --measure-latency. Possible values: avg, p95 and p99')
  app.add_option("--aggregation-depth", default=0, type=int, metavar='',
                 help="Aggregate paths up to a certain depth. Used with --count-requests or --measure-latency")
  app.add_option('--unpaired', default=False, action='store_true',
                 help='Don\'t pair reqs/reps')
  app.add_option('-p', '--include-pings', default=False, action='store_true',
                 help='Whether to include ping requests and replies')
  app.add_option('-c', '--colors', default=False, action='store_true',
                 help='Color each client/server stream differently')
  app.add_option('--dump-bad-packet', default=False, action='store_true',
                 help='If unable to to deserialize a packet, print it out')
  app.add_option('--version', default=False, action='store_true')
github apache / aurora / src / main / python / twitter / thermos / config / bin / config_load.py View on Github external
def main(args):
  """
    Given .thermos configs, loads them and prints out information about them.
  """

  if len(args) == 0:
    app.help()

  for arg in args:
    print '\nparsing %s\n' % arg
    tc = ThermosConfigLoader.load(arg)

    for task_wrapper in tc.tasks():
      task = task_wrapper.task
      if not task.has_name():
        print 'Found unnamed task!  Skipping...'
        continue

      print 'Task: %s [check: %s]' % (task.name(), task.check())
      if not task.processes():
        print '  No processes.'
      else:
        print '  Processes:'