Exemplo n.º 1
0
def main():
    js = utils.read_file(js_file)
    ctors_start, ctors_end = find_ctors(js)
    if ctors_start < 0:
        logger.debug('ctor_evaller: no ctors')
        sys.exit(0)

    ctors_text = js[ctors_start:ctors_end]
    if ctors_text.count('(') == 1:
        logger.debug('ctor_evaller: push, but no ctors')
        sys.exit(0)

    num_ctors = ctors_text.count('function()')
    logger.debug('ctor_evaller: %d ctors, from |%s|' % (num_ctors, ctors_text))

    wasm_file = binary_file
    logger.debug('ctor_evaller (wasm): trying to eval %d global constructors' %
                 num_ctors)
    num_successful, new_js = eval_ctors(js, wasm_file, num_ctors)
    if num_successful == 0:
        logger.debug('ctor_evaller: not successful')
        sys.exit(0)
    logger.debug('ctor_evaller: we managed to remove %d ctors' %
                 num_successful)
    utils.write_file(js_file, new_js)
Exemplo n.º 2
0
def generate_minimal_runtime_html(target, options, js_target, target_basename):
  logger.debug('generating HTML for minimal runtime')
  shell = utils.read_file(options.shell_path)
  if settings.SINGLE_FILE:
    # No extra files needed to download in a SINGLE_FILE build.
    shell = shell.replace('{{{ DOWNLOAD_JS_AND_WASM_FILES }}}', '')
  else:
    shell = shell.replace('{{{ DOWNLOAD_JS_AND_WASM_FILES }}}', generate_minimal_runtime_load_statement(target_basename))

  temp_files = shared.configuration.get_temp_files()
  with temp_files.get_file(suffix='.js') as shell_temp:
    utils.write_file(shell_temp, shell)
    shell = shared.read_and_preprocess(shell_temp)

  if re.search(r'{{{\s*SCRIPT\s*}}}', shell):
    shared.exit_with_error('--shell-file "' + options.shell_path + '": MINIMAL_RUNTIME uses a different kind of HTML page shell file than the traditional runtime! Please see $EMSCRIPTEN/src/shell_minimal_runtime.html for a template to use as a basis.')

  shell = shell.replace('{{{ TARGET_BASENAME }}}', target_basename)
  shell = shell.replace('{{{ EXPORT_NAME }}}', settings.EXPORT_NAME)
  shell = shell.replace('{{{ PTHREAD_WORKER_FILE }}}', settings.PTHREAD_WORKER_FILE)

  # In SINGLE_FILE build, embed the main .js file into the .html output
  if settings.SINGLE_FILE:
    js_contents = utils.read_file(js_target)
    shared.try_delete(js_target)
  else:
    js_contents = ''
  shell = shell.replace('{{{ JS_CONTENTS_IN_SINGLE_FILE_BUILD }}}', js_contents)
  shell = line_endings.convert_line_endings(shell, '\n', options.output_eol)
  # Force UTF-8 output for consistency across platforms and with the web.
  with open(target, 'wb') as f:
    f.write(shell.encode('utf-8'))
f = f.replace('}new TextDecoder("utf8");', '}')
f = f.replace(';new TextDecoder("utf-16le");', ';')
f = f.replace('}new TextDecoder("utf-16le");', '}')

# var a;a||(a=Module)
# ->
# var a=Module;
f = re.sub(r'var (\w);\1\|\|\(\1=Module\);', r'var \1=Module;', f)

# var Module=function(Module){Module =Module || {};var a=Module;
# ->
# var Module=function(a){
f = re.sub(
    r'\s*function\s*\(Module\)\s*{\s*Module\s*=\s*Module\s*\|\|\s*{\s*}\s*;\s*var\s+(\w+)\s*=\s*Module\s*;',
    r'function(\1){', f)

f = re.sub(r'\s+', ' ', f)
f = re.sub(r'[\n\s]+\n\s*', '\n', f)
f = re.sub(r'([;{}=,\+\-\*/\(\)\[\]])[\n]', r'\1', f)
f = re.sub(r'([;{}=,\*/\(\)\[\]])[\s]', r'\1', f)

# Finally, rerun minifier because the above changes may have left redundant whitespaces
write_file(sys.argv[1], f)
minified = building.acorn_optimizer(sys.argv[1], ['minifyWhitespace'],
                                    return_output=True)
write_file(sys.argv[1], minified)

# optimized_size = len(f)
# print('Further optimized ' + str(optimized_size - orig_size) + ' bytes (' + str(orig_size) + ' -> ' + str(optimized_size) + ' bytes, {0:.2f}'.format((optimized_size-orig_size)*100.0/orig_size) + '%)')
write_file(sys.argv[1], f)
Exemplo n.º 4
0
def build_write_file_head():
    product_list = []
    product_list.append('Customer_ID')
    for i in range(12):
        num = str(i + 1)
        product_list.append('Product_' + num.zfill(2))
    return utils.list_to_str(product_list)


def build_write_list(cust_prod_dic):
    write_list = []
    write_list.append(build_write_file_head())
    customer_list = list(cust_prod_dic.keys())
    customer_list.sort()
    for customer in iter(customer_list):
        line = []
        line.append(customer)
        line.extend(cust_prod_dic[customer])
        write_list.append(utils.list_to_str(line))
    return write_list


if __name__ == '__main__':
    print('start')
    data = utils.read_file(
        os.path.join(constant.data_files_path, constant.products_dat_name))
    cust_prod = build_cust_prod(data)
    cust_prod_write_list = build_write_list(cust_prod)
    utils.write_file('cust_prod_test.dat', cust_prod_write_list)
    print("end")
Exemplo n.º 5
0
 def unpack():
     logger.info(f'unpacking port: {name}')
     shared.safe_ensure_dirs(fullname)
     shutil.unpack_archive(filename=fullpath, extract_dir=fullname)
     utils.write_file(marker, url + '\n')
Exemplo n.º 6
0
                    key = listing['sell']['keys'] * cfg.KEY_PRICE * 9
                    ref = listing['sell']['metal'] * 9

                    for trade in trades:
                        profit += ((key + ref) - trade['price'])

                    break

    print(f"potential: {utils.to_keys(profit)} keys")

    # profit since last checked -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    if 'logs' not in os.listdir('./'):
        os.mkdir('./logs')

    if 'history.json' not in os.listdir('./logs'):
        utils.write_file('./logs/history.json', {})

    history = utils.read_file('./logs/history.json')

    if account_name not in history:
        history[account_name] = {}

    h = history[account_name]
    h[datetime.now().strftime('%d-%m-%Y_%H:%M:%S')] = utils.to_keys(
        sum([item_data[sku]['profit'] for sku in item_data]))

    if 2 <= len(h):
        dates = list(h.keys())
        print(
            f"since last checked ({dates[-2]}): {round(h[dates[-1]] - h[dates[-2]], 2)} keys"
        )