Skip to content

Commit

Permalink
2018.6.4 v1.0.13, add function from issue ,issue number is #27 #28 #35
Browse files Browse the repository at this point in the history
  • Loading branch information
jun.hu committed Jun 4, 2018
2 parents 96cead2 + f0ce0df commit 3d37a2c
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 60 deletions.
114 changes: 103 additions & 11 deletions .gitignore
@@ -1,14 +1,106 @@
.idea/
*.zip
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
fish_base-1.0.9.tar.gz
fish_base/__pycache__/__init__.cpython-35.pyc
fish_base/__pycache__/fish_common.cpython-35.pyc
fish_base/__pycache__/fish_date.cpython-35.pyc
fish_base/__pycache__/fish_file.cpython-35.pyc
<<<<<<< HEAD
=======

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
test/log
>>>>>>> 1a649f6bc4e5e2764d5828516da5ce51f2a79ee9
/_build/*
demo/log
.pytest_cache
19 changes: 8 additions & 11 deletions dev_doc/fish_issues.md
Expand Up @@ -12,12 +12,18 @@ last update: 2018.5.26
* 19042, file, edit function check_sub_path_create(), edit docstring, add unittest; ok
* 19043, common, edit function sorted_list_from_dict(), optimize, doc and unittest; ok
* 19044, common, edit function sorted_list_from_dict(), update doc; ok
* 19045, common, edit function hmac_sha256(), optimize, doc and unittest; ok
* 19046, common, edit function if_element_is_timestamp(), optimize, doc and unittest; ok
* 19047, common, edit function check_number_len(), optimize, doc and unittest; ok
* 19048, common, edit function check_str(), optimize, doc and unittest; ok
* 19049, date, edit function previous_months_date(), optimize, doc and unittest; ok
---

#### v1.0.12

* 19036, edit fish_base to fishbase

last update: 2018.5.18
---

#### v1.0.11

Expand Down Expand Up @@ -89,15 +95,6 @@ fish_common 目前测试覆盖率 65%

---

待排

* 19012,优化日志功能,缩写line->ln, 增加可选是否记录线程的编号
* 19014,unittest, 完善 test_common 部分
* 19025,file 中剩余函数也加入 docstring 说明
* 19026,构建统一单元测试,从 csv 中开始
* 19027,file auto_add_file_ext() 原来实现方式有问题,删除该函数
* 19028,修改完善 demo_file.py 中的例子;ok

安装
补充

* 文档主题需要安装 pip install sphinx_rtd_theme
2 changes: 1 addition & 1 deletion docs/conf.py
Expand Up @@ -30,7 +30,7 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autodoc', 'sphinx.ext.autosummary'
]

# Add any paths that contain templates here, relative to this directory.
Expand Down
11 changes: 11 additions & 0 deletions docs/fish_common.rst
@@ -1,5 +1,16 @@
``fish_common`` 基本函数包
=============================

.. autosummary::
fish_common.conf_as_dict
fish_common.get_uuid
fish_common.GetMD5.string
fish_common.GetMD5.file
fish_common.GetMD5.big_file
fish_common.if_json_contain
fish_common.SingleTon
fish_common.sorted_list_from_dict
fish_common.splice_url_params

.. automodule:: fish_common
:members:
1 change: 1 addition & 0 deletions fishbase/__init__.py
Expand Up @@ -24,3 +24,4 @@
from .fish_system import *

__version__ = '1.0.13' # type: str

15 changes: 7 additions & 8 deletions fishbase/fish_common.py
Expand Up @@ -40,7 +40,7 @@
# 2017.2.23 #19008 create by David Yi
# 2018.2.12 #11014 edit by David Yi, 增加返回内容,字典长度,
# 2018.4.18 #19015 加入 docstring,完善文档说明
# 2018.5.14 v1.0.11 $19028 逻辑修改,更加严密
# 2018.5.14 v1.0.11 #19028 逻辑修改,更加严密
def conf_as_dict(conf_filename):
"""
读入 ini 配置文件,返回根据配置文件内容生成的字典类型变量;
Expand Down Expand Up @@ -444,7 +444,7 @@ def splice_url_params(dic):
# v1.0.13 #19043, edit by Hu Jun, edit by David Yi
def sorted_list_from_dict(p_dict, order=odASC):
"""
sorted_list_from_dict,根据字典的 value 进行排序,并以列表形式返回
根据字典的 value 进行排序,并以列表形式返回
:param:
* p_dict: (dict) 需要排序的字典
Expand All @@ -454,7 +454,7 @@ def sorted_list_from_dict(p_dict, order=odASC):
举例如下::
print('--- sorted_list_from_dict demo ---')
# 定义待处理字典
dict1 = {'a_key': 'a_value', '1_key': '1_value', 'A_key': 'A_value', 'z_key': 'z_value'}
print(dict1)
list1 = sorted_list_from_dict(dict1, odASC)
Expand All @@ -465,7 +465,6 @@ def sorted_list_from_dict(p_dict, order=odASC):
执行结果::
--- sorted_list_from_dict demo ---
{'a_key': 'a_value', 'A_key': 'A_value', '1_key': '1_value', 'z_key': 'z_value'}
ascending order result is: ['1_value', 'A_value', 'a_value', 'z_value']
descending order result is: ['z_value', 'a_value', 'A_value', '1_value']
Expand All @@ -480,7 +479,7 @@ def sorted_list_from_dict(p_dict, order=odASC):
return o_list[::-1]


# v1.0.13 #19044, original by Jia Chunying, edit by David Yi, edit by Hu Jun
# v1.0.13 #19045, original by Jia Chunying, edit by David Yi, edit by Hu Jun
def hmac_sha256(secret, message):
"""
hmac_sha256,通过秘钥获取消息的hash值
Expand Down Expand Up @@ -514,7 +513,7 @@ def hmac_sha256(secret, message):
return hashed_str


# v1.0.13 #19045, edit by David Yi, edit by Hu Jun
# v1.0.13 #19046, edit by David Yi, edit by Hu Jun
def if_element_is_timestamp(source):
"""
if_element_is_timestamp,检查对象是否是unix时间戳
Expand Down Expand Up @@ -554,7 +553,7 @@ def if_element_is_timestamp(source):
return False


# v1.0.13 #19046, edit by David Yi, edit by Hu Jun
# v1.0.13 #19047, edit by David Yi, edit by Hu Jun
def check_number_len(p_number, min_length=None, max_length=None):
"""
check_number_len,判断整数的位数、字符串的长度否在限定长度内
Expand Down Expand Up @@ -612,7 +611,7 @@ def check_number_len(p_number, min_length=None, max_length=None):
return True


# v1.0.13 #19047, edit by David Yi, edit by Hu Jun
# v1.0.13 #19048, edit by David Yi, edit by Hu Jun
def check_str(p_str, check_style=ZhType):
"""
check_str,检查字符串是否含有指定类型字符
Expand Down
2 changes: 1 addition & 1 deletion fishbase/fish_csv.py
Expand Up @@ -20,7 +20,7 @@ def csv_file_to_list(csv_filename, deli=',', del_blank_row=True):
* csv_filename: (string) csv 文件的长文件名
* deli: (string) csv 文件分隔符,默认为逗号
* del_blank_row: (string) 是否要删除空行,默认为删除
:returns:
:return:
* csv_list: (list) 转换后的 list
举例如下::
Expand Down
2 changes: 1 addition & 1 deletion fishbase/fish_date.py
Expand Up @@ -37,7 +37,7 @@ def get_date_range(date_kind):
return first_day, last_day


# v1.0.13 #19048, edit by David Yi, edit by Hu Jun
# v1.0.13 #19049, edit by David Yi, edit by Hu Jun
def previous_months_date(n):
"""
previous_months_date,获得当前时间往前n个月的时间(年月)
Expand Down
49 changes: 24 additions & 25 deletions fishbase/fish_file.py
Expand Up @@ -79,36 +79,35 @@ def get_abs_filename_with_sub_path(sub_path, filename):
def get_abs_filename_with_sub_path_module(sub_path, filename):

"""
生成使用模块时的下一级路径某文件的完整文件名;
生成使用模块时的下一级路径某文件的完整文件名;
:param:
* sub_path: (string) 下一级的某路径名称
* filename: (string) 下一级路径的某个文件名
:returns:
* 返回类型 (tuple),有两个值,第一个为 flag,第二个为文件名,说明见下
* flag: (bool) 如果文件存在,返回 True,文件不存在,返回 False
* abs_filename: (string) 指定 filename 的包含路径的长文件名,注意是模块安装的路径,不是应用程序的路径
举例如下::
:param:
* sub_path: (string) 下一级的某路径名称
* filename: (string) 下一级路径的某个文件名
:return:
* 返回类型 (tuple),有两个值,第一个为 flag,第二个为文件名,说明见下
* flag: (bool) 如果文件存在,返回 True,文件不存在,返回 False
* abs_filename: (string) 指定 filename 的包含路径的长文件名,注意是模块安装的路径,不是应用程序的路径
# 定义子路径名称
sub_path = 'test_sub_dir'
# 定义存在的文件名称
filename_existent = 'demo_file.txt'
# 定义不存在的文件名称
filename_non_existent = 'demo.txt'
# 生成下一级路径文件的完整文件名
result = get_abs_filename_with_sub_path_module(sub_path, filename_existent)
print(result)
举例如下::
result = get_abs_filename_with_sub_path_module(sub_path, filename_non_existent)
print(result)
# 定义子路径名称
sub_path = 'test_sub_dir'
# 定义存在的文件名称
filename_existent = 'demo_file.txt'
# 定义不存在的文件名称
filename_non_existent = 'demo.txt'
# 生成下一级路径文件的完整文件名
result = get_abs_filename_with_sub_path_module(sub_path, filename_existent)
print(result)
输出结果::
result = get_abs_filename_with_sub_path_module(sub_path, filename_non_existent)
print(result)
(True, '/Users/*****/anaconda3/lib/python3.6/site-packages/fishbase/test_sub_dir/demo_file.txt')
(False, '/Users/****/anaconda3/lib/python3.6/site-packages/fishbase/test_sub_dir/demo.txt')
输出结果::
(True, '/Users/*****/anaconda3/lib/python3.6/site-packages/fishbase/test_sub_dir/demo_file.txt')
(False, '/Users/****/anaconda3/lib/python3.6/site-packages/fishbase/test_sub_dir/demo.txt')
"""

cur_module_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
Expand Down Expand Up @@ -142,7 +141,7 @@ def check_sub_path_create(sub_path):
:param:
* sub_path: (string) 下一级的某路径名称
:returns:
:return:
* 返回类型 (tuple),有两个值
* True: 路径存在,False: 不需要创建
* False: 路径不存在,True: 创建成功
Expand Down
2 changes: 1 addition & 1 deletion fishbase/fish_logger.py
Expand Up @@ -108,7 +108,7 @@ def set_log_file(local_file=None):
:param:
* local_fie: (string) 日志文件名
:returns:
:return: 无
举例如下::
Expand Down
2 changes: 1 addition & 1 deletion fishbase/fish_system.py
Expand Up @@ -16,7 +16,7 @@ def get_platform():
:param:
* 无
:returns:
:return:
* platform: (string) 返回 linux, osx, win 或者其他
举例如下::
Expand Down

0 comments on commit 3d37a2c

Please sign in to comment.