-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepowrite
More file actions
executable file
·99 lines (73 loc) · 2.38 KB
/
repowrite
File metadata and controls
executable file
·99 lines (73 loc) · 2.38 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
__author__ = 'cbarne02'
"""
to use:
1. clone your github repository
2. point this script at the root directory of your cloned repository
3. run the script
4. when you're finished making changes, make a pull request to your github repository
should I have a commit log feature?
one to extract metadata from an ogp instance, one to augment said
metadata with location info.
one to create a directory structure, rename metadata (iso vs fgdc)
one to create/update a json object that maps metadata id to path
"""
import os
import sys
import getopt
from repo_utils import write_to_repository
def usage():
message = """'-r' or '--repository': repository path.
Defaults to current directory.
'-m' or '--metadata': path to the xml metadata file.
REQUIRED
'-i' or '--layer_id': unique id for the data layer described by the metadata.
REQUIRED
'-o' or '--overwrite': boolean 'true' or 'false' to overwrite existing metadata.
Defaults to 'false'.
"""
print message
if __name__ == "__main__":
argv = sys.argv
repo_path = None
overwrite = None
file_path = None
ow = None
try:
opts, args = getopt.getopt(argv[1:], "hr:m:o:i:", ["help", "repository=", "metadata_path=",
"overwrite=", "layer_id="])
for opt, arg in opts:
if opt in ("-h", "--help"):
usage()
sys.exit()
elif opt in("-r", "--repository"):
repo_path = arg
elif opt in("-m", "--metadata_path"):
file_path = arg
elif opt in("-o", "--overwrite"):
ow = arg
elif opt in("-i", "--layer_id"):
file_id = arg
except getopt.GetoptError:
usage()
sys.exit(2)
if file_id is None or file_path is None:
# file path and id are required
usage()
sys.exit()
#assume the cwd is the repository, if not provided
if repo_path is None:
repo_path = os.getcwd()
bool_ow = False
if ow is not None:
ow = ow.lower()
if ow in ["true", "t", "yes", "y"]:
bool_ow = True
try:
fs = ""
with open(file_path, "r") as f:
fs = f.read()
write_to_repository(file_id, fs, repo_path, bool_ow)
except Exception as e:
print e.message
sys.exit(2)