Mercurial > repos > kls286 > chap_test_20230328
comparison build/bdist.linux-x86_64/egg/CHAP/models/basemodel.py @ 0:cbbe42422d56 draft
planemo upload for repository https://github.com/CHESSComputing/ChessAnalysisPipeline/tree/galaxy commit 1401a7e1ae007a6bda260d147f9b879e789b73e0-dirty
author | kls286 |
---|---|
date | Tue, 28 Mar 2023 15:07:30 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cbbe42422d56 |
---|---|
1 #!/usr/bin/env python | |
2 #-*- coding: utf-8 -*- | |
3 #pylint: disable= | |
4 """ | |
5 File : basemodel.py | |
6 Author : Valentin Kuznetsov <vkuznet AT gmail dot com> | |
7 Description: BaseModel module | |
8 """ | |
9 | |
10 # system modules | |
11 import logging | |
12 | |
13 | |
14 class BaseModel(): | |
15 """ | |
16 BaseModel docstring | |
17 """ | |
18 def __init__(self, filename=None, **kwds): | |
19 self.logger = logging.getLogger(__name__) | |
20 self.construct(filename, **kwds) | |
21 self.map = dict(name=__name__) | |
22 | |
23 def construct(self, filename=None, **kwds): | |
24 """ | |
25 construct from CLI object | |
26 | |
27 :param filename: input file name | |
28 :param **kwds: named arguments | |
29 :return: Basemodel object | |
30 """ | |
31 print('construct API calls: ', end='') | |
32 if filename and filename.endswith('yaml'): | |
33 self.construct_from_yaml(filename) | |
34 elif filename and filename != '': | |
35 self.construct_from_file(filename) | |
36 else: | |
37 self.construct_from_config(**kwds) | |
38 | |
39 @classmethod | |
40 def construct_from_config(cls, **config): | |
41 """ | |
42 construct from config object | |
43 | |
44 :param **config: named arguments | |
45 :return: Basemodel object | |
46 """ | |
47 print(f'construct_from_config: {config}') | |
48 | |
49 @classmethod | |
50 def construct_from_yaml(cls, filename): | |
51 """ | |
52 construct from CLI object | |
53 | |
54 :param filename: input file name | |
55 :return: Basemodel object | |
56 """ | |
57 print(f'construct_from_yaml: {filename}') | |
58 | |
59 @classmethod | |
60 def construct_from_file(cls, filename): | |
61 """ | |
62 construct from filename | |
63 | |
64 :param filename: input file name | |
65 :return: Basemodel object | |
66 """ | |
67 print(f'construct_from_file: {filename}') | |
68 | |
69 def getMap(self): | |
70 """ | |
71 return model map | |
72 | |
73 :return: map object | |
74 """ | |
75 return self.map | |
76 | |
77 | |
78 if __name__ == '__main__': | |
79 print('### should construct from file.yaml') | |
80 base = BaseModel('file.yaml') | |
81 print('### should construct from file.txt') | |
82 base = BaseModel('file.txt') | |
83 print('### should construct from config') | |
84 base = BaseModel(param='file.txt', arg='bla') |