-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patharkmatrix.py
More file actions
92 lines (82 loc) · 4.69 KB
/
Copy patharkmatrix.py
File metadata and controls
92 lines (82 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
/***************************************************************************
ARK Matrix
Part of the Archaeological Recording Kit by L-P : Archaeology
http://ark.lparchaeology.com
-------------------
begin : 2016-02-29
git sha : $Format:%H$
copyright : 2016 by John Layt
email : john@layt.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
import os, sys, argparse
from src import process
parser = argparse.ArgumentParser(description='A tool to process Harris Matrix files.')
parser.add_argument("-i", "--input", help="Choose input format, optional, defaults to infile suffix", choices=['lst', 'csv'])
parser.add_argument("-o", "--output", help="Choose output format, optional, defaults to outfile suffix", choices=['none', 'gv', 'dot', 'gml', 'graphml', 'gxl', 'tgf', 'csv'])
parser.add_argument("-r", "--reduce", help="Apply a transitive reduction to the input graph", action='store_true')
parser.add_argument("-s", "--style", help="Include basic style formatting in output", action='store_true')
parser.add_argument("--site", help="Site Code for Matrix", default='')
parser.add_argument("--name", help="Name for Matrix", default='')
parser.add_argument("--sameas", help="Include Same-As relationships in output", action='store_true')
parser.add_argument("--group", help="Generate subgroup and group Matrices", action='store_true')
parser.add_argument("--orphans", help="Include orphan units in output (format dependent)", action='store_true')
parser.add_argument("--width", help="Width of node if --style is set", type=float, default=50.0)
parser.add_argument("--height", help="Height of node if --style is set", type=float, default=25.0)
parser.add_argument('infile', help="Source data file", nargs='?', type=argparse.FileType('r'), default=sys.stdin)
parser.add_argument('outfile', help="Destination data file", nargs='?', type=argparse.FileType('w'), default=sys.stdout)
parser.add_argument('subgroupfile', help="Destination subgroup data file if --group set", nargs='?', type=argparse.FileType('w'), default=sys.stdout)
parser.add_argument('groupfile', help="Destination group data file if --group set", nargs='?', type=argparse.FileType('w'), default=sys.stdout)
args = parser.parse_args()
options = vars(args)
if not options['input'] and args.infile.name != '<stdin>':
basename, suffix = os.path.splitext(args.infile.name)
options['input'] = suffix.strip('.')
if not options['input']:
options['input'] = 'csv'
options['input'] = options['input'].lower()
if not options['output'] and args.outfile.name != '<stdout>':
basename, suffix = os.path.splitext(args.outfile.name)
options['output'] = suffix.strip('.')
options['outname'] = basename
if not options['output']:
options['output'] = 'none'
options['output'] = options['output'].lower()
if args.group:
if options['output']:
options['subgroupoutput'] = options['output']
options['groupoutput'] = options['output']
else:
if args.subgroupfile.name != '<stdout>':
basename, suffix = os.path.splitext(args.subgroupfile.name)
options['subgroupoutput'] = suffix.strip('.')
if args.groupfile.name != '<stdout>':
basename, suffix = os.path.splitext(args.groupfile.name)
options['groupoutput'] = suffix.strip('.')
if 'subgroupoutput' not in options:
options['subgroupoutput'] = 'none'
if 'groupoutput' not in options:
options['groupoutput'] = 'none'
options['subgroupoutput'] = options['subgroupoutput'].lower()
options['groupoutput'] = options['groupoutput'].lower()
if 'outname' not in options:
if args.name and args.site:
options['outname'] = args.site + '_' + args.name
elif args.name:
options['outname'] = args.name
elif args.site:
options['outname'] = args.site
else:
options['outname'] = 'matrix'
process.process(args.infile, args.outfile, args.subgroupfile, args.groupfile, options)