예제 #1
0
파일: test.py 프로젝트: DICE-UNC/polyclone
def run_tests():
  passed = []
  failed = []
  commands = command_map.copy()
  for filename in scan_tests():
    testpath = path.join(testdir, filename)
    source_ext = path.splitext(filename)[1][1:]
    if not source_ext in conversion_dict:
      print('no conversions for test file ' + filename)
      continue
    for target_ext in conversion_dict[source_ext]:
      print('test conversion ' + filename + ' to ' + target_ext)
      work_dir = get_work_dir()
      sourcefile = path.join(work_dir, 'file.' + source_ext)
      shutil.copyfile(testpath, sourcefile)
      result = do_conversion(sourcefile, target_ext)
      conversionpath = source_ext + ':' + target_ext
      command = commands.pop(conversionpath)
      if result == True:
        passed.append(conversionpath + ':' + command)
      else:
        failed.append((conversionpath + ':' + command, result))
      clean_work_dir(work_dir)
  untested = []
  return {
    'passed': passed,
    'failed': failed,
    'untested': list(commands.keys())
  }
예제 #2
0
파일: test.py 프로젝트: DICE-UNC/polyclone
def run_tests():
    passed = []
    failed = []
    commands = command_map.copy()
    for filename in scan_tests():
        testpath = path.join(testdir, filename)
        source_ext = path.splitext(filename)[1][1:]
        if not source_ext in conversion_dict:
            print('no conversions for test file ' + filename)
            continue
        for target_ext in conversion_dict[source_ext]:
            print('test conversion ' + filename + ' to ' + target_ext)
            work_dir = get_work_dir()
            sourcefile = path.join(work_dir, 'file.' + source_ext)
            shutil.copyfile(testpath, sourcefile)
            result = do_conversion(sourcefile, target_ext)
            conversionpath = source_ext + ':' + target_ext
            command = commands.pop(conversionpath)
            if result == True:
                passed.append(conversionpath + ':' + command)
            else:
                failed.append((conversionpath + ':' + command, result))
            clean_work_dir(work_dir)
    untested = []
    return {
        'passed': passed,
        'failed': failed,
        'untested': list(commands.keys())
    }
예제 #3
0
def process_form():
  if not 'output_format' in request.form:
    return 'no destination format specified', 400
  target_format = request.form['output_format']
  target_format = target_format.strip()
  
  if not 'file' in request.files:
    return 'file not found in POST', 400
  file = request.files['file']
  file_base_name = path.splitext(file.filename)[0]
  source_format = path.splitext(file.filename)[1][1:]

  tmp_path = get_work_dir()

  @after_this_request
  def delete_work_dir(response):
    clean_work_dir(tmp_path)
    return response

  filepath = path.join(tmp_path, 'file.' + source_format)
  file.save(filepath)
  result = do_conversion(filepath, target_format)
  if result <> True:
    return result, 500

  resp = send_from_directory(tmp_path, 'file.' + target_format)
  resp.headers['Content-Disposition'] = 'attachment; filename=' + file_base_name + '.' + target_format
  return resp
예제 #4
0
def process_form():
    if not 'output_format' in request.form:
        return 'no destination format specified', 400
    target_format = request.form['output_format']
    target_format = target_format.strip()

    if not 'file' in request.files:
        return 'file not found in POST', 400
    file = request.files['file']
    file_base_name = path.splitext(file.filename)[0]
    source_format = path.splitext(file.filename)[1][1:]

    tmp_path = get_work_dir()

    @after_this_request
    def delete_work_dir(response):
        clean_work_dir(tmp_path)
        return response

    filepath = path.join(tmp_path, 'file.' + source_format)
    file.save(filepath)
    result = do_conversion(filepath, target_format)
    if result <> True:
        return result, 500

    resp = send_from_directory(tmp_path, 'file.' + target_format)
    resp.headers[
        'Content-Disposition'] = 'attachment; filename=' + file_base_name + '.' + target_format
    return resp