Skip to content

Commit 1f3fc5d

Browse files
committed
Code Enhancement
1 parent f41c82c commit 1f3fc5d

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

about_code_tool/genabout.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -703,14 +703,14 @@ def main(parser, options, args):
703703
sys.exit(errno.EINVAL)
704704

705705
if copy_files_path:
706-
# code to handle tidle character
706+
# code to handle tilde character
707707
copy_files_path = os.path.abspath(expanduser(copy_files_path))
708708
if not _exists(copy_files_path):
709709
print("The project path does not exist.")
710710
sys.exit(errno.EINVAL)
711711

712712
if license_text_path:
713-
# code to handle tidle character
713+
# code to handle tilde character
714714
license_text_path = os.path.abspath(expanduser(license_text_path))
715715
if not _exists(license_text_path):
716716
print("The license text path does not exist.")
@@ -773,13 +773,12 @@ def main(parser, options, args):
773773
print('Please fix the input file and re-run the tool.')
774774
sys.exit(errno.EINVAL)
775775

776-
# Clear the log file
777-
# FIXME: we should just delete the file, not override it
778-
# or we should append to it...
779-
with open(output_path + LOG_FILENAME, 'w'):
780-
pass
776+
# Remove the previous log file if exist
777+
log_path = join(output_path, LOG_FILENAME)
778+
if exists(log_path):
779+
os.remove(log_path)
781780

782-
file_handler = logging.FileHandler(output_path + LOG_FILENAME)
781+
file_handler = logging.FileHandler(log_path)
783782
file_logger.addHandler(file_handler)
784783

785784
input_list = gen.get_input_list(input_path)

about_code_tool/genattrib.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222

2323
from __future__ import print_function
2424

25-
2625
import csv
2726
import errno
2827
import logging
2928
import optparse
29+
import os
3030
import sys
3131

32-
from os.path import exists, dirname, join, abspath, isdir, basename, expanduser
32+
from os.path import exists, dirname, join, abspath, isdir, basename, expanduser, normpath
3333

3434
from about import Collector
3535
import genabout
@@ -157,8 +157,8 @@ def main(parser, options, args):
157157
input_path, output_path, component_subset_path = args
158158

159159
# TODO: need more path normalization (normpath, expanduser)
160-
# input_path = abspath(input_path)
161-
output_path = abspath(output_path)
160+
input_path = expanduser(normpath(input_path))
161+
output_path = expanduser(normpath(output_path))
162162

163163
# Add the following to solve the
164164
# UnicodeEncodeError: 'ascii' codec can't encode character
@@ -229,11 +229,12 @@ def main(parser, options, args):
229229
print("Problem occurs. Attribution was not generated.")
230230
print(e)
231231

232-
# Clear the log file
233-
with open(join(dirname(output_path), LOG_FILENAME), 'w'):
234-
pass
232+
# Remove the previous log file if exist
233+
log_path = join(dirname(output_path), LOG_FILENAME)
234+
if exists(log_path):
235+
os.remove(log_path)
235236

236-
file_handler = logging.FileHandler(join(dirname(output_path), LOG_FILENAME))
237+
file_handler = logging.FileHandler(log_path)
237238
file_logger.addHandler(file_handler)
238239
for error_msg in errors:
239240
logger.error(error_msg)

0 commit comments

Comments
 (0)