-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodified_app.py
More file actions
153 lines (139 loc) · 5.52 KB
/
Copy pathmodified_app.py
File metadata and controls
153 lines (139 loc) · 5.52 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
from flask import Flask, render_template, request, jsonify, redirect, url_for
import os
import xml.etree.ElementTree as ET
import xml.dom.minidom as minidom
import glob
import re
import logging
# Configure logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
app = Flask(__name__)
# Path to Elite Dangerous bindings folder
BINDINGS_PATH = r"C:\Users\ian\AppData\Local\Frontier Developments\Elite Dangerous\Options\Bindings"
@app.route('/')
def index():
"""Main page that lists all binding files"""
logger.debug(f"Starting index route, checking path: {BINDINGS_PATH}")
try:
# Check if directory exists
if not os.path.exists(BINDINGS_PATH):
logger.error(f"Bindings path does not exist: {BINDINGS_PATH}")
return f"""
<html>
<body>
<h1>Error: Bindings directory not found</h1>
<p>The configured directory does not exist: {BINDINGS_PATH}</p>
</body>
</html>
"""
# Get binding files directly
binding_files = []
try:
binding_files = [os.path.basename(f) for f in glob.glob(os.path.join(BINDINGS_PATH, "*.binds"))]
logger.debug(f"Found {len(binding_files)} binding files: {binding_files}")
except Exception as e:
logger.exception("Error getting binding files")
return f"""
<html>
<body>
<h1>Error getting binding files</h1>
<p>Exception: {str(e)}</p>
</body>
</html>
"""
# Return inline HTML directly instead of using templates
files_html = ""
for file in binding_files:
files_html += f"<li><a href='/binding/{file}'>{file}</a></li>"
return f"""
<html>
<head>
<title>Elite Dangerous Bindings Manager</title>
<style>
body {{ font-family: Arial, sans-serif; background-color: #131822; color: #e4f0ff; }}
.container {{ max-width: 1200px; margin: 0 auto; padding: 20px; }}
header {{ background-color: #000; padding: 10px 20px; }}
h1 {{ color: #ff7100; }}
.main-content {{ display: flex; }}
.sidebar {{ width: 300px; background-color: rgba(0,0,0,0.3); padding: 20px; }}
.file-list {{ list-style: none; padding: 0; }}
.file-list li {{ margin-bottom: 8px; }}
.file-list a {{ display: block; padding: 8px; background-color: rgba(0,162,255,0.1);
color: #e4f0ff; text-decoration: none; border-radius: 3px; }}
.file-list a:hover {{ background-color: rgba(0,162,255,0.3); }}
</style>
</head>
<body>
<header>
<h1>Elite Dangerous Bindings Manager</h1>
</header>
<div class="container">
<div class="main-content">
<div class="sidebar">
<h2>Binding Files</h2>
<ul class="file-list">
{files_html if binding_files else "<li>No binding files found</li>"}
</ul>
</div>
<div class="content">
<h2>Welcome to Elite Dangerous Bindings Manager</h2>
<p>Select a binding file from the list to view and manage it.</p>
</div>
</div>
</div>
</body>
</html>
"""
except Exception as e:
logger.exception("Unexpected error in index route")
return f"""
<html>
<body>
<h1>Unexpected Error</h1>
<p>{str(e)}</p>
</body>
</html>
"""
@app.route('/binding/<filename>')
def view_binding(filename):
"""Simple view for a specific binding file"""
try:
filepath = os.path.join(BINDINGS_PATH, filename)
# Check if file exists
if not os.path.exists(filepath):
return f"<h1>Error: File {filename} not found</h1>"
# Read file content
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
# Return a simple view of the content
return f"""
<html>
<head>
<title>{filename} - Elite Dangerous Bindings Manager</title>
<style>
body {{ font-family: Arial, sans-serif; background-color: #131822; color: #e4f0ff; }}
.container {{ max-width: 1200px; margin: 0 auto; padding: 20px; }}
header {{ background-color: #000; padding: 10px 20px; }}
h1 {{ color: #ff7100; }}
pre {{ background-color: rgba(0,0,0,0.3); padding: 15px; overflow-x: auto; }}
.back-link {{ display: inline-block; margin-bottom: 20px; color: #00a2ff; }}
</style>
</head>
<body>
<header>
<h1>Elite Dangerous Bindings Manager</h1>
</header>
<div class="container">
<a href="/" class="back-link">← Back to List</a>
<h2>{filename}</h2>
<pre>{content}</pre>
</div>
</body>
</html>
"""
except Exception as e:
logger.exception(f"Error viewing binding {filename}")
return f"<h1>Error viewing binding</h1><p>{str(e)}</p>"
if __name__ == '__main__':
app.run(debug=True, port=5003)