Skip to content

Commit

Permalink
Merge pull request #4 from fosslight/develop
Browse files Browse the repository at this point in the history
Add a class for printing spinner
  • Loading branch information
soimkim authored Apr 29, 2021
2 parents b75a9cc + 317db4b commit 239f51a
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 3 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ It is a package that supports common utils used by FOSSLight Scanner.
2. It easily outputs csv file and excel file in OSS Report format.
3. It provides a simple function to create a text file.
4. It defines common constant variables.
5. It provides a thread that prints the spinner.

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

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

### 5. Call a spinner (tests/test_timer.py)
```
from fosslight_util.timer_thread import TimerThread
timer = TimerThread()
timer.setDaemon(True)
timer.start()
```

## 👏 How to report issue

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.
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
XlsxWriter
pandas
xlrd
openpyxl
openpyxl
progress
PyYAML
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
if __name__ == "__main__":
setup(
name='fosslight_util',
version='1.0.2',
version='1.0.3',
package_dir={"": "src"},
packages=find_packages(where='src'),
description='FOSSLight Util',
Expand Down
20 changes: 20 additions & 0 deletions src/fosslight_util/set_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import logging
import os
from pathlib import Path
import pkg_resources
import sys
import platform
from . import constant as constant


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

return logger


def init_log_item(main_package_name="", path_to_analyze= ""):

_PYTHON_VERSION = sys.version_info[0]
_result_log = {
"Tool Info": main_package_name,
"Python version": _PYTHON_VERSION,
"OS": platform.system()+" "+platform.release(),
}
if main_package_name != "":
pkg_version = pkg_resources.get_distribution(main_package_name).version
_result_log["Tool Info"] = main_package_name +" v."+pkg_version
if path_to_analyze != "":
_result_log["Path to analyze"] = path_to_analyze

return _result_log
17 changes: 17 additions & 0 deletions src/fosslight_util/timer_thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
import threading
import time
from progress.spinner import Spinner

class TimerThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self, name=' Thread')

def run(self):
spinner = Spinner('')
while True:
time.sleep(1)
spinner.next()
7 changes: 6 additions & 1 deletion tests/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0

import yaml
from fosslight_util.set_log import init_log
from fosslight_util.set_log import init_log_item
from _print_log import print_log
from _print_log_with_another_logger import print_log_another_logger

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

result_log = init_log_item("fosslight_util")
_str_final_result_log = yaml.safe_dump(result_log, allow_unicode=True)
logger.warning(_str_final_result_log)

print_log()
print_log_another_logger()

Expand Down
19 changes: 19 additions & 0 deletions tests/test_timer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
import os
import time
from fosslight_util.timer_thread import TimerThread


def main():
timer = TimerThread()
timer.setDaemon(True)
timer.start()

time.sleep(3)


if __name__ == '__main__':
main()
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ commands =
python tests/test_excel.py
ls test_result/excel
cat test_result/excel/OSS-Report.csv
# Test - timer
python tests/test_timer.py

0 comments on commit 239f51a

Please sign in to comment.