Ejemplo n.º 1
0
def extract_content(file_name):
    fd = open(file_name, 'rb')
    if not fd:
        printing.ERROR("Failed to open input file, error code, stopping")
    content = bytearray(fd.read())
    if not content:
        printing.ERROR("Unable to read data from the file %s" % file_name)

    fd.close()
    return content
Ejemplo n.º 2
0
def extract_content(file_name):
    fd = open(file_name, 'rb')
    if not fd:
        printing.ERROR("Failed to open input file, error code, stopping")
    # check file size and return empty string if 0
    if not os.path.getsize(file_name):
        fd.close()
        return b""
    content = bytearray(fd.read())
    if not content:
        printing.ERROR("Unable to read data from the file %s" % file_name)

    fd.close()
    return content
Ejemplo n.º 3
0
def parse_config(file_path):
    content = open(file_path, 'r').readlines()
    additional_cmd = ""
    args_dict = dict()
    for i, line in enumerate(content):
        line = line.replace("\n", "")
        if line.startswith("#") or len(line) <= 1:  # comments or empty lines
            continue
        line = line.replace(" ", "")
        if line.count("=") != 1:
            printing.ERROR("Wrong config format at line %d:%s, exiting" %
                           (i, line))

        line = line.split("=")  # [arg_name, value]
        # parse Bool|Number|String
        value = line[1]
        if value == 'True':
            additional_cmd += "--%s " % (line[0])
        elif value == 'None' or value == 'False':
            continue
        else:
            additional_cmd += "--%s %s " % (line[0], value)

    additional_cmd = additional_cmd[:-1]
    return additional_cmd
Ejemplo n.º 4
0
def save_content_win(data, output_file_path):
    fd = open(output_file_path, 'wb')
    if not fd:
        printing.ERROR("Failed to open output file, aborting")
    fd.write(data)
    fd.flush()
    fd.close()  # TODO: find the way to avoid closing it on Windows
    return 1
Ejemplo n.º 5
0
def save_content_lin(data, output_file_path):
    global fd_dict
    fd = fd_dict.get(output_file_path, None)
    if not fd:
        fd = open(output_file_path, 'wb')
        fd_dict[output_file_path] = fd
    else:
        fd.seek(0, 0)
    if not fd:
        printing.ERROR("Failed to open output file, aborting")
    fd.write(data)
    fd.flush()
    #fd.close()
    return 1
Ejemplo n.º 6
0
 def __init__(self, seed):
     self.seed = seed
     self.lib = None
     if not PY3:
         printing.ERROR("Radamsa library is not supported in Python2")