11
11
import warnings
12
12
from datetime import datetime
13
13
import logging
14
+ import shutil
14
15
import fosslight_dependency .constant as const
15
16
from collections import defaultdict
16
17
from fosslight_util .set_log import init_log
33
34
_exclude_dir = ['node_moduels' , 'venv' ]
34
35
35
36
37
+ def get_terminal_size ():
38
+ size = shutil .get_terminal_size ()
39
+ return size .lines
40
+
41
+
42
+ def paginate_file (file_path ):
43
+ lines_per_page = get_terminal_size () - 1
44
+ with open (file_path , 'r' , encoding = 'utf8' ) as file :
45
+ lines = file .readlines ()
46
+
47
+ for i in range (0 , len (lines ), lines_per_page ):
48
+ os .system ('clear' if os .name == 'posix' else 'cls' )
49
+ print ('' .join (lines [i : i + lines_per_page ]))
50
+ if i + lines_per_page < len (lines ):
51
+ input ("Press Enter to see the next page..." )
52
+
53
+
36
54
def find_package_manager (input_dir , abs_path_to_exclude = []):
37
55
ret = True
38
56
manifest_file_name = []
@@ -227,7 +245,15 @@ def run_dependency_scanner(package_manager='', input_dir='', output_dir_file='',
227
245
graph_path = os .path .abspath (graph_path )
228
246
try :
229
247
converter = GraphConvertor (scan_item .file_items [_PKG_NAME ])
230
- converter .save (graph_path , graph_size )
248
+ growth_factor_per_node = 10
249
+ node_count_threshold = 20
250
+ node_count = len (scan_item .file_items [_PKG_NAME ])
251
+ if node_count > node_count_threshold :
252
+ new_size = tuple (x + (node_count * growth_factor_per_node ) for x in graph_size )
253
+ else :
254
+ new_size = graph_size
255
+ new_size = tuple ((((x + 99 ) // 100 ) * 100 ) for x in new_size )
256
+ converter .save (graph_path , new_size )
231
257
logger .info (f"Output graph image file: { graph_path } " )
232
258
except Exception as e :
233
259
logger .error (f'Fail to make graph image: { e } ' )
@@ -324,9 +350,9 @@ def main():
324
350
if args .graph_size :
325
351
graph_size = args .graph_size
326
352
if args .direct : # --direct option
327
- if args .direct == 'true' :
353
+ if args .direct == 'true' or args . direct == 'True' :
328
354
direct = True
329
- elif args .direct == 'false' :
355
+ elif args .direct == 'false' or args . direct == 'False' :
330
356
direct = False
331
357
if args .notice : # --notice option
332
358
try :
@@ -337,8 +363,10 @@ def main():
337
363
data_path = os .path .join (base_path , 'LICENSES' )
338
364
print (f"*** { _PKG_NAME } open source license notice ***" )
339
365
for ff in os .listdir (data_path ):
340
- f = open (os .path .join (data_path , ff ), 'r' , encoding = 'utf8' )
341
- print (f .read ())
366
+ source_file = os .path .join (data_path , ff )
367
+ destination_file = os .path .join (base_path , ff )
368
+ paginate_file (source_file )
369
+ shutil .copyfile (source_file , destination_file )
342
370
sys .exit (0 )
343
371
344
372
run_dependency_scanner (package_manager , input_dir , output_dir , pip_activate_cmd , pip_deactivate_cmd ,
0 commit comments