From fae20c2b52883b3a3631f7a30e607b01c7d29c92 Mon Sep 17 00:00:00 2001 From: crypto netzulo Date: Sun, 1 Oct 2017 14:27:31 +0200 Subject: [PATCH] [qacode] fixed new package with py rules --- qacode.pyproj | 7 +++++ qacode/core/utils/Utils.py | 62 ++++++++++++++++++-------------------- setup.py | 20 +++++++++--- 3 files changed, 52 insertions(+), 37 deletions(-) diff --git a/qacode.pyproj b/qacode.pyproj index a891d6c9..89bbeafa 100644 --- a/qacode.pyproj +++ b/qacode.pyproj @@ -40,6 +40,8 @@ + + Code @@ -88,6 +90,9 @@ + + + @@ -106,6 +111,8 @@ + + diff --git a/qacode/core/utils/Utils.py b/qacode/core/utils/Utils.py index d6f0dad5..e77e2408 100644 --- a/qacode/core/utils/Utils.py +++ b/qacode/core/utils/Utils.py @@ -3,40 +3,38 @@ from sys import version_info from os import path -from json import * +import json -class Utils(object): - """All methods what i don't know where to include""" - @staticmethod - def get_file(version_py=version_info.major,file_path=None, file_name=None, encoding=None, json=False): - """Returns file, py version and enconding parametrization""" - if not path.exists(file_path): +def get_path_join(file_path=None, file_name=None): + """Return absolute path for __file__ instance""" + if file_path is None or not path.exists(file_path): raise IOError("Path '{0!s}' doesn't exists") - if not path.exists(file_name): - raise IOError("File '{0!s}' doesn't exists") - file_path_join = path.join(Utils.get_file_abspath(file_path), file_name) - if json: - with open(file_path_join, 'r') as f: - return json.load(f) - if encoding is None: - with open(file_path_join) as f: - return f.read() - if version_py == 3: - with open(file_path_join, encoding=encoding) as f: + if file_name is None or not path.exists(file_name): + raise IOError("File '{0!s}' doesn't exists") + return path.join(file_path, file_name) + +def read_file(is_json=False, file_path=None, encoding='utf-8'): + """Returns file object from file_path, + compatible with all py versiones + optionals: + can be use to return dict from json path + can modify encoding used to obtain file + """ + if is_json: + return json.load(file_abspath) + if file_path is None: + raise Exception("File path received it's None") + if version_info.major >= 3: + with open(file_path, encoding=encoding) as f: return f.read() - if version_py == 2: - with open(file_path_join) as f: + if version_info.major <= 2: + with open(file_path) as f: return f.read().decode(encoding) - @staticmethod - def get_file_abspath(file=None): - """Return absolute path for __file__ instance""" - if file is None: - raise IOError("File '{0!s}' doesn't exists") - return path.abspath(path.dirname(file)) - - @staticmethod - def get_config(): - return Utils.get_file(json=True, - file_path='qacode/configs', - file_name='settings.json') \ No newline at end of file + +def settings(): + """Returns file settings as a dict to be use on qacode lib""" + return read_file(is_json=True, file_path=get_path_join( + file_path='qacode/configs/', + file_name='settings.ini') + ) \ No newline at end of file diff --git a/setup.py b/setup.py index 7e0b6d26..e8577444 100755 --- a/setup.py +++ b/setup.py @@ -1,16 +1,26 @@ +# -*- coding: utf-8 -*- + + from setuptools import setup, find_packages -from qacode.core.utils.Utils import Utils +from qacode.core.utils.Utils import read_file +from qacode.core.utils.Utils import get_path_join + + +def read(file_name=None): + if file_name is None: + raise Exception("File name not provided") + return read_file(file_path=get_path_join( + file_path='./', file_name=file_name) + ) setup( name='qacode', version='0.1.9', - license=Utils.get_file(file_path=__file__, file_name='LICENSE'), + license=read("LICENSE"), packages=find_packages(exclude=['tests']), description='Main automation lib', - long_description=Utils.get_file(file_path=__file__, - file_name='README.rst', - encoding='utf-8'), + long_description=read("README.rst"), author='Netzulo Open Source', author_email='netzuleando@gmail.com', url='https://github.com/netzulo/qacode',