|
1 | 1 | import argparse
|
2 | 2 | import os
|
3 | 3 |
|
| 4 | + |
4 | 5 | def convert_names_to_csv(names, type, specialization="", verbose=False):
|
5 | 6 | """
|
6 | 7 | Converts a list of names to an importable archi csv string.
|
@@ -30,18 +31,20 @@ def convert_names_to_csv(names, type, specialization="", verbose=False):
|
30 | 31 |
|
31 | 32 | def read_names_from_file(filename, verbose=False):
|
32 | 33 | """
|
| 34 | + Reads the names for the elements from a given filename. |
| 35 | + Each line in the input file will correspond to a new name. |
33 | 36 |
|
34 | 37 | Args:
|
35 | 38 | filename (str): the path to the input file
|
36 | 39 | verbose (bool=False): show verbose output
|
37 | 40 |
|
38 | 41 | Returns:
|
| 42 | + list(str): the input list of names |
39 | 43 | """
|
40 | 44 | if verbose:
|
41 | 45 | print("Reading names from {0}...".format(filename))
|
42 | 46 |
|
43 | 47 | names = []
|
44 |
| - # TODO do any sanitization? |
45 | 48 | with open(filename, 'r') as fd:
|
46 | 49 | names = fd.readlines()
|
47 | 50 |
|
@@ -81,6 +84,19 @@ def write_csv_to_file(csv_string, filename, verbose=False):
|
81 | 84 |
|
82 | 85 | def sanitize_output(output_path, verbose=False):
|
83 | 86 | """
|
| 87 | + Sanitizes a given output_path and raises an error if the output path is incorrect. |
| 88 | + Note that archi expects a file titled "elements.csv" and this function wil raise an error if that is not possible. |
| 89 | + This function will adjust existing directory path to point to an elements.csv in that directory. |
| 90 | +
|
| 91 | + Args: |
| 92 | + output_path (str): the path to the output file |
| 93 | + verbose (bool=False): show verbose output |
| 94 | + |
| 95 | + Returns: |
| 96 | + str: the sanitized output path |
| 97 | +
|
| 98 | + Raises: |
| 99 | + ValueError: The output path cannot be sanitized to a valid path. |
84 | 100 | """
|
85 | 101 | if os.path.exists(output_path) and os.path.isdir(output_path):
|
86 | 102 | new_output_path = output_path + ('' if output_path.endswith('/') else '/') + 'elements.csv'
|
@@ -114,13 +130,13 @@ def initialize_parser():
|
114 | 130 | help="type of ArchiMate elements to be imported")
|
115 | 131 | parser.add_argument('input',
|
116 | 132 | help="path to the input file containing the list of names")
|
117 |
| - |
118 |
| - parser.add_argument('-o', '--output', default="elements.csv", |
119 |
| - help="path to the output file (or directory), default is \"elements.csv\"") |
120 |
| - parser.add_argument('-s', '--specialization', |
121 |
| - help="specialization for the ArchiMate elements") |
| 133 | + |
122 | 134 | parser.add_argument('-v', '--verbose', action='store_true',
|
123 | 135 | help="show verbose output")
|
| 136 | + parser.add_argument('-s', '--specialization', |
| 137 | + help="specialization for the ArchiMate elements") |
| 138 | + parser.add_argument('-o', '--output', default="elements.csv", |
| 139 | + help="path to the output file (or directory), default is \"elements.csv\"") |
124 | 140 |
|
125 | 141 | return parser
|
126 | 142 |
|
|
0 commit comments