-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
72 lines (53 loc) · 2.26 KB
/
app.py
File metadata and controls
72 lines (53 loc) · 2.26 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
import os
from flask import Flask, render_template, request
from flask_socketio import SocketIO, emit
from core.extractor import ProjectExtractor
app = Flask(__name__)
app.config["SECRET_KEY"] = "your-very-secret-key!"
socketio = SocketIO(app)
@app.route("/")
def index():
return render_template("index.html")
@socketio.on("connect")
def handle_connect():
print("Client connected:", request.sid)
@socketio.on("disconnect")
def handle_disconnect():
print("Client disconnected:", request.sid)
@socketio.on("start_extraction")
def handle_extraction_request(data):
project_path = data.get("path")
ignore_patterns = data.get("ignores")
include_paths = data.get("includes", "")
max_size_kb = data.get("max_size", 1024)
ignore_comments = data.get("ignore_comments", False)
external_files = data.get("external_files", [])
sid = request.sid
print(f"[{sid}] Received extraction request for path: {project_path}")
# It's now valid to have an empty project_path if external_files are provided
if not project_path and not external_files:
emit("extraction_complete", {"error": "Please provide a project root directory or at least one external file."})
return
if project_path and not os.path.isdir(project_path):
emit("extraction_complete", {"error": f"Invalid directory path: '{project_path}'. Please provide a valid path."})
return
try:
emit("update_status", {"message": "Initializing extractor..."})
extractor = ProjectExtractor(
root_path=project_path,
ignore_patterns_str=ignore_patterns,
include_only_paths_str=include_paths,
max_file_size_kb=int(max_size_kb),
ignore_comments=ignore_comments,
external_files_data=external_files,
)
emit("update_status", {"message": "Scanning project files and generating markdown..."})
markdown_output = extractor.extract()
print(f"[{sid}] Extraction successful. Sending markdown to client.")
emit("extraction_complete", {"markdown": markdown_output})
except Exception as e:
print(f"[{sid}] An error occurred during extraction: {e}")
emit("extraction_complete", {"error": f"An unexpected error occurred: {str(e)}"})
if __name__ == "__main__":
print("Starting Flask server with Socket.IO...")
socketio.run(app, debug=True, allow_unsafe_werkzeug=True)