<commit_before>#!/usr/bin/env python

# flopbox Server
#
# Handles file sync
#
# Run this in a different directory than client.py:
# python server.py
#
# Author(s): <NAME> (and maybe <NAME>)

import os
import json
from hashlib import sha1

from flask import Flask, request, redirect, url_for
from werkzeug import secure_filename

# Configuration
UPLOAD_FOLDER = os.path.abspath('.') + '/server/uploads/'

app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER


@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'GET':
        return 'GET request'
    if request.method == 'POST':
        return 'POST request'


@app.route('/download/<filename>', methods=['GET'])
def download(filename):
    pass


@app.route('/upload/', methods=['POST'])
def upload():
    if request.method == 'POST':
        file = request.files['file']
        if file:
            filename = secure_filename(file.filename)
            filename = file.filename
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            return "Upload complete."
        return "There was a problem with the file upload requested."


@app.route('/file_list/', methods=['GET'])
def file_list():
    files = _list_files()
    return json.dumps(files)


@app.route('/sync/<filename>', methods=['GET'])
def sync(filename):
    with open(filename, 'rb') as f:
        return f.read()


@app.route('/delete/<filename>', methods=['GET'])
def delete(filename):
    try:
        os.remove('./uploads/'+filename)
    finally:
        return 0


# TODO: This throws an error and doesn't return the list
# currently making initial syncing fail!
def _list_files():
    """
    Return a list containing all non-hidden files in the current directory.

    Ignores directories.
    """
    files = [file for file in next(os.walk('./uploads'))[2]
             if not file[0] == '.']
    return files


if __name__ == "__main__":
    file_dict = {}
    app.debug = True
    app.run()<commit_msg>Fix path issues with server, deleting works<commit_after>#!/usr/bin/env python

# flopbox Server
#
# Handles file sync
#
# Run this in a different directory than client.py:
# python server.py
#
# Author(s): <NAME> (and maybe <NAME>)

import os
import json
from hashlib import sha1

from flask import Flask, request, redirect, url_for
from werkzeug import secure_filename

# Configuration
UPLOAD_FOLDER = os.path.abspath('.') + '/server/uploads/'

app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER


@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'GET':
        return 'GET request'
    if request.method == 'POST':
        return 'POST request'


@app.route('/download/<filename>', methods=['GET'])
def download(filename):
    pass


@app.route('/upload/', methods=['POST'])
def upload():
    if request.method == 'POST':
        file = request.files['file']
        if file:
            filename = secure_filename(file.filename)
            filename = file.filename
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            return "Upload complete."
        return "There was a problem with the file upload requested."


@app.route('/file_list/', methods=['GET'])
def file_list():
    files = _list_files()
    return json.dumps(files)


@app.route('/sync/<filename>', methods=['GET'])
def sync(filename):
    with open(filename, 'rb') as f:
        return f.read()


@app.route('/delete/<filename>', methods=['GET'])
def delete(filename):
    try:
        os.remove(os.path.join(app.config['UPLOAD_FOLDER'], filename))
    finally:
        return "Done"


# TODO: This throws an error and doesn't return the list
# currently making initial syncing fail!
def _list_files():
    """
    Return a list containing all non-hidden files in the current directory.

    Ignores directories.
    """
    files = [file for file in next(os.walk(app.config['UPLOAD_FOLDER']))[2]
             if not file[0] == '.']
    return files


if __name__ == "__main__":
    file_dict = {}
    app.debug = True
    app.run()
{'fraction_non_alphanumeric': 0.1470227885322225, 'fraction_numerical': 0.0017152658662092624, 'mean_word_length': 3.203913491246138, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5239616', 'n_tokens_mistral': 1283, 'n_tokens_neox': 1282, 'n_words': 360}