コード例 #1
0
def weblab_upgrade(directory):
    def on_dir(directory, configuration_files, configuration_values):
        original_argv = sys.argv
        sys.argv = [sys.argv[0]] + sys.argv[3:]
        parser = argparse.ArgumentParser(description="WebLab upgrade tool.")
        parser.add_argument('-y', '--yes', dest='yes', action='store_true', help='Say yes to everything')
        sys_args = parser.parse_args()
        sys.argv = original_argv

        if not check_updated(directory, configuration_files, configuration_values, sys_args):
            upgrade(directory, configuration_files, configuration_values, sys_args)
        else:
            print("Already upgraded to the latest version.")

    run_with_config(directory, on_dir)
コード例 #2
0
def weblab_locations(directory):
    def on_dir(directory, configuration_files, configuration_values):
        parser = argparse.ArgumentParser(usage='%(prog)s locations DIR [options]')
        parser.add_argument('--redownload', action='store_true', help='Force redownload of databases')
        parser.add_argument('--reset-database', action='store_true', help='Reset the database, forcing the server to download all the data again')
        parser.add_argument('--reset-cache', action='store_true', help='Reset the database, forcing the server to download all the data again')
        args = parser.parse_args(sys.argv[3:])

        config = ConfigurationManager.create(directory, configuration_files, configuration_values)

        for filename in 'GeoLite2-Country.mmdb', 'GeoLite2-City.mmdb':
            if os.path.exists(filename):
                print("Found %s" % filename)
                if args.redownload:
                    print("Redownloading...")
            else:
                print("%s not found. Downloading..." % filename)

            if args.redownload or not os.path.exists(filename):
                r = requests.get("http://geolite.maxmind.com/download/geoip/database/%s.gz" % filename)
                open('%s.gz' % filename,'w').write(r.content)
                uncompressed = gzip.open('%s.gz' % filename).read()
                open(filename, 'w').write(uncompressed)
                print("Downloaded")

        db = DatabaseGateway(config)

        if args.reset_database:
            print("Resetting database")
            db.reset_locations_database()

        if args.reset_cache:
            print("Resetting cache")
            db.reset_locations_cache()

    run_with_config(directory, on_dir)
コード例 #3
0
def weblab_locations(directory):
    def on_dir(directory, configuration_files, configuration_values):
        parser = argparse.ArgumentParser(usage='%(prog)s locations DIR [options]')
        parser.add_argument('--redownload', action='store_true', help='Force redownload of databases')
        parser.add_argument('--reset-database', action='store_true', help='Reset the database, forcing the server to download all the data again')
        parser.add_argument('--reset-cache', action='store_true', help='Reset the database, forcing the server to download all the data again')
        args = parser.parse_args(sys.argv[3:])

        config = ConfigurationManager.create(directory, configuration_files, configuration_values)

        for filename in 'GeoLite2-Country.mmdb', 'GeoLite2-City.mmdb':
            if os.path.exists(filename):
                print("Found %s" % filename)
                if args.redownload:
                    print("Redownloading...")
            else:
                print("%s not found. Downloading..." % filename)

            if args.redownload or not os.path.exists(filename):
                r = requests.get("http://geolite.maxmind.com/download/geoip/database/%s.gz" % filename)
                open('%s.gz' % filename,'wb').write(r.content)
                uncompressed = gzip.open('%s.gz' % filename).read()
                open(filename, 'wb').write(uncompressed)
                print("Downloaded")

        db = DatabaseGateway(config)

        if args.reset_database:
            print("Resetting database")
            db.reset_locations_database()

        if args.reset_cache:
            print("Resetting cache")
            db.reset_locations_cache()

    run_with_config(directory, on_dir)
コード例 #4
0
ファイル: run.py プロジェクト: arobles1980/weblabdeusto
def weblab_start(directory):
    parser = OptionParser(usage="%prog create DIR [options]")

    parser.add_option("-m", "--machine",           dest="machine", default=None, metavar="MACHINE",
                                                   help = "If there is more than one machine in the configuration, which one should be started.")
    parser.add_option("-l", "--list-machines",     dest="list_machines", action='store_true', default=False, 
                                                   help = "List machines.")

    parser.add_option("-s", "--script",            dest="script", default=None, metavar="SCRIPT",
                                                   help = "If the runner option is not available, which script should be used.")

    options, args = parser.parse_args()

    check_dir_exists(directory, parser)

    def on_dir(directory, configuration_files):
        db_conf = DbConfiguration(configuration_files)
        regular_url = db_conf.build_url()
        coord_url   = db_conf.build_coord_url()
        upgrader = DbUpgrader(regular_url, coord_url)
        return upgrader.check_updated()

    if not run_with_config(directory, on_dir):
        print >> sys.stderr, "Error: WebLab-Deusto instance outdated! You may have updated WebLab-Deusto recently. Run: weblab-admin.py upgrade %s" % directory
        sys.exit(-1)


    old_cwd = os.getcwd()
    os.chdir(directory)
    try:
        if options.script: # If a script is provided, ignore the rest
            if os.path.exists(options.script):
                execfile(options.script)
            elif os.path.exists(os.path.join(old_cwd, options.script)):
                execfile(os.path.join(old_cwd, options.script))
            else:
                print >> sys.stderr, "Provided script %s does not exist" % options.script
                sys.exit(-1)
        else:
            parser = GlobalParser()
            global_configuration = parser.parse('.')
            if options.list_machines:
                for machine in global_configuration.machines:
                    print ' - %s' % machine
                sys.exit(0)

            machine_name = options.machine
            if machine_name is None: 
                if len(global_configuration.machines) == 1:
                    machine_name = global_configuration.machines.keys()[0]
                else:
                    print >> sys.stderr, "System has more than one machine (see -l). Please detail which machine you want to start with the -m option."
                    sys.exit(-1)

            if not machine_name in global_configuration.machines:
                print >> sys.stderr, "Error: %s machine does not exist. Use -l to see the list of existing machines." % machine_name
                sys.exit(-1)

            machine_config = global_configuration.machines[machine_name]
            if machine_config.runner is None:
                if os.path.exists('run.py'):
                    execfile('run.py')
                else:
                    print >> sys.stderr, "No runner was specified, and run.py was not available. Please the -s argument to specify the script or add the <runner file='run.py'/> option in %s." % machine_name
                    sys.exit(-1)
            else:
                if os.path.exists(machine_config.runner):
                    execfile(machine_config.runner)
                else:
                    print >> sys.stderr, "Misconfigured system. Machine %s points to %s which does not exist." % (machine_name, os.path.abspath(machine_config.runner))
                    sys.exit(-1)
    finally:
        os.chdir(old_cwd)
コード例 #5
0
ファイル: admin.py プロジェクト: zstars/weblabdeusto
def weblab_admin(directory):
    def on_dir(directory, configuration_files, configuration_values):
        Controller(configuration_files, configuration_values)
    
    run_with_config(directory, on_dir)
コード例 #6
0
ファイル: run.py プロジェクト: coycooper/Projects_Coy
def weblab_start(directory):
    parser = OptionParser(usage="%prog start DIR [options]")

    parser.add_option(
        '-m',
        '--host',
        '--machine',
        dest='host',
        default=None,
        metavar='HOST',
        help=
        'If there is more than one host in the configuration, which one should be started.'
    )

    parser.add_option('-l',
                      '--list-hosts',
                      '--list-machines',
                      dest='list_hosts',
                      action='store_true',
                      default=False,
                      help='List hosts.')

    parser.add_option(
        '-s',
        '--script',
        dest='script',
        default=None,
        metavar='SCRIPT',
        help=
        'If the runner option is not available, which script should be used.')

    options, args = parser.parse_args()

    check_dir_exists(directory, parser)

    if not run_with_config(directory, check_updated):
        print(
            "Error: WebLab-Deusto instance outdated! You may have updated WebLab-Deusto recently. Run: weblab-admin.py upgrade %s"
            % directory,
            file=sys.stderr)
        sys.exit(-1)

    old_cwd = os.getcwd()
    os.chdir(directory)

    # Ensure we aren't already running. The check is not currently supported on Windows.
    if sys.platform.lower().startswith('win'):
        if os.path.exists("weblab.pid"):
            pid = int(open("weblab.pid").read())
            running = check_pid(pid)
            if not running:
                os.remove("weblab.pid")
            else:
                print(
                    "Error: WebLab-Deusto instance seems to be running already!",
                    file=sys.stderr)
                sys.exit(-1)

    try:
        if options.script:  # If a script is provided, ignore the rest
            if os.path.exists(options.script):
                execfile(options.script)
            elif os.path.exists(os.path.join(old_cwd, options.script)):
                execfile(os.path.join(old_cwd, options.script))
            else:
                print("Provided script %s does not exist" % options.script,
                      file=sys.stderr)
                sys.exit(-1)
        else:
            global_configuration = load_dir('.')
            if options.list_hosts:
                for host in global_configuration:
                    print(' - %s' % host)
                sys.exit(0)

            host_name = options.host
            if host_name is None:
                if len(global_configuration) == 1:
                    host_name = global_configuration.keys()[0]
                else:
                    print(
                        "System has more than one host (see -l). Please detail which host you want to start with the --host option.",
                        file=sys.stderr)
                    sys.exit(-1)

            if not host_name in global_configuration:
                print(
                    "Error: %s host does not exist. Use -l to see the list of existing hosts."
                    % host_name,
                    file=sys.stderr)
                sys.exit(-1)

            host_config = global_configuration[host_name]
            if host_config.runner is None:
                if os.path.exists('run.py'):
                    execfile('run.py')
                else:
                    print(
                        "No runner was specified, and run.py was not available. Please the -s argument to specify the script or add the <runner file='run.py'/> option in %s."
                        % host_name,
                        file=sys.stderr)
                    sys.exit(-1)
            else:
                if os.path.exists(host_config.runner):
                    execfile(host_config.runner)
                else:
                    print(
                        "Misconfigured system. Machine %s points to %s which does not exist."
                        % (host_name, os.path.abspath(host_config.runner)),
                        file=sys.stderr)
                    sys.exit(-1)
    finally:
        os.chdir(old_cwd)
コード例 #7
0
ファイル: run.py プロジェクト: JamesHyunKim/weblabdeusto
def weblab_start(directory):
    parser = OptionParser(usage="%prog start DIR [options]")

    parser.add_option('-m', '--host', '--machine',
                                                   dest='host', default=None, metavar='HOST',
                                                   help = 'If there is more than one host in the configuration, which one should be started.')

    parser.add_option('-l', '--list-hosts', '--list-machines',     
                                                   dest='list_hosts', action='store_true', default=False, 
                                                   help = 'List hosts.')

    parser.add_option('-s', '--script',            dest='script', default=None, metavar='SCRIPT',
                                                   help = 'If the runner option is not available, which script should be used.')

    options, args = parser.parse_args()

    check_dir_exists(directory, parser)

    if not run_with_config(directory, check_updated):
        print("Error: WebLab-Deusto instance outdated! You may have updated WebLab-Deusto recently. Run: weblab-admin.py upgrade %s" % directory, file=sys.stderr)
        sys.exit(-1)


    old_cwd = os.getcwd()
    os.chdir(directory)

    # Ensure we aren't already running. The check is not currently supported on Windows.
    if sys.platform.lower().startswith('win'):
        if os.path.exists("weblab.pid"):
            pid = int(open("weblab.pid").read())
            running = check_pid(pid)
            if not running:
                os.remove("weblab.pid")
            else:
                print("Error: WebLab-Deusto instance seems to be running already!", file=sys.stderr)
                sys.exit(-1)

    try:
        if options.script: # If a script is provided, ignore the rest
            if os.path.exists(options.script):
                execfile(options.script)
            elif os.path.exists(os.path.join(old_cwd, options.script)):
                execfile(os.path.join(old_cwd, options.script))
            else:
                print("Provided script %s does not exist" % options.script, file=sys.stderr)
                sys.exit(-1)
        else:
            global_configuration = load_dir('.')
            if options.list_hosts:
                for host in global_configuration:
                    print(' - %s' % host)
                sys.exit(0)

            host_name = options.host
            if host_name is None: 
                if len(global_configuration) == 1:
                    host_name = global_configuration.keys()[0]
                else:
                    print("System has more than one host (see -l). Please detail which host you want to start with the --host option.", file=sys.stderr)
                    sys.exit(-1)

            if not host_name in global_configuration:
                print("Error: %s host does not exist. Use -l to see the list of existing hosts." % host_name, file=sys.stderr)
                sys.exit(-1)

            host_config = global_configuration[host_name]
            if host_config.runner is None:
                if os.path.exists('run.py'):
                    execfile('run.py')
                else:
                    print("No runner was specified, and run.py was not available. Please the -s argument to specify the script or add the <runner file='run.py'/> option in %s." % host_name, file=sys.stderr)
                    sys.exit(-1)
            else:
                if os.path.exists(host_config.runner):
                    execfile(host_config.runner)
                else:
                    print("Misconfigured system. Machine %s points to %s which does not exist." % (host_name, os.path.abspath(host_config.runner)), file=sys.stderr)
                    sys.exit(-1)
    finally:
        os.chdir(old_cwd)