first commit
This commit is contained in:
commit
09eebaf313
9 changed files with 299 additions and 0 deletions
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
39
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
39
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
|
@ -0,0 +1,39 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="PyAugmentAssignmentInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="PyClassicStyleClassInspection" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="PyCompatibilityInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ourVersions">
|
||||
<value>
|
||||
<list size="1">
|
||||
<item index="0" class="java.lang.String" itemvalue="3.11" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PyListCreationInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyMandatoryEncodingInspection" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="PyMethodMayBeStaticInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyMissingTypeHintsInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="PyPep8Inspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<option name="ignoredErrors">
|
||||
<list>
|
||||
<option value="E501" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<option name="ignoredErrors">
|
||||
<list>
|
||||
<option value="N806" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PyRedundantParenthesesInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyShadowingNamesInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyTypeCheckerInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyUnusedLocalInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||
</profile>
|
||||
</component>
|
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
|
@ -0,0 +1,6 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
4
.idea/misc.xml
generated
Normal file
4
.idea/misc.xml
generated
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (pywebio)" project-jdk-type="Python SDK" />
|
||||
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/pywebio.iml" filepath="$PROJECT_DIR$/.idea/pywebio.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
10
.idea/pywebio.iml
generated
Normal file
10
.idea/pywebio.iml
generated
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
217
main.py
Normal file
217
main.py
Normal file
|
@ -0,0 +1,217 @@
|
|||
###############################################
|
||||
# Imports
|
||||
###############################################
|
||||
|
||||
import pywebio
|
||||
from pywebio.output import put_text, put_table, use_scope, put_markdown, put_buttons, clear, put_info, put_error, put_html
|
||||
from pywebio.input import input, input_group, NUMBER, PASSWORD
|
||||
#import pywebio.input
|
||||
from pywebio import start_server
|
||||
from functools import partial
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
###############################################
|
||||
# Main loop
|
||||
###############################################
|
||||
|
||||
|
||||
def main(): # PyWebIO application function
|
||||
|
||||
###############################################
|
||||
# Functions
|
||||
###############################################
|
||||
|
||||
def home():
|
||||
clear(scope='add_backup')
|
||||
clear(scope='load_data')
|
||||
#use_scope('header')
|
||||
|
||||
def load_data():
|
||||
clear('load_data')
|
||||
clear('add_backup')
|
||||
|
||||
with use_scope('load_data'): # open and enter a new output: 'load_backup'
|
||||
|
||||
put_table([
|
||||
['No.','Backup Name', 'Actions'],
|
||||
[1, backup_data[0].name, put_buttons(['Backup', 'Prune'], onclick=partial(actions, 1))],
|
||||
[2, backup_data[1].name, put_buttons(['Backup', 'Prune'], onclick=partial(actions, 2))],
|
||||
[3, backup_data[2].name, put_buttons(['Backup', 'Prune'], onclick=partial(actions, 3))],
|
||||
[4, backup_data[3].name, put_buttons(['Backup', 'Prune'], onclick=partial(actions, 4))],
|
||||
[5, backup_data[4].name, put_buttons(['Backup', 'Prune'], onclick=partial(actions, 5))],
|
||||
[6, backup_data[5].name, put_buttons(['Backup', 'Prune'], onclick=partial(actions, 6))],
|
||||
[7, backup_data[6].name, put_buttons(['Backup', 'Prune'], onclick=partial(actions, 7))],
|
||||
[8, backup_data[7].name, put_buttons(['Backup', 'Prune'], onclick=partial(actions, 8))],
|
||||
])
|
||||
|
||||
def add_backup():
|
||||
with use_scope('add_backup'): # open and enter a new output: 'add_backup'
|
||||
clear('load_data')
|
||||
clear('add_backup')
|
||||
clear('control')
|
||||
clear('main_menue')
|
||||
|
||||
#put_text("You click 'add_backup' button", scope='add_backup')
|
||||
|
||||
put_text('', position=0)
|
||||
put_text('', position=0)
|
||||
put_text('* Required field', scope='add_backup', position=-2)
|
||||
|
||||
# input data
|
||||
backup = input_group("Add Backup", [
|
||||
input('Backup Name*', name='backup_name', required=True),
|
||||
input('Repository*', name='repository', required=True),
|
||||
input('Source*', name='source', required=True),
|
||||
input('Password*', name='password', type=PASSWORD, required=True),
|
||||
input('Exclude List', name='exclude_list')
|
||||
], cancelable=True)
|
||||
|
||||
with use_scope('main_menue'): # open and enter a new output: 'main_menue'
|
||||
put_buttons(['Home', 'Load data', 'Add backup'], onclick=[home, load_data, add_backup])
|
||||
if backup == None:
|
||||
clear('add_backup')
|
||||
return False
|
||||
|
||||
#print("TESTING", add_backup['backup_name'])
|
||||
|
||||
# control output
|
||||
put_table([
|
||||
['Name', 'Your input'],
|
||||
['Backup Name:', backup['backup_name']],
|
||||
['Repository:', backup['repository']],
|
||||
['Source:', backup['source']],
|
||||
['Password:', backup['password']],
|
||||
['Exclude List:', backup['exclude_list']]
|
||||
])
|
||||
|
||||
###############################################
|
||||
# Function actions
|
||||
###############################################
|
||||
|
||||
def actions(line, action):
|
||||
with use_scope('control', clear=True):
|
||||
put_text("You click %s button at line %s" % (action, line), scope='control', position=0)
|
||||
print(action)
|
||||
|
||||
match action:
|
||||
case 'Backup':
|
||||
try:
|
||||
args = ['restic',
|
||||
'-r',
|
||||
backup_data[line -1].repository,
|
||||
'backup',
|
||||
backup_data[line -1].source]
|
||||
|
||||
result = subprocess.run(args,
|
||||
input=backup_data[line -1].password,
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True)
|
||||
|
||||
except subprocess.CalledProcessError as error:
|
||||
# Process don't successful, send signal
|
||||
with use_scope('control', clear=True):
|
||||
put_error(error.stderr, scope='control')
|
||||
else:
|
||||
# Process successful, send signal
|
||||
with use_scope('control', clear=True):
|
||||
put_info(result.stdout, scope='control')
|
||||
|
||||
finally:
|
||||
pass
|
||||
|
||||
case 'Prune':
|
||||
print(action)
|
||||
|
||||
###############################################
|
||||
# Scopes
|
||||
###############################################
|
||||
|
||||
with use_scope('header'): # open and enter a new output: 'header'
|
||||
put_markdown(r""" # Restic UI
|
||||
""")
|
||||
with use_scope('main_menue'): # open and enter a new output: 'main_menue'
|
||||
put_buttons(['Home', 'Load data', 'Add backup'], onclick=[home, load_data, add_backup])
|
||||
|
||||
###############################################
|
||||
# Classes
|
||||
###############################################
|
||||
|
||||
class BackupList():
|
||||
""" I build here a class to manage the backup list
|
||||
Data is in backup_list.json """
|
||||
|
||||
#####################
|
||||
# Init
|
||||
#####################
|
||||
|
||||
def __init__(self,
|
||||
name,
|
||||
repository,
|
||||
source,
|
||||
password,
|
||||
init,
|
||||
exclude,
|
||||
rest,
|
||||
rest_domain,
|
||||
rest_port,
|
||||
rest_user,
|
||||
rest_password,
|
||||
rest_folder):
|
||||
|
||||
self.name = name
|
||||
self.repository = repository
|
||||
self.source = source
|
||||
self.password = password
|
||||
self.init = init
|
||||
self.exclude = exclude
|
||||
self.rest = rest
|
||||
self.rest_domain = rest_domain
|
||||
self.rest_port = rest_port
|
||||
self.rest_user = rest_user
|
||||
self.rest_password = rest_password
|
||||
self.rest_folder = rest_folder
|
||||
|
||||
try:
|
||||
with open('/home/frankm/.restic_ui/backup_list.json', 'r', encoding='utf-8') as f:
|
||||
# with open('backup_list.json', 'r', encoding='utf-8') as f:
|
||||
backups = json.load(f)
|
||||
|
||||
# We get the number of entries in the object backups
|
||||
# and put them in the keys_list! ['0', '1', '2', 3]
|
||||
keys_list = []
|
||||
for key in backups:
|
||||
keys_list.append(key)
|
||||
|
||||
# We create the objects backup_data and fill them with data
|
||||
backup_data = []
|
||||
for count, value in enumerate(keys_list):
|
||||
# After that we create an entry under backup_data.append etc.
|
||||
backup_data.append(BackupList(backups[keys_list[count]]['name'],
|
||||
backups[keys_list[count]]['repository'],
|
||||
backups[keys_list[count]]['source'],
|
||||
backups[keys_list[count]]['password'],
|
||||
backups[keys_list[count]]['init'],
|
||||
backups[keys_list[count]]['exclude'],
|
||||
backups[keys_list[count]]['rest'],
|
||||
backups[keys_list[count]]['rest_domain'],
|
||||
backups[keys_list[count]]['rest_port'],
|
||||
backups[keys_list[count]]['rest_user'],
|
||||
backups[keys_list[count]]['rest_password'],
|
||||
backups[keys_list[count]]['rest_folder']))
|
||||
|
||||
print("TEST",backup_data)
|
||||
|
||||
except IOError:
|
||||
print("File Error!")
|
||||
|
||||
###############################################
|
||||
# Start server (Main loop)
|
||||
###############################################
|
||||
|
||||
|
||||
start_server(main, debug=True, port=9090)
|
6
style.css
Normal file
6
style.css
Normal file
|
@ -0,0 +1,6 @@
|
|||
<style type="text/css">
|
||||
ul.horizontal{
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
</style>
|
Loading…
Add table
Reference in a new issue