mirror of
https://github.com/Team4388/RidgeScout.git
synced 2026-06-08 16:28:00 -06:00
Start working on the server
This commit is contained in:
@@ -26,7 +26,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
// Class to synchronise data over FTP.
|
||||
// This is now deprsicated
|
||||
public class FTPSync extends Thread {
|
||||
public static final String remoteBasePath = "/RidgeScout/";
|
||||
public static final String timestampsFilename = "timestamps";
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import os
|
||||
import json
|
||||
from bottle import Bottle, run, get, static_file, response
|
||||
|
||||
from utils import *
|
||||
|
||||
app = Bottle()
|
||||
|
||||
file_metadata = {}
|
||||
|
||||
def save_metadata():
|
||||
global file_metadata
|
||||
write(METADATA_FILE, json.dumps(file_metadata))
|
||||
|
||||
def load_metadata():
|
||||
global file_metadata
|
||||
data = read(METADATA_FILE)
|
||||
if data is not None:
|
||||
file_metadata = json.loads(data)
|
||||
|
||||
# @app.route('/')
|
||||
# def list():
|
||||
# response.content_type = 'application/json'
|
||||
# return json.dumps(ls(DATA_ROOT))
|
||||
|
||||
|
||||
@app.route('/api/metadata')
|
||||
def metadata():
|
||||
global file_metadata
|
||||
load_metadata()
|
||||
response.content_type = 'application/json'
|
||||
return json.dumps(file_metadata)
|
||||
|
||||
|
||||
|
||||
# @app.route('/<filename>')
|
||||
# def hello(filename):
|
||||
# return static_file(DATA_ROOT, filename)
|
||||
|
||||
if __name__ == '__main__':
|
||||
mkdir(DATA_ROOT)
|
||||
app.run(host='localhost', port=8080)
|
||||
@@ -0,0 +1 @@
|
||||
bottle
|
||||
@@ -0,0 +1,30 @@
|
||||
import os
|
||||
|
||||
ROOT = os.path.dirname(__file__)
|
||||
METADATA_FILE = os.path.join(ROOT, 'metadata.json')
|
||||
DATA_ROOT = os.path.join(os.path.dirname(__file__), 'data')
|
||||
|
||||
def mkdir(path):
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
|
||||
def ls(path):
|
||||
try:
|
||||
return os.listdir(path)
|
||||
except:
|
||||
return []
|
||||
|
||||
def read(path):
|
||||
if not os.path.exists(path):
|
||||
return None
|
||||
try:
|
||||
with open(path) as f:
|
||||
return f.read()
|
||||
except:
|
||||
return None
|
||||
|
||||
def write(path, data):
|
||||
if not os.path.exists(path):
|
||||
with open(path, mode='a'): pass
|
||||
with open(path, 'w') as f:
|
||||
f.write(data)
|
||||
Reference in New Issue
Block a user