Commit b8faa6fe authored by Titouan Soulard's avatar Titouan Soulard

Allow server to be configured

- Transform the server from Flask app to regular Python script
- Add an option  for parsing an external configuration file
parent c6e76146
......@@ -38,7 +38,6 @@ class Gakeshadeba():
entry = {
"sha512": file_sha512,
"software_url": sr,
# Should be flexible
"software_root": sr_el["software_root"],
"multiarch": sr_el["multiarch"],
"os": sr_el["os"],
......@@ -71,6 +70,7 @@ class Gakeshadeba():
def find_file_cache_entry(self, sha512):
file_name = self.file_sha512_dir.get(sha512)
if file_name:
return file_name
else:
......
import argparse
import configparser
from flask import Flask, send_from_directory
from gakeshadeba import Gakeshadeba
content_dir = "./files"
parser = argparse.ArgumentParser(
prog = "Gakeshadeba Server",
description = "Simple ShaCache and ShaDir implementation in plain Python"
)
parser.add_argument("-c", "--cfg", required=True)
argv = parser.parse_args()
config = configparser.ConfigParser()
config.read(argv.cfg)
gsha = Gakeshadeba("./files", "./sr_list.json")
gsha.set_signing_key("tmp.key")
gsha = Gakeshadeba(config["gakeshadeba"]["content_directory"], config["gakeshadeba"]["sr_list_path"])
gsha.set_signing_key(config["gakeshadeba"]["signing_key_path"])
gsha.build_file_cache()
gsha.build_sr_dir()
......@@ -20,5 +31,7 @@ def binary_cache(sha512):
if file_name is None:
return "Not found\n", 404
return send_from_directory(content_dir, file_name, as_attachment=True)
return send_from_directory(config["gakeshadeba"]["content_directory"], file_name, as_attachment=True)
app.run(host=config["server"]["host"], port=config["server"]["port"])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment