Commit e7574e87 authored by schmittu's avatar schmittu 🍺
Browse files

some improvements for delete command

parent 165165b9
......@@ -104,9 +104,10 @@ def _setup_session(print_err):
def _print_signals(q, max_rows, print_ok):
num_signals = q.count()
print_ok("- deletion affects {} signals".format(num_signals))
print_ok("- deletion affects {} signal(s)".format(num_signals))
if not num_signals:
return
rows = [dbo.resolved_columns() for dbo in itertools.islice(q, max_rows)]
header = SignalDbo.resolved_column_names()
table = format_table(header, rows)
......@@ -114,17 +115,10 @@ def _print_signals(q, max_rows, print_ok):
header, delim, *rows = table.split("\n")
print_ok(" " + header)
print_ok(" " + delim)
if len(rows) > max_rows:
n_start = max_rows // 2
n_end = max_rows - n_start
n_skipped = num_signals - max_rows + 1
rows = (
rows[:n_start]
+ ["... skipped {} signals ...".format(n_skipped)]
+ rows[-n_end:]
)
for row in rows:
print_ok(" " + row)
if num_signals > max_rows:
print_ok(" ... skipped {} signals".format(num_signals - max_rows))
print_ok("")
......@@ -202,7 +196,7 @@ def _delete_source(
return 0
_delete_signals(
session, SourceDbo, SourceDbo.source_id == source.source_id, print_ok
session, SourceDbo, SignalDbo.source_id == source.source_id, print_ok
)
for averaging in source.averaging:
session.delete(averaging)
......@@ -265,7 +259,7 @@ def _delete_site(
# delete in right order:
for picture in site.pictures:
session.delete(picture)
_delete_signals(session, SiteDbo, SiteDbo.site_id == site.site_id, print_ok)
_delete_signals(session, SiteDbo, SignalDbo.site_id == site.site_id, print_ok)
session.delete(site)
_remove_yaml_including_folders(yaml_path, print_ok, print_err)
......@@ -307,7 +301,7 @@ def _delete_parameter(
_delete_signals(
session,
ParameterDbo,
ParameterDbo.parameter_id == parameter.parameter_id,
SignalDbo.parameter_id == parameter.parameter_id,
print_ok,
)
session.delete(parameter)
......
......@@ -2,6 +2,7 @@
# encoding: utf-8
from __future__ import absolute_import, division, print_function
import atexit
import importlib
import json
# Copyright © 2018 Uwe Schmitt <uwe.schmitt@id.ethz.ch>
......@@ -61,9 +62,12 @@ class DataPoolHttpServer:
def run_http_server_in_background(config_http_server, print_ok):
port = config_http_server.port
server = DataPoolHttpServer(port)
print_ok("- start background http server on port {}".format(port))
server.start()
yield
print_ok("- stop http server")
server.stop()
print_ok("- stopped http server")
......@@ -10,13 +10,12 @@ import time
from os.path import exists, join, relpath
from .errors import DataPoolIOError, InvalidLandingZone, InvalidOperationError
from .instance.landing_zone_structure import (
lock_file,
ordered_fnmatch_patterns_for_update,
raw_file_pattern_for_script,
scripts_pattern,
)
from .utils import copy, here, hexdigest_file, iter_to_list, list_folder_recursive
from .instance.landing_zone_structure import (lock_file,
ordered_fnmatch_patterns_for_update,
raw_file_pattern_for_script,
scripts_pattern)
from .utils import (copy, here, hexdigest_file, iter_to_list,
list_folder_recursive)
def disable_write(path):
......
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