Skip to content

Commit cae0067

Browse files
committed
Fix issues with logging and blacklist files
1 parent a81d59b commit cae0067

File tree

4 files changed

+51
-24
lines changed

4 files changed

+51
-24
lines changed

command_line.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -899,10 +899,13 @@ def make_output_dirs(self, write_json=True):
899899

900900
output_blacklist = os.path.basename(self.output_dir())
901901

902+
blacklist_vals = re.split(r'\\n?,?\n?', blacklist_setting.value)
903+
whitelist_vals = re.split(r'\\n?,?\n?', whitelist_setting.value)
904+
902905
self.file_tree.init(self.project_dir(),
903-
blacklist=(blacklist_setting.value.split('\n') +
906+
blacklist=(blacklist_vals +
904907
['*'+output_blacklist+'*']),
905-
whitelist=whitelist_setting.value.split('\n'))
908+
whitelist=whitelist_vals)
906909

907910
self.copy_files_to_project_folder()
908911

@@ -1537,7 +1540,7 @@ def get_arguments(command_base, args=None):
15371540
'to export to.'))
15381541

15391542
if args:
1540-
return parse.parse_args(args)
1543+
return parser.parse_args(args)
15411544

15421545
return parser.parse_args()
15431546

@@ -1601,19 +1604,12 @@ def setup_logging(args, command_base):
16011604
if args.verbose:
16021605
logging.basicConfig(
16031606
stream=sys.stdout,
1604-
format=("%(levelname) -10s %(module)s.py: "
1605-
"%(lineno)s %(funcName)s - %(message)s"),
1606-
level=logging.DEBUG
1607-
)
1608-
else:
1609-
# Log to the logfile in config.py
1610-
logging.basicConfig(
1611-
filename=config.LOG_FILENAME,
1612-
format=("%(levelname) -10s %(asctime)s %(module)s.py: "
1613-
"%(lineno)s %(funcName)s - %(message)s"),
1607+
format=("%(levelname) -6s %(module)s.py %(lineno)s: "
1608+
"%(message)s"),
16141609
level=logging.DEBUG
16151610
)
16161611

1612+
16171613
config.logger = logging.getLogger('CMD Logger')
16181614
config.handler = lh.RotatingFileHandler(config.LOG_FILENAME,
16191615
maxBytes=100000,

config.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,6 @@ def is_installed():
9292

9393
LOG_FILENAME = utils.get_data_file_path(ERROR_LOG_FILE)
9494

95-
if __name__ != '__main__':
96-
logging.basicConfig(
97-
filename=LOG_FILENAME,
98-
format=("%(levelname) -10s %(asctime)s %(module)s.py: "
99-
"%(lineno)s %(funcName)s - %(message)s"),
100-
level=logging.DEBUG
101-
)
102-
10395
logger = logging.getLogger(__name__)
10496

10597
## Custom except hook to log all errors ----------------------

main.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import os
2525
import glob
2626
import sys
27+
import re
2728
import logging
2829
import platform
2930

@@ -988,11 +989,13 @@ def load_project(self, directory, readonly=False):
988989
self.open_export_button.setEnabled(True)
989990

990991
blacklist_setting = self.get_setting('blacklist')
992+
whitelist_setting = self.get_setting('whitelist')
991993

992994
output_blacklist = os.path.basename(self.output_dir())
993995

994996
self.tree_browser.init(directory,
995-
blacklist=(blacklist_setting.value.split('\n') +
997+
whitelist=re.split('\n?,?', whitelist_setting.value),
998+
blacklist=(re.split('\n?,?', blacklist_setting.value) +
996999
['*'+output_blacklist+'*']))
9971000

9981001
self.update_json = True
@@ -1260,12 +1263,12 @@ def create_blacklist_layout(self, blacklist_layout):
12601263
def blacklist_changed(self, text, blacklist_setting):
12611264
new_val = text.toPlainText()
12621265
output_blacklist = os.path.basename(self.output_dir())
1263-
self.tree_browser.refresh(blacklist=(new_val.split('\n') +
1266+
self.tree_browser.refresh(blacklist=(re.split('\n?,?', new_val) +
12641267
['*'+output_blacklist+'*']))
12651268

12661269
def whitelist_changed(self, text, whitelist_setting):
12671270
new_val = text.toPlainText()
1268-
self.tree_browser.refresh(whitelist=new_val.split('\n'))
1271+
self.tree_browser.refresh(whitelist=re.split('\n?,?', new_val))
12691272

12701273
@property
12711274
def used_project_files(self):

util_classes.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import zipfile
77
import tarfile
88
import time
9+
import logging
10+
from pprint import pformat
911

1012
import config
1113
import utils
@@ -40,6 +42,8 @@ def __init__(self, directory=None,
4042
def init(self, directory=None,
4143
whitelist=None, blacklist=None):
4244

45+
self.logger = logging.getLogger(__name__)
46+
4347
if directory:
4448
self.directory = directory + os.sep
4549
else:
@@ -104,12 +108,32 @@ def add_to_cache(self, *args):
104108
if self.cache:
105109
self.walkcache[self.directory].append(args)
106110

111+
def is_in_skipped(self, skipped, path):
112+
temp = path
113+
114+
while temp:
115+
if temp in skipped:
116+
return True
117+
if temp == os.path.dirname(temp):
118+
return False
119+
temp = os.path.dirname(temp)
120+
return False
121+
107122
def generate_files(self):
108123
if self.directory is None:
109124
return
110125

126+
self.logger.debug('Blacklist pattern:')
127+
self.logger.debug(pformat(self.blacklist))
128+
self.logger.debug('')
129+
self.logger.debug('Whitelist pattern:')
130+
self.logger.debug(pformat(self.whitelist))
131+
self.logger.debug('')
132+
111133
self.init_cache()
112134

135+
skipped_files = set()
136+
113137
for root, dirs, files in self.walk(self.directory):
114138
self.add_to_cache(root, dirs, files)
115139

@@ -119,15 +143,27 @@ def generate_files(self):
119143
path = os.path.join(proj_path, directory)
120144

121145
if self.determine_skip(path):
146+
if not self.is_in_skipped(skipped_files, path):
147+
self.logger.debug('Skipping dir: %s', path)
148+
skipped_files.add(path)
122149
continue
150+
else:
151+
if self.is_in_skipped(skipped_files, path):
152+
self.logger.debug('Keeping dir: %s', path)
123153

124154
self.dirs.append(path)
125155

126156
for file in files:
127157
path = os.path.join(proj_path, file)
128158

129159
if self.determine_skip(path):
160+
if not self.is_in_skipped(skipped_files, path):
161+
self.logger.debug('Skipping file: %s', path)
162+
skipped_files.add(path)
130163
continue
164+
else:
165+
if self.is_in_skipped(skipped_files, path):
166+
self.logger.debug('Keeping file: %s', path)
131167

132168
self.files.append(path)
133169

0 commit comments

Comments
 (0)