Beispiel #1
0
def check_local_configuration(client):
    if os.path.isfile(system.config['host'][client]['path']) == False:
        sys.exit(
            output.message(output.get_subject().ERROR,
                           'Local database configuration not found', False))

    system.config['db'] = {}

    _db_credentials = check_output(
        helper.get_command(client, 'grep') + ' -v "^#" ' +
        system.config['host'][client]['path'] + ' | ' +
        helper.get_command(client, 'grep') + ' DATABASE_URL',
        stderr=subprocess.STDOUT,
        shell=True)

    _db_config = parse_database_credentials(_db_credentials)

    if system.option['verbose']:
        if client == mode.get_clients().TARGET:
            _subject = output.get_subject().TARGET
        else:
            _subject = output.get_subject().ORIGIN
        output.message(
            _subject,
            output.get_bcolors().BLACK + helper.get_command(client, 'grep') +
            ' -v "^#" ' + system.config['host'][client]['path'] + ' | ' +
            helper.get_command(client, 'grep') + ' DATABASE_URL' +
            output.get_bcolors().ENDC, True)

    system.config['db'][client] = _db_config
Beispiel #2
0
def check_sync_mode():
    global sync_mode

    if 'host' in system.config['host']['origin']:
        sync_mode = sync_modes.RECEIVER
        _description = output.get_bcolors(
        ).BLACK + '(REMOTE --> LOCAL)' + output.get_bcolors().ENDC
    if 'host' in system.config['host']['target']:
        sync_mode = sync_modes.SENDER
        _description = output.get_bcolors(
        ).BLACK + '(LOCAL --> REMOTE)' + output.get_bcolors().ENDC
    if 'host' in system.config['host']['origin'] and 'host' in system.config[
            'host']['target']:
        sync_mode = sync_modes.PROXY
        _description = output.get_bcolors(
        ).BLACK + '(REMOTE --> LOCAL --> REMOTE)' + output.get_bcolors().ENDC
    if not 'host' in system.config['host'][
            'origin'] and not 'host' in system.config['host']['target']:
        sync_mode = sync_modes.DUMP_LOCAL
        _description = output.get_bcolors(
        ).BLACK + '(LOCAL, NO TRANSFER/IMPORT)' + output.get_bcolors().ENDC
        system.option['is_same_client'] = True
    if 'host' in system.config['host']['origin'] and 'host' in system.config[
            'host']['target'] and system.config['host']['origin'][
                'host'] == system.config['host']['target']['host']:
        sync_mode = sync_modes.DUMP_REMOTE
        _description = output.get_bcolors(
        ).BLACK + '(REMOTE, NO TRANSFER/IMPORT)' + output.get_bcolors().ENDC
        system.option['is_same_client'] = True

    output.message(output.get_subject().INFO,
                   'Sync mode: ' + sync_mode + ' ' + _description, True)
Beispiel #3
0
def download_status(sent, size):
    sent_mb = round(float(sent) / 1024 / 1024, 1)
    size = round(float(size) / 1024 / 1024, 1)
    sys.stdout.write(
        output.get_subject().ORIGIN + output.get_bcolors().BLACK + '[REMOTE]' + output.get_bcolors().ENDC + " Status: {0} MB of {1} MB downloaded".
        format(sent_mb, size, ))
    sys.stdout.write('\r')
Beispiel #4
0
def run_command(command, client):
    if client == clients.ORIGIN:
        if system.option['verbose']:
            output.message(
                output.get_subject().ORIGIN,
                output.get_bcolors().BLACK + command +
                output.get_bcolors().ENDC, True)
        if is_origin_remote():
            return connect.run_ssh_command_origin(command)
        else:
            return os.system(command)
    elif client == clients.TARGET:
        if system.option['verbose']:
            output.message(
                output.get_subject().TARGET,
                output.get_bcolors().BLACK + command +
                output.get_bcolors().ENDC, True)
        if is_target_remote():
            return connect.run_ssh_command_target(command)
        else:
            return os.system(command)
Beispiel #5
0
def upload_status(sent, size):
    sent_mb = round(float(sent) / 1024 / 1024, 1)
    size = round(float(size) / 1024 / 1024, 1)

    if (mode.get_sync_mode() == mode.get_sync_modes().PROXY):
        _subject = output.get_subject().LOCAL
    else:
        _subject = output.get_subject().ORIGIN + output.get_bcolors().BLACK + '[LOCAL]' + output.get_bcolors().ENDC

    sys.stdout.write(
        _subject + " Status: {0} MB of {1} MB uploaded".
        format(sent_mb, size, ))
    sys.stdout.write('\r')
Beispiel #6
0
def print_header():
    _information = get_composer_information()

    print(output.get_bcolors().BLACK +
          '############################################' +
          output.get_bcolors().ENDC)
    print(output.get_bcolors().BLACK +
          '#                                          #' +
          output.get_bcolors().ENDC)
    print(output.get_bcolors().BLACK + '#' + output.get_bcolors().ENDC +
          '           DATABASE SYNC TOOL             ' +
          output.get_bcolors().BLACK + '#' + output.get_bcolors().ENDC)
    print(output.get_bcolors().BLACK + '#                  v' +
          _information['version'] + '                  #' +
          output.get_bcolors().ENDC)
    print(output.get_bcolors().BLACK + '# ' + _information['homepage'] + ' #' +
          output.get_bcolors().ENDC)
    print(output.get_bcolors().BLACK +
          '#                                          #' +
          output.get_bcolors().ENDC)
    print(output.get_bcolors().BLACK +
          '############################################' +
          output.get_bcolors().ENDC)