Skip to content

Commit

Permalink
feat: replace the std print to the logging module
Browse files Browse the repository at this point in the history
  • Loading branch information
maksyuki committed Feb 23, 2024
1 parent 84c22b2 commit d14f979
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
31 changes: 12 additions & 19 deletions src/add_soc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ def fill_data(self, term: List[str]):

def handle_err(self, val: str):
# NOTE: need to write to the submit info
print(f'ID: error format, the err val: {val}')
logging.info(msg=f'ID: error format, the err val: {val}')

def add(self):
with open(config.SUBMIT_LIST_PATH, 'r+', encoding='utf-8') as fp:
for v in fp.readlines():
tmp = v.split()
print(tmp[1])
logging.debug(msg=tmp[1])
if self.check_valid(tmp[1]) != '':
self.fill_data(tmp)
else:
Expand All @@ -49,16 +49,15 @@ def add(self):
# update the core list
def update(self):
os.chdir(config.SUBMIT_DIR)
# os.system('git checkout ' + config.CUR_BRAN)
# print(f'git checkout {config.CUR_BRAN}')
os.system('git checkout ' + config.CUR_BRAN)
logging.info(msg=f'git checkout {config.CUR_BRAN}')
with open(config.CORE_LIST_PATH, 'r+', encoding='utf-8') as fp:
for v in fp.readlines():
tmp = v.split()
# print('id: ' + val)
# filter err and spaces
if self.check_valid(tmp[0]) != '':
self.core_list.append(CoreInfo('', tmp[0]))
# print('id: ' + v.rstrip('\n'))
logging.debug(msg=f'id: {tmp[0]}')

self.core_list.sort(key=lambda v: v.sid)
self.submit_list.sort(key=lambda v: v.sid)
Expand All @@ -73,13 +72,13 @@ def update(self):

if is_find is False:
os.system(f'git clone {va.url} submit/{va.sid}')
# print(f'git clone {va.url} submit/{va.sid}')
logging.debug(msg=f'git clone {va.url} submit/{va.sid}')
new_id.append(CoreInfo('', va.sid, 'F'))

print(f'new core num: {len(new_id)}')
logging.debug(msg=f'new core num: {len(new_id)}')
self.core_list += new_id
self.core_list.sort(key=lambda v: v.sid)
# print(self.core_list)
logging.debug(msg=self.core_list)
with open(config.CORE_LIST_PATH, 'w+', encoding='utf-8') as fp:
for v in self.core_list:
fp.write(v.sid + ' ' + v.flag + '\n')
Expand All @@ -89,17 +88,11 @@ def update(self):


def main():
logging.basicConfig(filename=config.RUN_LOG_PATH, filemode='w', format='%(asctime)s %(name)s:%(levelname)s:%(message)s', datefmt='%Y-%M-%d %H:%M:%S', level=logging.DEBUG)
logging.info('[add soc]')
logging.debug('This is a debug message')
logging.warning('This is a warning message')
logging.error('This is an error message')
logging.critical('This is a critical message')

logging.info(msg='[add soc]')
os.system(f'mkdir -p {config.DATA_DIR}')
# cores.clear()
# cores.add()
# cores.update()
cores.clear()
cores.add()
cores.update()


if __name__ == '__main__':
Expand Down
10 changes: 7 additions & 3 deletions src/task.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/python

import time
import config
import logging
import schedule
import config
import add_soc
import repo_update
import dispatch
Expand All @@ -18,13 +18,17 @@
# toml, database
def main_task():
add_soc.main()
# repo_update.main()
repo_update.main()
# dispatch.main()


logging.basicConfig(filename=config.RUN_LOG_PATH, filemode='w',
# prio level: DEBUG < INFO < WARNING < ERROR < CRITICAL
# logging print message which greater than prio level
logging.basicConfig(filename=config.RUN_LOG_PATH, filemode='a',
format='%(asctime)s %(name)s:%(levelname)s:%(message)s',
datefmt='%Y-%M-%d %H:%M:%S', level=logging.DEBUG)

logging.info('\n=====NEW LOG======\n') #TODO: add start screen
schedule.every(1).seconds.do(main_task)

while True:
Expand Down

0 comments on commit d14f979

Please sign in to comment.