()
| 181 | |
| 182 | |
| 183 | def main(): # <4> |
| 184 | # create the parser |
| 185 | parser = argparse.ArgumentParser( |
| 186 | description='Convert an ISIS .mst or .iso file to a JSON array') |
| 187 | |
| 188 | # add the arguments |
| 189 | parser.add_argument( |
| 190 | 'file_name', metavar='INPUT.(mst|iso)', |
| 191 | help='.mst or .iso file to read') |
| 192 | parser.add_argument( |
| 193 | '-o', '--out', type=argparse.FileType('w'), default=sys.stdout, |
| 194 | metavar='OUTPUT.json', |
| 195 | help='the file where the JSON output should be written' |
| 196 | ' (default: write to stdout)') |
| 197 | parser.add_argument( |
| 198 | '-c', '--couch', action='store_true', |
| 199 | help='output array within a "docs" item in a JSON document' |
| 200 | ' for bulk insert to CouchDB via POST to db/_bulk_docs') |
| 201 | parser.add_argument( |
| 202 | '-m', '--mongo', action='store_true', |
| 203 | help='output individual records as separate JSON dictionaries, one' |
| 204 | ' per line for bulk insert to MongoDB via mongoimport utility') |
| 205 | parser.add_argument( |
| 206 | '-t', '--type', type=int, metavar='ISIS_JSON_TYPE', default=1, |
| 207 | help='ISIS-JSON type, sets field structure: 1=string, 2=alist,' |
| 208 | ' 3=dict (default=1)') |
| 209 | parser.add_argument( |
| 210 | '-q', '--qty', type=int, default=DEFAULT_QTY, |
| 211 | help='maximum quantity of records to read (default=ALL)') |
| 212 | parser.add_argument( |
| 213 | '-s', '--skip', type=int, default=0, |
| 214 | help='records to skip from start of .mst (default=0)') |
| 215 | parser.add_argument( |
| 216 | '-i', '--id', type=int, metavar='TAG_NUMBER', default=0, |
| 217 | help='generate an "_id" from the given unique TAG field number' |
| 218 | ' for each record') |
| 219 | parser.add_argument( |
| 220 | '-u', '--uuid', action='store_true', |
| 221 | help='generate an "_id" with a random UUID for each record') |
| 222 | parser.add_argument( |
| 223 | '-p', '--prefix', type=str, metavar='PREFIX', default='', |
| 224 | help='concatenate prefix to every numeric field tag' |
| 225 | ' (ex. 99 becomes "v99")') |
| 226 | parser.add_argument( |
| 227 | '-n', '--mfn', action='store_true', |
| 228 | help='generate an "_id" from the MFN of each record' |
| 229 | ' (available only for .mst input)') |
| 230 | parser.add_argument( |
| 231 | '-k', '--constant', type=str, metavar='TAG:VALUE', default='', |
| 232 | help='Include a constant tag:value in every record (ex. -k type:AS)') |
| 233 | |
| 234 | ''' |
| 235 | # TODO: implement this to export large quantities of records to CouchDB |
| 236 | parser.add_argument( |
| 237 | '-r', '--repeat', type=int, default=1, |
| 238 | help='repeat operation, saving multiple JSON files' |
| 239 | ' (default=1, use -r 0 to repeat until end of input)') |
| 240 | ''' |
no test coverage detected