def load_md5_table(filename):
    out.log('loading hash table from ' + filename, 'sync')
    engine.sync_ftp()
    try:
        #load form file
        md5_table_file = open(filename, 'r', encoding='utf-8')
        md5_table = json.load(md5_table_file)
        md5_table_file.close()
    except:
        #if that fails: return empty table
        out.log('unable to load hashtable from ' + filename + ', creating empty table.', 'sync', out.LEVEL_WARNING)
        md5_table = {}

    #normalize unicode entries
    if NORMALIZE_UNICODE_FILENAMES:
        normalized_md5_table = {}
        for key in md5_table:
            if isinstance(key, str):
                key = unicode(key, 'utf-8')
            normalized_key = unicodedata.normalize(NORMALIZATION_FORM, key)
            normalized_md5_table[normalized_key] = md5_table[key]
        md5_table = normalized_md5_table

    #give back
    return md5_table
Example #2
0
def uncompress_local(filename, tell_engine=False):
    if tell_engine:
        rename_tmp_func = engine.rename_local_file
    else:
        rename_tmp_func = None
    #sync ftp only on local compression/uncompression, because on remote it get's synced anyway by the command system
    engine.sync_ftp()
    return uncompress(filename, run.local, rename_tmp_func)
def execute(command):
    import run
    #out.log('executing ' + command, 'ssh', out.LEVEL_VERBOSE)

    #get in sync with all possibly buffered ftp commands
    engine.sync_ftp()

    #run the command
    ssh_command_line = 'ssh ' + engine.SSH_USER + '@' + engine.SSH_HOST + " 'cd " + engine.SSH_PATH_TO_WWW_DIR + ' && ' + command + "'"
    run.local(ssh_command_line, retry=3, halt_on_stderr=False)
def execute(command, halt_on_output=False):
    import run

    #tell
    out.log(command, 'php', out.LEVEL_VERBOSE)

    #make sure the command file is online
    upload_command_file()

    #write command to file and upload it. We do it this way, althouth this is quite inefficient, but otherwise we'd have tremendous problems with escaping characters.
    #althouth, TODO: escape special characters in command
    script_content = '#!/bin/bash\n' + command
    filename = engine.write_remote_file(script_content,
                                        'sh',
                                        permissions='777')

    #reserve a remote .log file
    output_file = engine.get_new_local_file('log', True)

    #run the command via php access and tell the server to put the commands output into the remote output file
    curl_command = 'curl --silent --output ' + output_file

    #account for basic auth
    if engine.NEED_BASIC_AUTH:
        curl_command += ' -u ' + engine.AUTH_USER + ':' + engine.AUTH_PASSWORD

    #continue assembling curl command
    curl_command += ' ' + engine.REMOTE_COMMAND_URL + '?cmd=' + filename

    #execute all buffered ftp commands
    engine.sync_ftp()

    #and go
    run.local(curl_command, halt_on_stdout=halt_on_output
              )  #halt_on_output strongly depends on the command

    #log output to screen
    if halt_on_output:
        log_level = out.LEVEL_ERROR
        if os.stat(output_file).st_size > 0:
            out.file(output_file, 'php exec', out.LEVEL_ERROR)
            out.log(
                'error executing "' + command + '" via php command system.',
                'php', out.LEVEL_ERROR)
            engine.quit()

    out.file(output_file, 'php exec', out.LEVEL_INFO)
    return output_file