-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathprotongen.py
96 lines (81 loc) · 5.13 KB
/
protongen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
# BSD 3-Clause License
#
# Copyright (c) 2018, Pruthvi Kumar All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
# following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this list of conditions and the following
# disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided with the distribution.
#
# Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import os
import argparse
from colorama import Fore, Style
from nucleus.execgen import ExecGen
from nucleus.metagen import MetaGen
__author__ = "Pruthvi Kumar, pruthvikumar.123@gmail.com"
__copyright__ = "Copyright (C) 2018 Pruthvi Kumar | http://www.apricity.co.in"
__license__ = "BSD 3-Clause License"
__version__ = "1.0"
class ProtonGen(MetaGen, ExecGen):
def __init__(self):
super(ProtonGen, self).__init__()
self.protongen_logger = self.get_logger(log_file_name='proton_gen_logs',
log_file_path='{}/trace/proton_gen_logs.log'.format(self.ROOT_DIR))
self.parser = argparse.ArgumentParser()
self.parser.add_argument('--mic_name', help='MIC stands for Model Interface & Controller. Proton spins up'
'the MIC stack for you; when provided with a name.')
self.parser.add_argument('--port', help='Port for PROTON to launch the interface onto. Defaults to 3000.')
self.parser.add_argument('--forceStart', help='Do not create a new MIC Stack; but, executes PROTON stack '
'by re-generating main with existing iFace!')
self.proton_args = self.parser.parse_args()
try:
self.bootstrap_sqlite()
if self.proton_args.mic_name is None:
if self.proton_args.forceStart is not None:
self.generate_executor(port=3000)
print(Fore.GREEN + 'PROTON initialized with existing iFace stack! Starting service '
'@ 3000' + Style.RESET_ALL)
self.protongen_logger.info('PROTON initialized with existing iFace stack! Starting service @ 3000')
else:
print(Fore.GREEN + '[PROTON-GEN] - There is no name provided for Proton to initiate. Please '
'provide a valid mic_name using --mic_name argument' + Style.RESET_ALL)
self.protongen_logger.info(
'[PROTON-GEN] - There is no name provided for Proton to initiate. Please '
'provide a valid mic_name using --mic_name argument')
else:
if self.proton_args.port is None:
self.proton_args.port = 8000
self.__creator(self.proton_args.mic_name, self.proton_args.port)
except Exception as e:
self.protongen_logger.exception('[ProtonGen] Error during protonGen initialization. Stacktrace to follow')
self.protongen_logger.exception(str(e))
def __creator(self, mic_name, port):
try:
with open('{}/proton_vars/target_table_for_{}.txt'.format(self.ROOT_DIR, mic_name)) as f:
target_table_for_mic = f.read().replace('\n', '')
self.new_mic(mic_name=mic_name)
self.generate_executor(port=port)
print(Fore.GREEN + 'PROTON initialized for {}. Starting service @ {} & target table for this MIC '
'stack is - {}'.format(mic_name, port, target_table_for_mic) + Style.RESET_ALL)
self.protongen_logger.info('[ProtonGen] Proton initialized for mic_name - {} @ port {} & target table for '
'this MIC stack is -{}'.format(mic_name, port, target_table_for_mic))
except Exception as e:
self.protongen_logger.exception('[ProtonGen] Error during protonGen initialization for mic_name '
'{}. Details: {}'.format(mic_name, str(e)))
if __name__ == '__main__':
ProtonGen()