Skip to content

Commit 028607c

Browse files
committed
finished writing documentation
1 parent 03e33e4 commit 028607c

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# archi-import
22
```
3-
usage: archi-import [-h] [-o OUTPUT] [-s SPECIALIZATION] [-v] type input
3+
usage: archi-import [-h] [-v] [-s SPECIALIZATION] [-o OUTPUT] type input
44
55
Create an archi import csv file given a list of names
66
@@ -10,12 +10,12 @@ positional arguments:
1010
1111
options:
1212
-h, --help show this help message and exit
13+
-v, --verbose show verbose output
14+
-s SPECIALIZATION, --specialization SPECIALIZATION
15+
specialization for the ArchiMate elements
1316
-o OUTPUT, --output OUTPUT
1417
path to the output file (or directory), default is
1518
"elements.csv"
16-
-s SPECIALIZATION, --specialization SPECIALIZATION
17-
specialization for the ArchiMate elements
18-
-v, --verbose show verbose output
1919
2020
See also https://github.com/Frostielocks/archi-import
21-
```
21+
```

archi-import.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import argparse
22
import os
33

4+
45
def convert_names_to_csv(names, type, specialization="", verbose=False):
56
"""
67
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):
3031

3132
def read_names_from_file(filename, verbose=False):
3233
"""
34+
Reads the names for the elements from a given filename.
35+
Each line in the input file will correspond to a new name.
3336
3437
Args:
3538
filename (str): the path to the input file
3639
verbose (bool=False): show verbose output
3740
3841
Returns:
42+
list(str): the input list of names
3943
"""
4044
if verbose:
4145
print("Reading names from {0}...".format(filename))
4246

4347
names = []
44-
# TODO do any sanitization?
4548
with open(filename, 'r') as fd:
4649
names = fd.readlines()
4750

@@ -81,6 +84,19 @@ def write_csv_to_file(csv_string, filename, verbose=False):
8184

8285
def sanitize_output(output_path, verbose=False):
8386
"""
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.
84100
"""
85101
if os.path.exists(output_path) and os.path.isdir(output_path):
86102
new_output_path = output_path + ('' if output_path.endswith('/') else '/') + 'elements.csv'
@@ -114,13 +130,13 @@ def initialize_parser():
114130
help="type of ArchiMate elements to be imported")
115131
parser.add_argument('input',
116132
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+
122134
parser.add_argument('-v', '--verbose', action='store_true',
123135
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\"")
124140

125141
return parser
126142

0 commit comments

Comments
 (0)