Skip to content

Commit 239f51a

Browse files
authored
Merge pull request #4 from fosslight/develop
Add a class for printing spinner
2 parents b75a9cc + 317db4b commit 239f51a

File tree

8 files changed

+79
-3
lines changed

8 files changed

+79
-3
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ It is a package that supports common utils used by FOSSLight Scanner.
99
2. It easily outputs csv file and excel file in OSS Report format.
1010
3. It provides a simple function to create a text file.
1111
4. It defines common constant variables.
12+
5. It provides a thread that prints the spinner.
1213

1314
[or]: http://collab.lge.com/main/x/xDHlFg
1415

@@ -84,6 +85,16 @@ logger = logging.getLogger(constant.LOGGER_NAME)
8485
logger.warning("Get a logger after init_log is called once.")
8586
```
8687

88+
### 5. Call a spinner (tests/test_timer.py)
89+
```
90+
from fosslight_util.timer_thread import TimerThread
91+
92+
93+
timer = TimerThread()
94+
timer.setDaemon(True)
95+
timer.start()
96+
```
97+
8798
## 👏 How to report issue
8899

89100
Please report any ideas or bugs to improve by creating an issue in [fosslight_util repository][cl]. Then there will be quick bug fixes and upgrades. Ideas to improve are always welcome.

requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
XlsxWriter
22
pandas
33
xlrd
4-
openpyxl
4+
openpyxl
5+
progress
6+
PyYAML

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
if __name__ == "__main__":
1414
setup(
1515
name='fosslight_util',
16-
version='1.0.2',
16+
version='1.0.3',
1717
package_dir={"": "src"},
1818
packages=find_packages(where='src'),
1919
description='FOSSLight Util',

src/fosslight_util/set_log.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import logging
77
import os
88
from pathlib import Path
9+
import pkg_resources
10+
import sys
11+
import platform
912
from . import constant as constant
1013

1114

@@ -35,3 +38,20 @@ def init_log(log_file, create_file=True):
3538
logger.propagate = False
3639

3740
return logger
41+
42+
43+
def init_log_item(main_package_name="", path_to_analyze= ""):
44+
45+
_PYTHON_VERSION = sys.version_info[0]
46+
_result_log = {
47+
"Tool Info": main_package_name,
48+
"Python version": _PYTHON_VERSION,
49+
"OS": platform.system()+" "+platform.release(),
50+
}
51+
if main_package_name != "":
52+
pkg_version = pkg_resources.get_distribution(main_package_name).version
53+
_result_log["Tool Info"] = main_package_name +" v."+pkg_version
54+
if path_to_analyze != "":
55+
_result_log["Path to analyze"] = path_to_analyze
56+
57+
return _result_log

src/fosslight_util/timer_thread.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# Copyright (c) 2021 LG Electronics Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
import threading
6+
import time
7+
from progress.spinner import Spinner
8+
9+
class TimerThread(threading.Thread):
10+
def __init__(self):
11+
threading.Thread.__init__(self, name=' Thread')
12+
13+
def run(self):
14+
spinner = Spinner('')
15+
while True:
16+
time.sleep(1)
17+
spinner.next()

tests/test_log.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22
# -*- coding: utf-8 -*-
33
# Copyright (c) 2021 LG Electronics Inc.
44
# SPDX-License-Identifier: Apache-2.0
5-
5+
import yaml
66
from fosslight_util.set_log import init_log
7+
from fosslight_util.set_log import init_log_item
78
from _print_log import print_log
89
from _print_log_with_another_logger import print_log_another_logger
910

1011
def main():
1112
logger = init_log("test_result/log_file1.txt")
1213
logger.warning("TESTING LOG - from 1st Module")
1314

15+
result_log = init_log_item("fosslight_util")
16+
_str_final_result_log = yaml.safe_dump(result_log, allow_unicode=True)
17+
logger.warning(_str_final_result_log)
18+
1419
print_log()
1520
print_log_another_logger()
1621

tests/test_timer.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# Copyright (c) 2021 LG Electronics Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
import os
6+
import time
7+
from fosslight_util.timer_thread import TimerThread
8+
9+
10+
def main():
11+
timer = TimerThread()
12+
timer.setDaemon(True)
13+
timer.start()
14+
15+
time.sleep(3)
16+
17+
18+
if __name__ == '__main__':
19+
main()

tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ commands =
2424
python tests/test_excel.py
2525
ls test_result/excel
2626
cat test_result/excel/OSS-Report.csv
27+
# Test - timer
28+
python tests/test_timer.py

0 commit comments

Comments
 (0)