Skip to content

Commit a70c0b4

Browse files
authored
Merge pull request #2390 from tynanford/master
Add create_settings_template.py - #2353
2 parents 877405e + 6884611 commit a70c0b4

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ buildNumber.properties
112112
# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
113113
!/.mvn/wrapper/maven-wrapper.jar
114114

115+
# Exclude complete settings template file if it is created
116+
phoebus-product/settings_template.ini
115117

116118
# End of https://www.gitignore.io/api/maven,eclipse
117119
/.gitignore
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import argparse
2+
import glob
3+
import zipfile
4+
import os
5+
import shutil
6+
7+
8+
def create_settings_template(product_location: str, include_comments: bool) -> None:
9+
"""
10+
Create complete list of settings for settings.ini file
11+
12+
:param product_location: Location of the product jar files to check for *preferences.properties files
13+
:param include_comments: Option to include comments for each setting in output file
14+
"""
15+
# find all jar files so we can unzip jar and find preference files
16+
jar_file_list = glob.glob(product_location + "/*.jar")
17+
18+
# temp directory to hold unzipped jar file contents (deleted at end of script)
19+
tmp_zip_dir = "./tmp-zip"
20+
21+
output_file = "settings_template.ini"
22+
out_f = open(output_file, 'w')
23+
print("Creating settings_template.ini file...")
24+
25+
out_f.write("# Complete List of Available Preference Properties (Created by create_settings_template.py)\n")
26+
27+
for jar_file in jar_file_list:
28+
if not os.path.isdir(tmp_zip_dir):
29+
os.makedirs(tmp_zip_dir)
30+
with zipfile.ZipFile(jar_file, 'r') as zip_ref:
31+
zip_ref.extractall(tmp_zip_dir)
32+
# find all *preference.properties files
33+
prop_files = glob.glob(tmp_zip_dir + "/*preferences.properties")
34+
35+
package_str = ""
36+
for prop_file in prop_files:
37+
with open(prop_file, 'r') as file:
38+
lines = file.readlines()
39+
for line in lines:
40+
line = line.strip()
41+
if line.startswith("# Package "):
42+
package_str = line[10:].strip()
43+
# print package name with number signs above and below
44+
if include_comments:
45+
out_f.write("\n{0}\n{1}\n{0}\n".format("#"*(len(line)), line))
46+
else:
47+
out_f.write("\n{0}\n{1}\n{0}\n\n".format("#"*(len(line)), line))
48+
elif "--------" in line:
49+
continue
50+
# assume equal sign means this is a property
51+
elif "=" in line:
52+
if line[0] == "#":
53+
if include_comments:
54+
out_f.write("# {}/{}\n".format(package_str, line[1:].strip()))
55+
else:
56+
out_f.write("# {}/{}\n".format(package_str, line))
57+
# a few pva properties don't have equal sign so this covers those
58+
elif line != "" and line[0] != "#":
59+
out_f.write("# {}/{}\n".format(package_str, line))
60+
else:
61+
if include_comments:
62+
out_f.write(line + "\n")
63+
64+
# remove temp directory
65+
shutil.rmtree(tmp_zip_dir)
66+
print("Creation complete")
67+
68+
69+
parser = argparse.ArgumentParser(description="Create template of settings.ini with all available settings")
70+
parser.add_argument("product", type=str, nargs='?', default="./target/lib", help="Location of product jars. Defaults to ./target/lib")
71+
parser.add_argument("-c", "--comments", action="store_true", help="Include settting comments in file")
72+
73+
args = parser.parse_args()
74+
75+
create_settings_template(args.product, args.comments)

0 commit comments

Comments
 (0)