コード例 #1
0
ファイル: file.py プロジェクト: mikalindh/qweb
 def create_text_file_instance(filename):
     filepath = download.get_path(filename)
     try:
         with open(filepath, 'rb') as txt_file:
             data = txt_file.read()
             data = data.decode("utf-8")
             if data != '':
                 return File(data, filepath)
             raise QWebValueMismatchError(
                 'Text not found. Seems that the file is empty.')
     except TypeError as e:
         raise QWebFileNotFoundError(
             'File not found. Got {} instead.'.format(e))
コード例 #2
0
def get_path(filename):
    if Path(filename).exists():
        return Path(filename)
    files = Path(BuiltIn().get_variable_value(
        '${SUITE SOURCE}')).parent.parent / 'files' / filename
    images = Path(BuiltIn().get_variable_value(
        '${SUITE SOURCE}')).parent.parent / 'images' / filename
    downloads = Path(get_downloads_dir()) / filename
    paths = [downloads, files, images]
    for path in paths:
        if path.exists():
            logger.debug(path)
            return path
    try:
        base_path = BuiltIn().get_variable_value(u'${base_image_path}')
        full_path = os.path.join(base_path, "{}".format(filename.lower()))
        return Path(full_path)
    except TypeError:
        raise QWebFileNotFoundError(
            'File not found from default folders. Set variable for base image path'
        )