forked from PocketNC/Settings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateINI.py
More file actions
executable file
·99 lines (78 loc) · 2.99 KB
/
generateINI.py
File metadata and controls
executable file
·99 lines (78 loc) · 2.99 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
93
94
95
96
97
98
99
#!/usr/bin/python
from copy import deepcopy
import os
import re
import pprint
import sys
from version import getVersion
import subprocess
POCKETNC_DIRECTORY = "/home/pocketnc/pocketnc"
VERSION = getVersion()
sys.path.insert(0, os.path.join(POCKETNC_DIRECTORY, "Rockhopper"));
from ini import read_ini_data, merge_ini_data, write_ini_data, append_ini_data
INI_FILE = os.path.join(POCKETNC_DIRECTORY, "Settings/PocketNC.ini")
INI_DEFAULT_FILE = os.path.join(POCKETNC_DIRECTORY, "Settings/versions/%s/PocketNC.ini" % VERSION)
CALIBRATION_OVERLAY_FILE = os.path.join(POCKETNC_DIRECTORY, "Settings/CalibrationOverlay.inc")
FEATURES_DIR = os.path.join(POCKETNC_DIRECTORY, "Settings/features")
if __name__ == "__main__":
defaults = read_ini_data(INI_DEFAULT_FILE)
if os.path.isfile(CALIBRATION_OVERLAY_FILE):
overlay = read_ini_data(CALIBRATION_OVERLAY_FILE)
else:
overlay = { 'parameters': [],
'sections': {} }
merged = merge_ini_data(defaults, overlay)
features = set()
# Auto detected features
for feature in os.listdir(FEATURES_DIR):
feature_path = os.path.join(FEATURES_DIR, feature)
detect_path = os.path.join(feature_path, "detect")
if os.path.isfile(detect_path):
detected = subprocess.check_output(detect_path).strip()
if detected == "1":
print "Detected feature, %s" % feature
features.add(feature)
# Manually enabled/disabled features
for param in overlay['parameters']:
section = param['values']['section']
name = param['values']['name']
value = param['values']['value']
if section == "POCKETNC_FEATURES":
feature = name.lower()
if value == "1":
features.add(feature)
elif value == "0" and feature in features:
features.remove(feature)
for feature in features:
dir = os.path.join(FEATURES_DIR, feature)
feature_overlay_path = os.path.join(dir, "overlay.inc")
feature_append_path = os.path.join(dir, "append.inc")
feature_startup_path = os.path.join(dir, "startup")
if os.path.isfile(feature_startup_path):
# executed first so overlay.inc and/or append.inc could be generated by the script
subprocess.check_output(feature_startup_path);
if os.path.isfile(feature_overlay_path):
feature_overlay = read_ini_data(feature_overlay_path)
merged = merge_ini_data(merged, feature_overlay)
if os.path.isfile(feature_append_path):
feature_append = read_ini_data(feature_append_path)
merged = append_ini_data(merged, feature_append)
merged = merge_ini_data(merged, {
'parameters': [
{
'values': {
'section': 'POCKETNC_FEATURES',
'name': feature.upper(),
'value': "1",
'comment': '',
'help': '',
'default': ''
}
}
],
'sections': {
'POCKETNC_FEATURES': { 'comment': '', 'help': '' }
}
});
merged = merge_ini_data(merged, overlay)
write_ini_data(merged, INI_FILE);