@@ -93,10 +93,10 @@ def rules_pass(rules, currField=''):
93
93
94
94
return False
95
95
96
- if filters .get ('exclude' ) != None and rules_pass (filters ['exclude' ]) == True :
96
+ if bool ( filters .get ('exclude' )) and rules_pass (filters ['exclude' ]) == True :
97
97
return False
98
98
99
- if filters .get ('include' ) != None and rules_pass (filters ['include' ]) == False :
99
+ if bool ( filters .get ('include' )) and rules_pass (filters ['include' ]) == False :
100
100
return False
101
101
102
102
return True
@@ -203,7 +203,8 @@ def print_tree(tree, fields, pad="", level=0):
203
203
204
204
205
205
def print_report (files , fields , filters = {}):
206
- print ('\n ---------\n Group by : ' , fields )
206
+ print ('\n ---------\n Group by : ' , fields , '\n ---------\n ' )
207
+ print ('---------\n Filters : ' , filters , '\n ---------\n ' )
207
208
print ()
208
209
sys .stdout .flush ()
209
210
@@ -223,30 +224,58 @@ def print_report(files, fields, filters={}):
223
224
224
225
print_tree (res ['tree' ], fields )
225
226
227
+
226
228
def get_choice (choice_str , list_of_choices , default_num = None ):
227
229
choices = list (enumerate (list_of_choices , 1 ))
228
- num , choice = choices [default_num - 1 ] if default_num != None else (0 , None )
230
+ include , exclude = [], []
231
+
232
+ def parse_choice (inpt ):
233
+ user_unput = inpt .split ('!' )
234
+ index = int (user_unput [1 ]) if len (user_unput ) == 2 else int (user_unput [0 ])
235
+ if index == '' :
236
+ raise Exception ('Enter was pressed' )
237
+ if index <= len (choices ) and index > - len (choices ):
238
+ if index > 0 :
239
+ index -= 1
240
+ num , setlected_set = choices [index ]
241
+ # choice = setlected_set
242
+ if len (user_unput ) == 2 :
243
+ exclude .append (setlected_set )
244
+ else :
245
+ include .append (setlected_set )
246
+ else :
247
+ return False
248
+ return True
249
+
229
250
while True :
230
251
print (choice_str )
231
- print ("\n \t (Default value is:" , choice , ")" )
252
+ print ("\n \t (Default num is:" , default_num , ")" )
232
253
for num , name in choices :
233
254
print ("\t {}) {}" .format (num , name ))
234
255
print ("Press Enter for use default value..." )
256
+
235
257
try :
236
- index = int (input ())
237
- if index <= len (choices ) and index > - len (choices ):
238
- if index > 0 :
239
- index -= 1
240
- num , setlected_set = choices [index ]
241
- choice = setlected_set
258
+ if parse_choice (input ()) == True :
242
259
break
243
260
except :
261
+ print ("Default setting" )
262
+ if default_num != None :
263
+ parse_choice (str (default_num ))
244
264
break
245
- print ("\n Value is: " , choice )
265
+
266
+ print ("\n Values is: exclude = " , exclude , "include=" , include )
246
267
print ("\n \n " )
247
- if type (list_of_choices ) is dict and choice != None :
248
- choice = list_of_choices [choice ]
249
- return choice
268
+
269
+ def list_cases (arr ):
270
+ if type (list_of_choices ) is dict and len (arr ) > 0 :
271
+ for i , v in enumerate (arr ):
272
+ arr [i ] = list_of_choices [v ]
273
+ return arr
274
+
275
+ return {
276
+ 'include' : list_cases (include ),
277
+ 'exclude' : list_cases (exclude ),
278
+ }
250
279
251
280
252
281
if __name__ == '__main__' :
@@ -351,6 +380,9 @@ def get_choice(choice_str, list_of_choices, default_num=None):
351
380
{'uri' : r'^/(?:bio|music|song|short_story)/[^\/?#\\]+(?:\.html|\/)?$' },
352
381
{'uri' : r'^/img/[a-z\d\-\_]+\.(?:png|jpg|gif)$' },
353
382
],
383
+ 'hide bot' : [
384
+ {'ua' : r'bot|scan' },
385
+ ],
354
386
}
355
387
356
388
group_set = [
@@ -386,13 +418,12 @@ def get_choice(choice_str, list_of_choices, default_num=None):
386
418
# sys.exit(0)
387
419
388
420
# Select filters
389
- filters = get_choice ("=== Select set of exclude filters:" , site )
421
+ filters = get_choice (
422
+ "=== Select set of exclude filters (!num for include):" , site )
390
423
391
- print_report (files , groups , {
392
- 'exclude' : [
393
- skip_my_ip ,
394
- filters ,
395
- ],
424
+ print_report (files , groups ['include' ][0 ], {
425
+ 'exclude' : ([skip_my_ip ] + filters ['include' ]),
426
+ 'include' : filters ['exclude' ],
396
427
})
397
428
398
429
# Extract only important
0 commit comments