def versions(namespace: "file namespace", filename: "filename"): """ Show available versions for a specific file """ loop = asyncio.get_event_loop() settings.init_settings() storage = get_storage(settings.BACKEND, settings.BACKEND_OPTIONS) result = loop.run_until_complete( storage.versions(namespace=namespace, filename=filename)) print("Avaible version(s) for this file:") [print(v) for v in result]
def serve(host: "Web api host" = "localhost", port: "Listen port" = 8080): from bygfiles.server import get_app loop = asyncio.get_event_loop() settings.init_settings() storage = get_storage(settings.BACKEND, settings.BACKEND_OPTIONS) app = get_app(storage) import webbrowser webbrowser.open(f"http://{host}:{port}") app.run(host=host, port=port)
def search(namespace: "file namespace", filename: "filename", revision="latest"): """ Search for an entry """ loop = asyncio.get_event_loop() settings.init_settings() storage = get_storage(settings.BACKEND, settings.BACKEND_OPTIONS) result = loop.run_until_complete( storage.search(namespace=namespace, filename=filename, version=revision)) print(f"""url: {result['url']} version: {result['version']}""")
def delete( namespace: "Namespace to store", filename: "File name to delete", revision: "File version", ): """ Delete file from storage """ loop = asyncio.get_event_loop() settings.init_settings() storage = get_storage(settings.BACKEND, settings.BACKEND_OPTIONS) print("Delete in progress...") loop.run_until_complete( storage.delete(namespace=namespace, filename=filename, version=revision)) print("Deleted!")
def store( path: "file path to upload", namespace: "Namespace to store", filename: "File name to store", revision: "File version", ): """ Store or update file in storage """ loop = asyncio.get_event_loop() settings.init_settings() storage = get_storage(settings.BACKEND, settings.BACKEND_OPTIONS) with open(path, "rb") as fin: print("Storage in progress...") loop.run_until_complete( storage.store(stream=fin, namespace=namespace, filename=filename, version=revision)) print("Stored!")