Commit 495988a1 authored by Oleg Borisenko's avatar Oleg Borisenko
Browse files

Files tab is finished

parent 4a6171b4
......@@ -43,6 +43,11 @@
</div>
</form>
<div><p3>Отфильтровано {{ files_total }} файлов суммарным размером {{ files_total_size }} Гбайт</p3></div>
<div>
{% for tape_status in tapes_status %}
<p>{{ tape_status }}</p>
{% endfor %}
</div>
<div class="pagination">
{% if page != 0 %}
<a href="{{ request.current_route_path(_query=dict(request.params.dicts[0], page = 0)) }}">к началу</a>
......
......@@ -15,6 +15,7 @@ from sqlalchemy.sql import and_
import logging
log = logging.getLogger(__name__)
def tape_stats(request):
finalized_tapes = request.dbsession.query(models.Tape).filter(
models.Tape.state == models.TapeState.finalized).count()
......@@ -31,6 +32,7 @@ def tape_stats(request):
"ready_for_export_tapes": ready_for_export_tapes}
return tape_status
@view_config(route_name='home', renderer='tapebackup:templates/home.jinja2')
def home_route(request):
try:
......@@ -101,6 +103,7 @@ def status_route(request):
"empty_mailslot_slots": empty_mailslot_slots,
"ready_for_export": ready_for_export, "ready_for_import": ready_for_import}
@view_config(route_name='targets', renderer='tapebackup:templates/targets.jinja2')
def targets_route(request):
try:
......@@ -113,6 +116,7 @@ def targets_route(request):
return {"backup_targets": backup_targets, "restore_targets": restore_targets}
@view_config(route_name='add_backup_target_post')
def add_backup_target_post(request):
try:
......@@ -138,6 +142,7 @@ def add_backup_target_post(request):
('color', 'red')))
return HTTPFound(location=next_url)
@view_config(route_name='add_restore_target_post')
def add_restore_target_post(request):
try:
......@@ -160,6 +165,7 @@ def add_restore_target_post(request):
('color', 'red')))
return HTTPFound(location=next_url)
@view_config(route_name='tapes', renderer='tapebackup:templates/tapes.jinja2')
def tapes_route(request):
try:
......@@ -170,13 +176,8 @@ def tapes_route(request):
return {"known_tapes": tapes}
@view_config(route_name="files", renderer='tapebackup:templates/files.jinja2')
def files_route(request):
limit = request.GET.get('limit') or 100
limit = int(limit)
page = request.GET.get('page') or 0
page = int(page)
pagination_pages_to_show = 10
def file_filter(request):
files = request.dbsession.query(models.FileToBackup).filter(models.FileToBackup.is_file == True)
labnum_seq = request.GET.get('labnum')
......@@ -215,6 +216,42 @@ def files_route(request):
if copied_at_time_after:
files = files.filter(models.FileToBackup.copied_at_time >= copied_at_time_after)
tapes_involved = files.join(models.Tape, models.Tape.label == models.FileToBackup.tape_label)\
.distinct(models.Tape.label).all()
tapes_inside_list = []
tapes_inside = []
tapes_outside = []
tapes_involved_labels = [tape.tape_label for tape in tapes_involved]
tapes_list = request.dbsession.query(models.Tape).filter(models.Tape.label.in_(tapes_involved_labels)).all()
for tape in tapes_list:
if tape.location == 'Inside tape library':
tapes_inside_list.append(tape.label)
else:
tapes_outside.append("Кассета с номером %s находится в %s и файлы с нее **НЕ БУДУТ** восстановлены" % tape.label, tape.location)
tapes_inside = ["Кассеты с номерами %s находятся внутри ленточной библиотеки и могут быть использованы для восстановления." \
% " ".join(str(x) for x in tapes_inside_list)]
tapes_status = tapes_inside + tapes_outside
return files, tapes_status
@view_config(route_name="files", renderer='tapebackup:templates/files.jinja2')
def files_route(request):
limit = request.GET.get('limit') or 100
limit = int(limit)
page = request.GET.get('page') or 0
page = int(page)
pagination_pages_to_show = 10
file_mtime_before = request.GET.get('file_mtime_before') or "9999-01-01"
file_mtime_after = request.GET.get('file_mtime_after') or "1837-01-01"
copied_at_time_before = request.GET.get('copied_at_time_before') or "9999-01-01"
copied_at_time_after = request.GET.get('copied_at_time_after') or "1837-01-01"
files, tapes_status = file_filter(request)
files_total = files.count()
if files.with_entities(func.sum(models.FileToBackup.fsize)).scalar():
files_total_size = round(files.with_entities(func.sum(models.FileToBackup.fsize)).scalar() / 1024**3, 2)
......@@ -242,7 +279,9 @@ def files_route(request):
"copied_at_time_before": copied_at_time_before,
"copied_at_time_after": copied_at_time_after,
"backup_targets": backup_targets,
"restore_targets": restore_targets}
"restore_targets": restore_targets,
"tapes_status": tapes_status}
@view_config(route_name="add_to_restore_queue")
def add_to_restore_queue(request):
......@@ -250,29 +289,21 @@ def add_to_restore_queue(request):
restore_target = request.GET.get('restore_target')
if not restore_target:
raise HTTPException("No restore target selected")
restore_target_object = request.dbsession.query(models.RestoreTarget).filter(models.RestoreTarget.unique_label == restore_target).one()
files = request.dbsession.query(models.FileToBackup).filter(models.FileToBackup.is_file == True)
labnum_seq = request.GET.get('labnum')
if labnum_seq:
labnum_list = labnum_seq.split(',')
patterns = []
for labnum in labnum_list:
pattern = "%{}%".format(labnum.strip())
patterns.append(pattern)
files = files.filter(or_(*[models.FileToBackup.labnum.like(name) for name in patterns]))
restore_target_object = request.dbsession.query(models.RestoreTarget).filter(models.RestoreTarget.unique_label
== restore_target).one()
files = file_filter(request)
backup_target = request.GET.get('backup_target')
if backup_target:
files = files.filter(models.FileToBackup.target_unique_label == backup_target)
files = files.all()
files, tapes_status = files.all()
for f in files:
restore_queue_object = models.RestoreHistory(
restore_target = restore_target_object,
file_to_restore = f,
status = False
restore_target=restore_target_object,
file_to_restore=f,
status=False
)
request.dbsession.add(f)
request.dbsession.add(restore_queue_object)
next_url = request.route_url('files',
_query=(('result', 'Files added to restore queue'),
('color', 'green')))
......@@ -281,4 +312,4 @@ def add_to_restore_queue(request):
next_url = request.route_url('files',
_query=(('result', e.detail),
('color', 'red')))
return HTTPFound(location=next_url)
\ No newline at end of file
return HTTPFound(location=next_url)
Supports Markdown
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