1
0
mirror of https://github.com/sashacmc/photo-importer.git synced 2026-04-24 19:13:49 +02:00

Add outpath web interface option

This commit is contained in:
sashacmc
2020-01-18 02:29:06 +01:00
parent aeac6696b7
commit 76c7534eca
3 changed files with 40 additions and 15 deletions
+6
View File
@@ -1,3 +1,9 @@
photo-importer (1.0.1) stable; urgency=medium
* Add outpath web interface option
-- Alexander Bushnev <Alexander@Bushnev.ru> Fri, 17 Jan 2020 12:29:53 +0100
photo-importer (1.0.0) stable; urgency=medium
* Initial release.
+15 -12
View File
@@ -146,8 +146,8 @@ class PhotoImporterHandler(http.server.BaseHTTPRequestHandler):
self.__ok_response(result)
def __import_start(self, in_path):
self.server.import_start(in_path)
def __import_start(self, in_path, out_path):
self.server.import_start(in_path, out_path)
return True
def __import_stop(self, dev):
@@ -159,22 +159,21 @@ class PhotoImporterHandler(http.server.BaseHTTPRequestHandler):
def __import_request(self, params):
try:
action = params['a'][0]
except Exception as ex:
self.__bad_request_response(str(ex))
logging.exception(ex)
return
try:
in_path = params['p'][0]
except Exception as ex:
self.__bad_request_response(str(ex))
logging.exception(ex)
return
try:
out_path = params['o'][0]
except Exception as ex:
out_path = self.server.out_path()
result = None
if action == 'start':
result = self.__import_start(in_path)
result = self.__import_start(in_path, out_path)
self.__ok_response(result)
elif action == 'stop':
result = self.__import_stop(in_path)
@@ -187,8 +186,12 @@ class PhotoImporterHandler(http.server.BaseHTTPRequestHandler):
return
def __sysinfo_request(self, params):
try:
path = params['p'][0]
except Exception as ex:
path = self.server.out_path()
res = {}
du = psutil.disk_usage(self.server.out_path())
du = psutil.disk_usage(path)
mem = psutil.virtual_memory()
res['disk_size'] = self.__bytes_to_gbytes(du.total)
res['disk_usage'] = du.percent
@@ -303,7 +306,7 @@ class PhotoImporterServer(http.server.HTTPServer):
def fixed_in_path(self):
return self.__fixed_in_path
def import_start(self, in_path):
def import_start(self, in_path, out_path):
logging.info('import_start: %s', in_path)
if in_path in self.__importers and in_path != self.fixed_in_path():
raise Exception('Already started')
@@ -311,7 +314,7 @@ class PhotoImporterServer(http.server.HTTPServer):
self.__importers[in_path] = importer.Importer(
self.__cfg,
in_path,
self.out_path(),
out_path,
False)
self.__importers[in_path].start()
+19 -3
View File
@@ -14,7 +14,8 @@
<div>
<div class="table table-striped table-bordered" id="devTable"/>
</div>
<div id="sysInfo"/>
<div id="storagePath"></div>
<div id="sysInfo"></div>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
@@ -106,8 +107,12 @@
function updateSysInfo()
{
var argpath = "";
if (g_outpath) {
argpath = "?p=" + g_outpath;
}
$.ajax({
url: "sysinfo",
url: "sysinfo" + argpath,
cache: false,
success: function(json) {
var data = eval(json);
@@ -129,8 +134,12 @@
});
} else
if (cmd == "start") {
var argpath = "";
if (g_outpath) {
argpath = "&o=" + g_outpath;
}
$.ajax({
url: "import?a=" + cmd + "&p=" + dev,
url: "import?a=" + cmd + "&p=" + dev + argpath,
type: "POST",
success: function() {
update()
@@ -141,6 +150,13 @@
function init()
{
var urlParams = new URLSearchParams(window.location.search);
g_outpath = urlParams.get('outpath');
if (g_outpath) {
$("#storagePath").html("<p class=\"text-monospace\">Storage: " + g_outpath + "</p>");
}
update()
updateSysInfo()
}