MCPcopy Index your code
hub / github.com/WebODM/WebODM / extract_odm_strings

Function extract_odm_strings

app/scripts/extract_odm_strings.py:20–76  ·  view source on GitHub ↗
(url, outfile)

Source from the content-addressed store, hash-verified

18 pass
19
20def extract_odm_strings(url, outfile):
21 strings = []
22 print("Fetching %s ..." % url)
23 res = urllib.request.urlopen(url)
24 config_file = res.read().decode('utf-8')
25 # config_file = open("test.py").read()
26
27 options = {}
28 class ArgumentParserStub(argparse.ArgumentParser):
29 def add_argument(self, *args, **kwargs):
30 argparse.ArgumentParser.add_argument(self, *args, **kwargs)
31 options[args[0]] = {}
32 for name, value in kwargs.items():
33 options[args[0]][str(name)] = str(value)
34
35 def add_mutually_exclusive_group(self):
36 return ArgumentParserStub()
37
38 # Voodoo! :)
39 # ( parse AST, extract "def config()" function, set module to only
40 # contain that function, execute module in current scope,
41 # run config function)
42 root = ast.parse(config_file)
43 new_body = []
44 for stmt in root.body:
45 # Assignments
46 if hasattr(stmt, 'targets'):
47 new_body.append(stmt)
48
49 # Functions
50 elif hasattr(stmt, 'name'):
51 new_body.append(stmt)
52
53 root.body = new_body
54 exec(compile(root, filename="<ast>", mode="exec"), globals())
55
56
57
58 config(["--project-path", "/bogus", "name"], parser=ArgumentParserStub())
59 for opt in options:
60 h = options[opt].get('help')
61 if h:
62 h = h.replace("\n", "")
63 strings.append(h)
64
65 strings = list(set(strings))
66 print("Found %s ODM strings" % len(strings))
67 if len(strings) > 0:
68 with open(outfile, "w") as f:
69 f.write("// Auto-generated with extract_odm_strings.py, do not edit!\n\n")
70
71 for s in strings:
72 f.write("_(\"%s\");\n" % s.replace("\"", "\\\""))
73
74 print("Wrote %s" % outfile)
75 else:
76 print("No strings found")
77

Callers 1

handleMethod · 0.90

Calls 8

configFunction · 0.85
ArgumentParserStubClass · 0.85
setFunction · 0.85
appendMethod · 0.80
writeMethod · 0.80
readMethod · 0.45
parseMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected