Пример #1
0
def command_line_options():
    """ command line configuration """
    
    parser = OptionParser(usage="usage: %prog [options] <htpasswd>")
    
    parser.formatter = PlainHelpFormatter()
    parser.description = """Expose a directory of bash scripts as an API.

Note: This application gives you plenty of bullets to shoot yourself in the 
foot!  Please use the SSL config options, give a password file, and either 
whitelist access to it via a firewall or keep it in a private network.

You can use the apache htpasswd utility to create your htpasswd files.  If
you do, I recommend passing the -d flag, forcing the encryption type pyjojo
recognises."""
    
    parser.add_option('-d', '--debug', action="store_true", dest="debug", default=False,
                      help="Start the application in debugging mode.")
    
    parser.add_option('--dir', action="store", dest="directory", default="/srv/pyjojo",
                      help="Base directory to parse the scripts out of")
    
    parser.add_option('--force-json', action="store_true", dest="force_json", default=False,
                      help="Force the application to treat all incoming requests as 'Content-Type: application/json'")
    
    parser.add_option('-p', '--port', action="store", dest="port", default=3000,
                      help="Set the port to listen to on startup.")
    
    parser.add_option('-a', '--address', action ="store", dest="address", default=None,
                      help="Set the address to listen to on startup. Can be a hostname or an IPv4/v6 address.")
    
    parser.add_option('-c', '--certfile', action="store", dest="certfile", default=None,
                      help="SSL Certificate File")
    
    parser.add_option('-k', '--keyfile', action="store", dest="keyfile", default=None,
                      help="SSL Private Key File")
    
    parser.add_option('-u', '--unix-socket', action="store", dest="unix_socket", default=None,
                      help="Bind pyjojo to a unix domain socket")

    options, args = parser.parse_args()

    # TODO: only do this if they specify the ssl certfile and keyfile
    if len(args) >= 1:
        config['passfile'] = args[0]
    else:
        config['passfile'] = None
        
    config['directory'] = options.directory
    config['force_json'] = options.force_json

    return options
Пример #2
0
def command_line_options():
    """ command line configuration """
    
    parser = OptionParser(usage="usage: %prog [options] <htpasswd>")
    
    parser.formatter = PlainHelpFormatter()
    parser.description = """Expose a directory of bash scripts as an API.

Note: This application gives you plenty of bullets to shoot yourself in the 
foot!  Please use the SSL config options, give a password file, and either 
whitelist access to it via a firewall or keep it in a private network.

Use the apache htpasswd utility to create your htpasswd files."""
    
    parser.add_option('-d', '--debug', action="store_true", dest="debug", default=False,
                      help="Start the application in debugging mode.")
    
    parser.add_option('--dir', action="store", dest="directory", default="/srv/pyjojo",
                      help="Base directory to parse the scripts out of")
    
    parser.add_option('--force-json', action="store_true", dest="force_json", default=False,
                      help="Force the application to treat all incoming requests as 'Content-Type: application/json'")
    
    parser.add_option('-p', '--port', action="store", dest="port", default=3000,
                      help="Set the port to listen to on startup.")
    
    parser.add_option('-a', '--address', action ="store", dest="address", default=None,
                      help="Set the address to listen to on startup. Can be a hostname or an IPv4/v6 address.")
    
    parser.add_option('-c', '--certfile', action="store", dest="certfile", default=None,
                      help="SSL Certificate File")
    
    parser.add_option('-k', '--keyfile', action="store", dest="keyfile", default=None,
                      help="SSL Private Key File")
    
    parser.add_option('-u', '--unix-socket', action="store", dest="unix_socket", default=None,
                      help="Bind pyjojo to a unix domain socket")

    options, args = parser.parse_args()

    # TODO: only do this if they specify the ssl certfile and keyfile
    if len(args) >= 1:
        config['passfile'] = args[0]
    else:
        config['passfile'] = None
        
    config['directory'] = options.directory
    config['force_json'] = options.force_json

    return options
Пример #3
0
def command_line_options():
    """ command line configuration """
    
    parser = OptionParser(usage="usage: %prog [options] <htpasswd>")
    
    parser.formatter = PlainHelpFormatter()
    parser.description = """Expose a directory of bash scripts as an API.

Note: This application gives you plenty of bullets to shoot yourself in the 
foot!  Please use the SSH config options, give a password file, and either 
whitelist access to it via a firewall or keep it in a private network.

You can use the apache htpasswd utility to create your htpasswd files.  If
you do, I recommend passing the -d flag, forcing the encryption type pyjojo
recognises."""
    
    parser.add_option('-d', '--debug', action="store_true", dest="debug", default=False,
                      help="Start the application in debugging mode.")
    
    parser.add_option('-p', '--port', action="store", dest="port", default=3000,
                      help="Set the port to listen to on startup.")
    
    parser.add_option('-a', '--address', action ="store", dest="address", default=None,
                      help="Set the address to listen to on startup. Can be a hostname or an IPv4/v6 address.")
    
    parser.add_option('--dir', action="store", dest="directory", default="/srv/pyjojo",
                      help="Base directory to parse the scripts out of")
    
    parser.add_option('-c', '--certfile', action="store", dest="certfile", default=None,
                      help="SSL Certificate File")
    
    parser.add_option('-k', '--keyfile', action="store", dest="keyfile", default=None,
                      help="SSL Private Key File")

    options, args = parser.parse_args()

    # TODO: only do this if they specify the ssl certfile and keyfile
    if len(args) >= 1:
        config['passwords'] = parse_password_file(args[0])
    else:
        config['passwords'] = None
        
    config['directory'] = options.directory

    return options
Пример #4
0
    def get_options(self):
        opts = OptionParser()
        opts.add_option('',
                        '--remove-after',
                        action='store',
                        default=None,
                        dest='remove_after',
                        help=('The time after which to delete oplog entries. '
                              '(YYYY-MM-DD HH:MM:SS, in UTC).'))
        opts.add_option('-y',
                        '',
                        action='store_true',
                        dest='always_yes',
                        default=None,
                        help='Answer yes for all prompts.')
        opts.usage = '%prog --host=<host> --remove-after=<date> [options]'
        opts.epilog = """
%s

""" % warning

        opts.formatter = HelpFormatter()
        return opts
Пример #5
0
    def get_options(self):
        opts = OptionParser()
        opts.add_option(
            "",
            "--remove-after",
            action="store",
            default=None,
            dest="remove_after",
            help=("The time after which to delete oplog entries. " "(YYYY-MM-DD HH:MM:SS, in UTC)."),
        )
        opts.add_option(
            "-y", "", action="store_true", dest="always_yes", default=None, help="Answer yes for all prompts."
        )
        opts.usage = "%prog --host=<host> --remove-after=<date> [options]"
        opts.epilog = (
            """
%s

"""
            % warning
        )

        opts.formatter = HelpFormatter()
        return opts
Пример #6
0
def parse_command_line(args):
    """
    Parse the command line arguments.

    Returns a tuple of (options, destination_dir).

    Calls sys.exit() if the command line could not be parsed.
    """

    usage = 'usage: %prog [options] DESTINATION-DIR'
    description = 'Backs up all available Mercurial repositories on Kiln ' + \
        'by cloning them (if they have not been backed up before), or by ' + \
        'pulling changes. In order to run this without user interaction, ' + \
        'you must install the FogBugz "KilnAuth" Mercurial extension and ' + \
        'clone at least one repository so that your credentials are saved.'
    version = "%prog, v" + __version__

    parser = OptionParser(usage=usage,
                          description=description,
                          version=version)
    parser.formatter = IndentedHelpFormatter(max_help_position=30)

    parser.add_option('-t', '--token', dest='token', help='FogBugz API token')
    parser.add_option('-s', '--server', dest='server', help='Kiln server name')
    parser.add_option('--scheme',
                      dest='scheme',
                      type='choice',
                      choices=('https', 'http'),
                      help='scheme used to connect to server')
    parser.add_option('-d',
                      '--debug',
                      dest='debug',
                      action='store_true',
                      default=False,
                      help='extra-verbose output')
    parser.add_option('-q',
                      '--quiet',
                      dest='verbose',
                      action='store_false',
                      default=True,
                      help='non-verbose output')
    parser.add_option('-l', '--limit', dest='limit', metavar='PATH',
        help='only backup repos in the specified project/group (ex.: ' + \
        'MyProject) (or: MyProject/MyGroup)')
    parser.add_option('-u',
                      '--update',
                      dest='update',
                      action='store_true',
                      default=False,
                      help='update working copy when cloning or pulling')

    (options, args) = parser.parse_args(args)

    # Get the destination directory, which should be the one and
    # only non-option argument.
    if len(args) == 0:
        parser.error('Must specify the destination directory for the backups.')
    if len(args) > 1:
        parser.error('Unknown arguments passed after destination directory')
    destination_dir = args[0]

    # Now get any saved options from the configuration file and use
    # them to fill in any missing options.
    configfile_path = os.path.join(destination_dir, CONFIG_FILE)
    if os.path.exists(configfile_path):
        configfile = open(configfile_path, 'r')
        config_data = json.load(configfile)
        configfile.close()

        if not options.token and 'token' in config_data:
            options.token = config_data['token']

        if not options.server and 'server' in config_data:
            options.server = config_data['server']

        if not options.scheme and 'scheme' in config_data:
            options.scheme = config_data['scheme']

    # default to https if still no scheme specified
    if not options.scheme:
        options.scheme = 'https'

    return (options, destination_dir)
Пример #7
0
                  ,default='WII'
                  ,help='Select which OS to run the tests on. The default is WII' )
parser.add_option( '-p'
                  ,'--port'
                  ,type='string'
                  ,dest='serialPortName'
                  ,default='COM1'
                  ,help='Select PC serial port to use' )
parser.add_option( '-a'
                  ,'--all'
                  ,action='store_true'
                  ,dest='bAllMsg'
                  ,default=False
                  ,help='See all console messages' )

parser.formatter = TitledHelpFormatter()

(options, args) = parser.parse_args()

osversion = options.osversion
rootdir = options.rootdir
buildtype = options.buildtype
matchexpr = options.matchexpr
catstring = options.catstring
serialPortName = options.serialPortName
bAllMsg = options.bAllMsg

catlist = set( catstring.split(',') )
categorylist = set([])

# Make all the categories lowercase so they are easy to compare
Пример #8
0
    default='WII',
    help='Select which OS to run the tests on. The default is WII')
parser.add_option('-p',
                  '--port',
                  type='string',
                  dest='serialPortName',
                  default='COM1',
                  help='Select PC serial port to use')
parser.add_option('-a',
                  '--all',
                  action='store_true',
                  dest='bAllMsg',
                  default=False,
                  help='See all console messages')

parser.formatter = TitledHelpFormatter()

(options, args) = parser.parse_args()

osversion = options.osversion
rootdir = options.rootdir
buildtype = options.buildtype
matchexpr = options.matchexpr
catstring = options.catstring
serialPortName = options.serialPortName
bAllMsg = options.bAllMsg

catlist = set(catstring.split(','))
categorylist = set([])

# Make all the categories lowercase so they are easy to compare
Пример #9
0
def command_line_options():
    """ command line configuration """

    parser = OptionParser(usage="usage: %prog [options] <htpasswd>")

    parser.formatter = PlainHelpFormatter()
    parser.description = """This will expose a set of opsapi extensions as a REST API.

Note: Please make sure this application is behind authentication for security.
Please use the SSL config options, give a passwd file, and either whitelist
access to the API via firewall or keep it on a privately routed network.

Use the apache htpasswd utility to create your htpasswd files."""

    parser.add_option('-d',
                      '--debug',
                      action="store_true",
                      dest="debug",
                      default=False,
                      help="Start the application with debug enabled.")

    parser.add_option('--dir',
                      action="store",
                      dest="directory",
                      default="/srv/extensions",
                      help="Directory to load SDK extensions from")

    parser.add_option(
        '--config',
        action="store",
        dest="config_file",
        default=None,
        help=
        "Provide a YAML file to load config options from. NOTE: Syntax is key: v; python objects allowed as values. Native YAML lists and hash syntax are unsupported."
    )

    parser.add_option(
        '--force-json',
        action="store_true",
        dest="force_json",
        default=False,
        help=
        "Force the application to treat all incoming requests as 'Content-Type: application/json'"
    )

    parser.add_option('-p',
                      '--port',
                      action="store",
                      dest="port",
                      default=3000,
                      help="The listening port")

    parser.add_option(
        '-a',
        '--address',
        action="store",
        dest="address",
        default=None,
        help="Listening interface. Can be a hostname or an IPv4/v6 address.")

    parser.add_option('-c',
                      '--certfile',
                      action="store",
                      dest="certfile",
                      default=None,
                      help="SSL Cert File")

    parser.add_option('-k',
                      '--keyfile',
                      action="store",
                      dest="keyfile",
                      default=None,
                      help="SSL Private Key File")

    parser.add_option('-u',
                      '--unix-socket',
                      action="store",
                      dest="unix_socket",
                      default=None,
                      help="Bind opsapi to a unix domain socket")

    options, args = parser.parse_args()

    # TODO: only do this if they specify the ssl certfile and keyfile
    if len(args) >= 1:
        config['passfile'] = args[0]
    else:
        config['passfile'] = None

    config['directory'] = options.directory
    config['force_json'] = options.force_json

    for k, v in config_defaults.iteritems():
        config[k] = v  # set defaults

    load_config_from_disk(options.config_file)

    return options
Пример #10
0
def parse_command_line(args):
    """
    Parse the command line arguments.

    Returns a tuple of (options, destination_dir).

    Calls sys.exit() if the command line could not be parsed.
    """

    global debug

    usage = 'usage: %prog [options] DESTINATION-DIR'
    description = 'Backs up all available Mercurial repositories on Kiln ' + \
        'by cloning them (if they have not been backed up before), or by ' + \
        'pulling changes. In order to run this without user interaction, ' + \
        'you must install the FogBugz "KilnAuth" Mercurial extension and ' + \
        'clone at least one repository so that your credentials are saved.'
    version = "%prog, v" + __version__

    parser = OptionParser(usage=usage, description=description, version=version)
    parser.formatter = IndentedHelpFormatter(max_help_position=30)

    parser.add_option('-t', '--token', dest='token', help='FogBugz API token')
    parser.add_option('-s', '--server', dest='server', help='Kiln server name')
    parser.add_option('--scheme', dest='scheme', type='choice',
        choices=('https', 'http'), help='scheme used to connect to server')
    parser.add_option('-q', '--quiet', dest='verbose', action='store_false',
        default=True, help='non-verbose output')
    parser.add_option('-d', '--debug', dest='debug', action='store_true',
        default=False, help='additional output for debugging')
    parser.add_option('-l', '--limit', dest='limit', metavar='PATH',
        help='only backup repos in the specified project/group (ex.: ' + \
        'MyProject) (or: MyProject/MyGroup)')
    parser.add_option('-u', '--update', dest='update', action='store_true',
        default=False, help='update working copy when cloning or pulling')

    (options, args) = parser.parse_args(args)

    # Get the destination directory, which should be the one and
    # only non-option argument.
    if len(args) == 0:
        parser.error('Must specify the destination directory for the backups.')
    if len(args) > 1:
        parser.error('Unknown arguments passed after destination directory')
    destination_dir = args[0]
    debug = options.debug

    # Now get any saved options from the configuration file and use
    # them to fill in any missing options.
    configfile_path = os.path.join(destination_dir, CONFIG_FILE)
    if os.path.exists(configfile_path):
        configfile = open(configfile_path, 'r')
        config_data = json.load(configfile)
        configfile.close()

        if not options.token and 'token' in config_data:
            options.token = config_data['token']

        if not options.server and 'server' in config_data:
            options.server = config_data['server']

        if not options.scheme and 'scheme' in config_data:
            options.scheme = config_data['scheme']

    # default to https if still no scheme specified
    if not options.scheme:
        options.scheme = 'https'
        
    return (options, destination_dir)