Added update base
This commit is contained in:
parent
14821e7481
commit
416dcdcd72
@ -1,12 +1,12 @@
|
|||||||
import os
|
import os
|
||||||
from flask import request
|
from flask import request
|
||||||
from flask_restful import Resource
|
from flask_restful import Resource
|
||||||
from dashmachine.version import tcmachine_version
|
from dashmachine.version import version
|
||||||
|
|
||||||
|
|
||||||
class GetVersion(Resource):
|
class GetVersion(Resource):
|
||||||
def get(self):
|
def get(self):
|
||||||
return {"Version": tcmachine_version}
|
return {"Version": version}
|
||||||
|
|
||||||
|
|
||||||
class ServerShutdown(Resource):
|
class ServerShutdown(Resource):
|
||||||
|
@ -5,6 +5,8 @@ from dashmachine.user_system.forms import UserForm
|
|||||||
from dashmachine.main.utils import read_config, row2dict
|
from dashmachine.main.utils import read_config, row2dict
|
||||||
from dashmachine.main.models import Files, TemplateApps
|
from dashmachine.main.models import Files, TemplateApps
|
||||||
from dashmachine.paths import backgrounds_images_folder, icons_images_folder
|
from dashmachine.paths import backgrounds_images_folder, icons_images_folder
|
||||||
|
from dashmachine.update import check_needed, update_dashmachine
|
||||||
|
from dashmachine.version import version
|
||||||
from dashmachine.settings_system.utils import load_files_html
|
from dashmachine.settings_system.utils import load_files_html
|
||||||
|
|
||||||
settings_system = Blueprint("settings_system", __name__)
|
settings_system = Blueprint("settings_system", __name__)
|
||||||
@ -21,12 +23,15 @@ def settings():
|
|||||||
t_apps = TemplateApps.query.all()
|
t_apps = TemplateApps.query.all()
|
||||||
for t_app in t_apps:
|
for t_app in t_apps:
|
||||||
template_apps.append(f"{t_app.name}&&{t_app.icon}")
|
template_apps.append(f"{t_app.name}&&{t_app.icon}")
|
||||||
|
update_need = check_needed()
|
||||||
return render_template(
|
return render_template(
|
||||||
"settings_system/settings.html",
|
"settings_system/settings.html",
|
||||||
config_form=config_form,
|
config_form=config_form,
|
||||||
files_html=files_html,
|
files_html=files_html,
|
||||||
user_form=user_form,
|
user_form=user_form,
|
||||||
template_apps=",".join(template_apps),
|
template_apps=",".join(template_apps),
|
||||||
|
version=version,
|
||||||
|
update_need=update_need,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -59,3 +64,9 @@ def get_app_template():
|
|||||||
if key not in ["id", "name"]:
|
if key not in ["id", "name"]:
|
||||||
template += f"{key} = {value}<br>"
|
template += f"{key} = {value}<br>"
|
||||||
return template
|
return template
|
||||||
|
|
||||||
|
|
||||||
|
@settings_system.route("/settings/update", methods=["GET"])
|
||||||
|
def update():
|
||||||
|
update_dashmachine()
|
||||||
|
return "ok"
|
||||||
|
@ -66,4 +66,14 @@ $( document ).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#update-btn").on('click', function(e) {
|
||||||
|
$.ajax({
|
||||||
|
url: $(this).attr('data-url'),
|
||||||
|
type: 'GET',
|
||||||
|
success: function(data){
|
||||||
|
M.toast({html: 'DashMachine Updated'});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
@ -253,37 +253,56 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="user" class="col s12">
|
<div id="user" class="col s12">
|
||||||
<h5>User</h5>
|
<div class="row">
|
||||||
{{ user_form.hidden_tag() }}
|
<h5>User</h5>
|
||||||
|
{{ user_form.hidden_tag() }}
|
||||||
|
|
||||||
{{ input(
|
{{ input(
|
||||||
label="Username",
|
label="Username",
|
||||||
id="user-form-username",
|
id="user-form-username",
|
||||||
size="s12",
|
size="s12",
|
||||||
form_obj=user_form.username,
|
form_obj=user_form.username,
|
||||||
val=current_user.username
|
val=current_user.username
|
||||||
) }}
|
) }}
|
||||||
|
|
||||||
{{ input(
|
{{ input(
|
||||||
label="Password",
|
label="Password",
|
||||||
id="user-form-password",
|
id="user-form-password",
|
||||||
form_obj=user_form.password,
|
form_obj=user_form.password,
|
||||||
size="s12"
|
size="s12"
|
||||||
) }}
|
) }}
|
||||||
|
|
||||||
{{ input(
|
{{ input(
|
||||||
label="Confirm Password",
|
label="Confirm Password",
|
||||||
id="user-form-confirm_password",
|
id="user-form-confirm_password",
|
||||||
form_obj=user_form.confirm_password,
|
form_obj=user_form.confirm_password,
|
||||||
required='required',
|
required='required',
|
||||||
size="s12"
|
size="s12"
|
||||||
) }}
|
) }}
|
||||||
|
|
||||||
|
{{ button(
|
||||||
|
icon="save",
|
||||||
|
float="left",
|
||||||
|
text="save"
|
||||||
|
) }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row mt-4">
|
||||||
|
<h5>DashMachine</h5>
|
||||||
|
<p class="mb-2">version: {{ version }}</p>
|
||||||
|
|
||||||
|
{% if update_needed %}
|
||||||
|
{{ button(
|
||||||
|
float="left",
|
||||||
|
id="update-btn",
|
||||||
|
icon="system_update_alt",
|
||||||
|
data={"url": url_for('settings_system.update')},
|
||||||
|
text="update available"
|
||||||
|
) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
{{ button(
|
|
||||||
icon="save",
|
|
||||||
float="left",
|
|
||||||
text="save"
|
|
||||||
) }}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -2,7 +2,32 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
from dashmachine.paths import root_folder
|
from dashmachine.paths import root_folder
|
||||||
|
|
||||||
migrate_fn = os.path.join(root_folder, 'manage_db.py db migrate')
|
|
||||||
upgrade_fn = os.path.join(root_folder, 'manage_db.py db upgrade')
|
|
||||||
|
|
||||||
def update():
|
def check_needed():
|
||||||
|
subprocess.run("git remote update", shell=True)
|
||||||
|
out = subprocess.run(
|
||||||
|
"git status -uno", stdout=subprocess.PIPE, shell=True, encoding="utf-8"
|
||||||
|
)
|
||||||
|
if str(out.stdout).find("Your branch is up to date") > -1:
|
||||||
|
needed = False
|
||||||
|
return needed
|
||||||
|
|
||||||
|
elif str(out.stdout).find("Your branch is up-to-date") > -1:
|
||||||
|
needed = False
|
||||||
|
return needed
|
||||||
|
else:
|
||||||
|
needed = True
|
||||||
|
return needed
|
||||||
|
|
||||||
|
|
||||||
|
def update_dashmachine():
|
||||||
|
|
||||||
|
subprocess.run(
|
||||||
|
"git pull origin master", stdout=subprocess.PIPE, shell=True, encoding="utf-8"
|
||||||
|
)
|
||||||
|
|
||||||
|
migrate_cmd = "python " + os.path.join(root_folder, "manage_db.py db migrate")
|
||||||
|
subprocess.run(migrate_cmd, stderr=subprocess.PIPE, shell=True, encoding="utf-8")
|
||||||
|
|
||||||
|
upgrade_cmd = "python " + os.path.join(root_folder, "manage_db.py db upgrade")
|
||||||
|
subprocess.run(upgrade_cmd, stderr=subprocess.PIPE, shell=True, encoding="utf-8")
|
||||||
|
@ -1 +1 @@
|
|||||||
tcmachine_version = "v0.0"
|
version = "v0.1"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user