Skip to content

Commit 72b4ecf

Browse files
committed
init
1 parent 70264f4 commit 72b4ecf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+3322
-1
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.pyc
2+
*__pycache__
3+
build/
4+
dist/
5+
dwf_sdk_python.egg-info/
6+
.idea/
7+
*run.log

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
# dwf-sdk-python
2-
dwf-sdk-python

dwf.conf

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[HDFS]
2+
DWF_MODEL_STORAGE_NAME = MODEL_STORAGE
3+
DWF_MODEL_LOG_STORAGE_NAME = LOG_STORAGE
4+
5+
[LOCAL]
6+
LOCAL_TMP_DIR = /tmp
7+
8+
[LOG]
9+
LOG_FILE = run.log
10+
LOG_LEVEL = debug
11+
12+
[DB]
13+
DB_HOST = 192.168.6.106
14+
DB_PORT = 5432
15+
DB_NAME = dwf_test
16+
DB_USER = postgres
17+
DB_PASSWORD = xlearn123
18+
19+
[TEST_DB]
20+
DB_HOST = 192.168.6.106
21+
DB_PORT = 5432
22+
DB_NAME = dwf_test
23+
DB_USER = postgres
24+
DB_PASSWORD = xlearn123
25+
26+
[ROLE]
27+
ADMIN_ID = USERaaaaaaaaaaaaaaaaaaaaaaaaaaaa

dwf/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# -*- coding:utf-8 -*-
2+
3+
from pkgutil import extend_path
4+
5+
__path__ = extend_path(__path__, __name__)
6+
7+
__all__ = ['algorithm', 'common', 'datapattern', 'dataset', 'datasource', 'model', 'package', 'util']

dwf/algorithm/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# -*- coding:utf-8 -*-
2+
3+
from pkgutil import extend_path
4+
5+
__path__ = extend_path(__path__, __name__)
6+
7+
__all__ = ['metadata']

dwf/algorithm/metadata/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# -*- coding:utf-8 -*-
2+
from pkgutil import extend_path
3+
4+
__path__ = extend_path(__path__, __name__)
5+
6+
__all__ = ['algorithm_crud']

dwf/algorithm/metadata/algorithm_crud.py

+562
Large diffs are not rendered by default.

dwf/common/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# -*- coding:utf-8 -*-
2+
3+
from pkgutil import extend_path
4+
5+
__path__ = extend_path(__path__, __name__)
6+
7+
__all__ = ['config', 'exception', 'log']

dwf/common/config.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -*- coding:utf-8 -*-
2+
#
3+
# DataWay Dataset SDK
4+
# Initial Date: 2018.06.15
5+
#
6+
# Title: Global Configuration
7+
#
8+
# Version 0.1
9+
#
10+
11+
import configparser
12+
import os
13+
14+
# don't add logger here to avoid cycled dependencies.
15+
16+
deploy_config = configparser.ConfigParser()
17+
file_name = "dwf.conf"
18+
if not os.path.exists(file_name):
19+
file_name = "../dwf.conf"
20+
if not os.path.exists(file_name):
21+
file_name = "/etc/dwf/dwf.conf"
22+
deploy_config.read(file_name)
23+
24+
test_config = configparser.ConfigParser()
25+
file_name = "dwf.conf"
26+
if not os.path.exists(file_name):
27+
file_name = "../dwf.conf"
28+
if not os.path.exists(file_name):
29+
file_name = "/etc/dwf/dwf.conf"
30+
test_config.read(file_name)

dwf/common/exception.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#
2+
# DataWay SDK
3+
# Author: peizhongyi([email protected])
4+
# Initial Date: 2018.06.16
5+
#
6+
# Title: DWFException
7+
#
8+
# Version 0.1
9+
#
10+
11+
12+
class DWFException(Exception):
13+
def __init__(self, status, msg):
14+
self.STATUS = status
15+
self.MSG = msg
16+
Exception.__init__(self, msg)
17+
18+
19+
'''
20+
Unknown Exceptions
21+
'''
22+
UNDEFINE = DWFException(1, '发现未定义异常')
23+
24+
'''
25+
Exceptions for Parameters
26+
'''
27+
PARAM_LACK = DWFException(2001, '缺少参数')
28+
PARAM_WRONG_TYPE = DWFException(2002, '参数类型错误')
29+
30+
'''
31+
Exceptions for Database
32+
'''
33+
DATABASE_CONN_FAIL = DWFException(3001, '数据库连接错误')
34+
NUM_RESULT_MISMATCH = DWFException(3002, '查询记录结果数不符合预期')
35+
ILLEGAL_REPEATED_FILED = DWFException(3003, '字段不可重复')
36+
NON_EXISTING_ALGORITHM = DWFException(3004, '算法不存在')
37+
NON_EXISTING_DATA_PATTERN = DWFException(3004, '数据模式不存在')
38+
'''
39+
Exceptions for Files
40+
'''
41+
FILE_NOT_EXIST = DWFException(4001, '文件不存在')
42+
FILE_FORMAT_ERROR = DWFException(4002, '文件格式不符合预期')
43+
44+
'''
45+
Exceptions for Development
46+
'''
47+
NOT_IMPLEMENTED = DWFException(5001, '方法未实现')

dwf/common/log.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding:utf-8 -*-
2+
#
3+
# DataWay Dataset SDK
4+
# Author: peizhongyi([email protected])
5+
# Initial Date: 2018.06.16
6+
#
7+
# Title: Logger
8+
#
9+
# Version 0.1
10+
#
11+
12+
import logging as logger
13+
from dwf.common.config import deploy_config
14+
15+
LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
16+
LOG_FILE = deploy_config.get('LOG', 'LOG_FILE')
17+
18+
if deploy_config.get('LOG', 'LOG_LEVEL') == 'debug':
19+
logger.basicConfig(filename=LOG_FILE, level=logger.DEBUG, format=LOG_FORMAT)
20+
else:
21+
logger.basicConfig(filename=LOG_FILE, level=logger.INFO, format=LOG_FORMAT)

dwf/datapattern/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# -*- coding:utf-8 -*-
2+
3+
from pkgutil import extend_path
4+
5+
__path__ = extend_path(__path__, __name__)
6+
7+
__all__ = ['metadata']

dwf/datapattern/metadata/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# -*- coding:utf-8 -*-
2+
3+
from pkgutil import extend_path
4+
5+
__path__ = extend_path(__path__, __name__)
6+
7+
__all__ = ['datapattern_crud']
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# -*- coding:utf-8 -*-
2+
#
3+
# DataWay Algorithm SDK
4+
# Initial Date: 2018.10.27
5+
#
6+
# Title: methods for metadata of pattern
7+
#
8+
# Version 1.0
9+
#
10+
11+
from dwf.ormmodels import *
12+
from dwf.common.log import logger
13+
from dwf.common.exception import *
14+
from dwf.util.id import generate_primary_key
15+
16+
17+
class DataPatternCRUD:
18+
19+
def __init__(self, db_session):
20+
self.db_session = db_session
21+
22+
def add_datapattern(self, name, semantic=None):
23+
# NO.A317
24+
# Wait for jinying
25+
# Args:
26+
# package_name - The name of package.
27+
# deployment_path - The path to deploy algorithm.
28+
# upload_source - The upload source of package.
29+
# requirement_list - Dependencies of algorithms in this package.
30+
# Returns:
31+
# package_id
32+
# hyperparameter_config
33+
# Exceptions:
34+
# ADD_FAILURE
35+
id = generate_primary_key('DPAT')
36+
pattern = DataPattern(id=id, name=name, semantic=semantic)
37+
self.db_session.add(pattern)
38+
self.db_session.commit()
39+
return id
40+
41+
def delete_datapattern(self, delete_pattern_id):
42+
# NO.A320
43+
# Wait for jinying
44+
# Args:
45+
# package_id: The id of package to be deleted.
46+
# Returns:
47+
# None.
48+
# Exceptions:
49+
# NON_EXISTING_PACKAGE - The given package_id does not exist.
50+
# DELETE_FAILURE - The package cannot be deleted.
51+
pending = self.db_session.query(DataPattern).get(delete_pattern_id)
52+
self.db_session.delete(pending)
53+
self.db_session.commit()
54+
return
55+
56+
def update_datapattern(self, delete_pattern_id, name=None, semantic=None):
57+
# NO.A321
58+
# Wait for jinying
59+
# Args:
60+
# package_name - The name of package.
61+
# deployment_path - The path to deploy algorithm.
62+
# upload_source - The upload source of package.
63+
# requirement_list - Dependencies of algorithms in this package.
64+
# Returns:
65+
# package_id - The id of package.
66+
# conda_id - The id of conda.
67+
# Exceptions:
68+
# UPDATE_FAILURE - Fail to add this package.
69+
pending = self.db_session.query(DataPattern).get(delete_pattern_id)
70+
if delete_pattern_id is None:
71+
logger.error('delete_pattern_id is needed')
72+
raise PARAM_LACK
73+
74+
if name is not None:
75+
pending.plt_name = name
76+
if semantic is not None:
77+
pending.semantic = semantic
78+
self.db_session.commit()
79+
return pending
80+
81+
def query_datapattern(self, delete_pattern_id):
82+
# NO.A322
83+
# Wait for jinying
84+
# Args:
85+
# package_id: The id of package.
86+
# Returns:
87+
# {
88+
# package_name:"***",
89+
# deployment_path:"***",
90+
# upload_source:"***",
91+
# requirement_list:"***"
92+
# }
93+
pending = self.db_session.query(DataPattern).get(delete_pattern_id)
94+
if pending is None:
95+
logger.error('data pattern is not found')
96+
raise NON_EXISTING_DATA_PATTERN
97+
return pending

dwf/dataset/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# -*- coding:utf-8 -*-
2+
3+
from pkgutil import extend_path
4+
__path__ = extend_path(__path__, __name__)
5+
6+
7+
__all__ = ['io','metadata']

dwf/dataset/io/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)