job folders, selection
This commit is contained in:
+49
-7
@@ -15,6 +15,9 @@ app = Flask(__name__, static_folder='static', template_folder='templates')
|
||||
running_processes = {}
|
||||
process_logs = {}
|
||||
|
||||
# Global var
|
||||
latest_path = "/data/latest"
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
"""Main index page with script execution buttons"""
|
||||
@@ -31,12 +34,12 @@ def index():
|
||||
}
|
||||
|
||||
# Get list of files
|
||||
counties = os.listdir('/data/latest')
|
||||
data_files = {}
|
||||
for county in counties:
|
||||
files = os.listdir('/data/latest/'+county)
|
||||
data_files[county] = files
|
||||
# data_files.append(county)
|
||||
if os.path.exists(latest_path):
|
||||
for countyFolder in os.listdir(latest_path):
|
||||
files = os.listdir('/data/latest/'+countyFolder)
|
||||
data_files[countyFolder] = files
|
||||
# data_files.append(countyFolder)
|
||||
|
||||
return render_template('index.html',
|
||||
script_map=script_map,
|
||||
@@ -52,7 +55,7 @@ def map_viewer():
|
||||
def get_script_map():
|
||||
"""Get the map of available scripts and their commands"""
|
||||
return {
|
||||
'ls': 'ls -alr /data',
|
||||
'ls': 'ls -al /data',
|
||||
'make-new-latest': 'cd /data && NEWDIR=$(date +%y%m%d) && mkdir -p $NEWDIR/lake $NEWDIR/sumter && ln -sfn $NEWDIR latest',
|
||||
# todo: make a clean-old-data script
|
||||
'download-county-addresses': {
|
||||
@@ -112,10 +115,24 @@ def run_script():
|
||||
data = request.json
|
||||
script_name = data.get('script')
|
||||
county = data.get('county', '')
|
||||
force_download = data.get('forceDownload', False)
|
||||
|
||||
if not script_name:
|
||||
return jsonify({'error': 'No script specified'}), 400
|
||||
|
||||
# Check if /data/latest exists and is a symlink, not a regular directory
|
||||
# Skip this check for make-new-latest, ls
|
||||
skip_check_scripts = ['make-new-latest', 'ls']
|
||||
if script_name not in skip_check_scripts:
|
||||
latest_path = '/data/latest'
|
||||
if os.path.exists(latest_path) or os.path.islink(latest_path):
|
||||
# Check if it's a directory but NOT a symlink
|
||||
if os.path.isdir(latest_path) and not os.path.islink(latest_path):
|
||||
return jsonify({'error': '/data/latest is a directory, not a symlink. Please run "Make New Latest" first.'}), 400
|
||||
else:
|
||||
# /data/latest doesn't exist at all
|
||||
return jsonify({'error': '/data/latest does not exist. Please run "Make New Latest" first.'}), 400
|
||||
|
||||
script_map = get_script_map()
|
||||
|
||||
if script_name not in script_map:
|
||||
@@ -138,7 +155,11 @@ def run_script():
|
||||
if isinstance(cmd_config, str):
|
||||
cmd = ['bash', '-c', cmd_config]
|
||||
else:
|
||||
cmd = cmd_config
|
||||
cmd = list(cmd_config) # Make a copy to avoid modifying the original
|
||||
|
||||
# Add --force-download flag for diff-addresses if requested
|
||||
if script_name == 'diff-addresses' and force_download and isinstance(cmd, list):
|
||||
cmd.append('--force-download')
|
||||
else:
|
||||
return jsonify({'error': 'Invalid script configuration'}), 400
|
||||
|
||||
@@ -189,6 +210,27 @@ def job_status(job_id):
|
||||
'logs': logs
|
||||
})
|
||||
|
||||
@app.route('/api/cancel-job', methods=['POST'])
|
||||
def cancel_job():
|
||||
"""Cancel a running job"""
|
||||
data = request.json
|
||||
job_id = data.get('job_id')
|
||||
|
||||
if not job_id:
|
||||
return jsonify({'error': 'No job ID specified'}), 400
|
||||
|
||||
if job_id not in running_processes:
|
||||
return jsonify({'error': 'Job not found or already completed'}), 404
|
||||
|
||||
try:
|
||||
process = running_processes[job_id]
|
||||
process.terminate()
|
||||
process_logs[job_id].append('\n[Job cancelled by user]')
|
||||
del running_processes[job_id]
|
||||
return jsonify({'success': True})
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
@app.route('/api/list-files')
|
||||
def list_files():
|
||||
"""List available GeoJSON files"""
|
||||
|
||||
Reference in New Issue
Block a user