@@ -68,27 +68,16 @@ def setup_logging_helm() -> bool:
68
68
return True
69
69
70
70
71
- def copy_network_defaults (directory : Path ):
72
- """Create the project structure for a warnet project"""
73
- (directory / WAR_NETWORK_DIR / DEFAULT_NETWORK ).mkdir (parents = True , exist_ok = True )
74
- target_network_defaults = directory / WAR_NETWORK_DIR / DEFAULT_NETWORK / DEFAULTS_FILE
75
- target_network_example = directory / WAR_NETWORK_DIR / DEFAULT_NETWORK / NETWORK_FILE
76
- shutil .copy2 (WAR_NETWORK_FILES / DEFAULT_NETWORK / DEFAULTS_FILE , target_network_defaults )
77
- shutil .copy2 (WAR_NETWORK_FILES / DEFAULT_NETWORK / NETWORK_FILE , target_network_example )
78
-
79
-
80
- def copy_scenario_defaults (directory : Path ):
81
- """Create the project structure for a warnet project"""
82
- target_dir = directory / WAR_SCENARIOS_DIR
71
+ def copy_defaults (directory : Path , target_subdir : str , source_path : Path , exclude_list : list [str ]):
72
+ """Generic function to copy default files and directories"""
73
+ target_dir = directory / target_subdir
83
74
target_dir .mkdir (parents = True , exist_ok = True )
84
- print (f"Creating scenarios directory: { target_dir } " )
85
-
86
- scenarios_path = WAR_SCENARIOS_FILES .joinpath ()
75
+ print (f"Creating directory: { target_dir } " )
87
76
88
77
def should_copy (item : Path ) -> bool :
89
- return item .name not in [ "__init__.py" , "__pycache__" , "commander.py" ]
78
+ return item .name not in exclude_list
90
79
91
- for item in scenarios_path .iterdir ():
80
+ for item in source_path .iterdir ():
92
81
if should_copy (item ):
93
82
if item .is_file ():
94
83
shutil .copy2 (item , target_dir )
@@ -97,7 +86,15 @@ def should_copy(item: Path) -> bool:
97
86
shutil .copytree (item , target_dir / item .name , dirs_exist_ok = True )
98
87
print (f"Copied directory: { item .name } " )
99
88
100
- print (f"Finished copying scenario files to { target_dir } " )
89
+ print (f"Finished copying files to { target_dir } " )
90
+
91
+ def copy_network_defaults (directory : Path ):
92
+ """Create the project structure for a warnet project's network"""
93
+ copy_defaults (directory , WAR_NETWORK_DIR , WAR_NETWORK_FILES .joinpath (), [])
94
+
95
+ def copy_scenario_defaults (directory : Path ):
96
+ """Create the project structure for a warnet project's scenarios"""
97
+ copy_defaults (directory , WAR_SCENARIOS_DIR , WAR_SCENARIOS_FILES .joinpath (), ["__init__.py" , "__pycache__" , "commander.py" ])
101
98
102
99
103
100
@network .command ()
@@ -179,7 +176,7 @@ def _connected():
179
176
for peer in peerinfo :
180
177
if peer ["connection_type" ] == "manual" :
181
178
manuals += 1
182
- # Even if more edges are specifed , bitcoind only allows
179
+ # Even if more edges are specified , bitcoind only allows
183
180
# 8 manual outbound connections
184
181
185
182
print ("manual " + str (manuals ))
0 commit comments