Skip to content

Commit

Permalink
[qacode] fixed new package with py rules
Browse files Browse the repository at this point in the history
  • Loading branch information
crypto netzulo committed Oct 1, 2017
1 parent 5db748c commit fae20c2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 37 deletions.
7 changes: 7 additions & 0 deletions qacode.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
<Compile Include="qacode\core\testing\testlink\TestlinkBase.py" />
<Compile Include="qacode\core\testing\testlink\__init__.py" />
<Compile Include="qacode\core\testing\__init__.py" />
<Compile Include="qacode\core\utils\Utils.py" />
<Compile Include="qacode\core\utils\__init__.py" />
<Compile Include="qacode\core\webs\controls\ControlBase.py">
<SubType>Code</SubType>
</Compile>
Expand Down Expand Up @@ -88,6 +90,9 @@
<Content Include="appveyor.yml" />
<Content Include="LICENSE" />
<Content Include="qacode\configs\settings.example.ini" />
<Content Include="qacode\configs\settings.json" />
<Content Include="qacode\core\utils\__pycache__\Utils.cpython-36.pyc" />
<Content Include="qacode\core\utils\__pycache__\__init__.cpython-36.pyc" />
<Content Include="qacode\logs\.gitkeep" />
<Content Include="qacode\logs\qacode.log" />
<Content Include="README.rst" />
Expand All @@ -106,6 +111,8 @@
<Folder Include="qacode\core\loggers" />
<Folder Include="qacode\core\testing" />
<Folder Include="qacode\core\testing\testlink" />
<Folder Include="qacode\core\utils\" />
<Folder Include="qacode\core\utils\__pycache__\" />
<Folder Include="qacode\core\webs" />
<Folder Include="qacode\core\webs\controls" />
<Folder Include="qacode\core\webs\pages" />
Expand Down
62 changes: 30 additions & 32 deletions qacode/core/utils/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

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')
)
20 changes: 15 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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',
Expand Down

0 comments on commit fae20c2

Please sign in to comment.