Skip to content

Commit

Permalink
0.0.5 release
Browse files Browse the repository at this point in the history
  • Loading branch information
s-m-e committed Jul 24, 2020
2 parents 9098760 + 3e95552 commit df2cea5
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 27 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changes

## 0.0.5 (2020-07-24)

- FEATURE: Version shown in GUI
- FEATURE: Version exposed through `--version` option on command line
- FEATURE: While `{zpool}{/{prefix}}` is included in all operations by default, this can be deactivated by setting the new `include_root` configuration option to `no`, see #14.
- FIX: If a remote host is not up, provide a proper error and fail gracefully, see #15.

## 0.0.4 (2020-07-22)

- FEATURE: Improved labels in wizard GUI
Expand Down
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@
)
import os

from abgleich import __version__

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# SETUP
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

# Package version
__version__ = "0.0.4"

# List all versions of Python which are supported
python_minor_min = 6
python_minor_max = 8
Expand Down
6 changes: 6 additions & 0 deletions src/abgleich/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@
</LICENSE_BLOCK>
"""

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# META
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

__version__ = "0.0.5"
14 changes: 12 additions & 2 deletions src/abgleich/cli/_main_.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@

import importlib
import os
import sys

import click

from .. import __version__

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# ROUTINES
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand All @@ -54,9 +57,16 @@ def _add_commands(ctx):
continue


@click.group()
def cli():
@click.group(invoke_without_command=True)
@click.option("--version", is_flag=True)
def cli(version):
"""abgleich, zfs sync tool"""

if not version:
return

print(__version__)
sys.exit()


_add_commands(cli)
7 changes: 7 additions & 0 deletions src/abgleich/cli/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

import click
import sys

from ..core.config import Config
from ..core.i18n import t
from ..core.lib import is_host_up
from ..core.zpool import Zpool

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand All @@ -46,6 +48,11 @@ def backup(configfile):

config = Config.from_fd(configfile)

for side in ("source", "target"):
if not is_host_up(side, config):
print(f'{t("host is not up"):s}: {side:s}')
sys.exit(1)

source_zpool = Zpool.from_config("source", config=config)
target_zpool = Zpool.from_config("target", config=config)

Expand Down
7 changes: 7 additions & 0 deletions src/abgleich/cli/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

import time
import sys

import click

from ..core.config import Config
from ..core.i18n import t
from ..core.io import humanize_size
from ..core.lib import is_host_up
from ..core.zpool import Zpool

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand All @@ -49,6 +51,11 @@ def cleanup(configfile):

config = Config.from_fd(configfile)

for side in ("source", "target"):
if not is_host_up(side, config):
print(f'{t("host is not up"):s}: {side:s}')
sys.exit(1)

source_zpool = Zpool.from_config("source", config=config)
target_zpool = Zpool.from_config("target", config=config)
available_before = Zpool.available("source", config=config)
Expand Down
8 changes: 8 additions & 0 deletions src/abgleich/cli/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

import click
import sys

from ..core.config import Config
from ..core.i18n import t
from ..core.lib import is_host_up
from ..core.zpool import Zpool

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand All @@ -45,6 +48,11 @@ def compare(configfile):

config = Config.from_fd(configfile)

for side in ("source", "target"):
if not is_host_up(side, config):
print(f'{t("host is not up"):s}: {side:s}')
sys.exit(1)

source_zpool = Zpool.from_config("source", config=config)
target_zpool = Zpool.from_config("target", config=config)

Expand Down
10 changes: 9 additions & 1 deletion src/abgleich/cli/snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

import click
import sys

from ..core.config import Config
from ..core.i18n import t
from ..core.lib import is_host_up
from ..core.zpool import Zpool

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand All @@ -44,7 +46,13 @@
@click.argument("configfile", type=click.File("r", encoding="utf-8"))
def snap(configfile):

zpool = Zpool.from_config("source", config=Config.from_fd(configfile))
config = Config.from_fd(configfile)

if not is_host_up("source", config):
print(f'{t("host is not up"):s}: source')
sys.exit(1)

zpool = Zpool.from_config("source", config=config)
transactions = zpool.get_snapshot_transactions()

if len(transactions) == 0:
Expand Down
11 changes: 10 additions & 1 deletion src/abgleich/cli/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

import click
import sys

from ..core.config import Config
from ..core.i18n import t
from ..core.lib import is_host_up
from ..core.zpool import Zpool

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand All @@ -44,5 +47,11 @@
@click.argument("side", default="source", type=str)
def tree(configfile, side):

zpool = Zpool.from_config(side, config=Config.from_fd(configfile))
config = Config.from_fd(configfile)

if not is_host_up("source", config):
print(f'{t("host is not up"):s}: source')
sys.exit(1)

zpool = Zpool.from_config(side, config=config)
zpool.print_table()
7 changes: 6 additions & 1 deletion src/abgleich/core/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ def __str__(self) -> str:

return " ".join([item.replace(" ", "\\ ") for item in self._cmd])

def run(self):
def run(
self, returncode: bool = False
) -> typing.Union[typing.Tuple[str, str], typing.Tuple[str, str, int]]:

proc = subprocess.Popen(
self.cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE
Expand All @@ -59,6 +61,9 @@ def run(self):
status = not bool(proc.returncode)
output, errors = output.decode("utf-8"), errors.decode("utf-8")

if returncode:
return output, errors, int(proc.returncode)

if not status or len(errors.strip()) > 0:
raise SystemError("command failed", str(self), output, errors)

Expand Down
5 changes: 2 additions & 3 deletions src/abgleich/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ def get(

if isinstance(key, str):
return self._properties.get(
key,
Property(key, None, None) if default is None else default,
)
key, Property(key, None, None) if default is None else default,
)

assert isinstance(key, int) or isinstance(key, slice)

Expand Down
4 changes: 1 addition & 3 deletions src/abgleich/core/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ def _load(self):
def _dump(self):

with open(self._path, "w") as f:
f.write(
yaml.dump(self.copy(), Dumper=Dumper, allow_unicode=True, indent=4)
)
f.write(yaml.dump(self.copy(), Dumper=Dumper, allow_unicode=True, indent=4))


# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand Down
15 changes: 15 additions & 0 deletions src/abgleich/core/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,26 @@

import typeguard

from .abc import ConfigABC
from .command import Command

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# ROUTINES
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


@typeguard.typechecked
def is_host_up(side: str, config: ConfigABC) -> bool:

assert side in ("source", "target")
if config[side]["host"] == "localhost":
return True

_, _, returncode = Command.on_side(["exit"], side, config).run(returncode=True)
assert returncode in (0, 255)
return returncode == 0


@typeguard.typechecked
def join(*args: str) -> str:

Expand Down
28 changes: 16 additions & 12 deletions src/abgleich/core/zpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,10 @@ def _get_snapshot_transactions_from_dataset(

if dataset.subname in self._config["ignore"]:
return
if dataset.get("mountpoint").value is None and dataset['type'].value == 'filesystem':
if (
dataset.get("mountpoint").value is None
and dataset["type"].value == "filesystem"
):
return
if not dataset.changed:
return
Expand Down Expand Up @@ -358,18 +361,10 @@ def available(side: str, config: ConfigABC,) -> int:
@classmethod
def from_config(cls, side: str, config: ConfigABC,) -> ZpoolABC:

root_dataset = root(config[side]["zpool"], config[side]["prefix"])

output, _ = Command.on_side(
[
"zfs",
"get",
"all",
"-r",
"-H",
"-p",
root(config[side]["zpool"], config[side]["prefix"]),
],
side,
config,
["zfs", "get", "all", "-r", "-H", "-p", root_dataset,], side, config,
).run()
output = [
line.split("\t") for line in output.split("\n") if len(line.strip()) > 0
Expand All @@ -378,6 +373,15 @@ def from_config(cls, side: str, config: ConfigABC,) -> ZpoolABC:
for line_list in output:
entities[line_list[0]].append(line_list[1:])

if not config.get("include_root", True):
entities.pop(root_dataset)
for name in [
snapshot
for snapshot in entities.keys()
if snapshot.startswith(f"{root_dataset:s}@")
]:
entities.pop(name)

datasets = [
Dataset.from_entities(
name,
Expand Down
3 changes: 2 additions & 1 deletion src/abgleich/gui/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from ..core.transaction import TransactionList
from ..core.i18n import t
from ..core.zpool import Zpool
from .. import __version__

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# CLASS
Expand All @@ -56,7 +57,7 @@ def __init__(self, config: ConfigABC):
self.setWindowIcon(
QIcon(os.path.join(os.path.dirname(__file__), "..", "share", "icon.svg"))
)
self.setWindowTitle(t("abgleich wizard"))
self.setWindowTitle(f'{t("abgleich wizard"):s} {__version__:s}')

self._ui["button_cancel"].setEnabled(False)
self._ui["button_continue"].setEnabled(False)
Expand Down
2 changes: 2 additions & 0 deletions src/abgleich/share/translations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ dataset_subname:
de_SE: Datensatz-Namensfragment
de: Name des Datensatzes
en: Name of dataset
host is not up:
de: Computer ist nicht erreichbar
nothing to do:
de: nichts zu tun
snapshot:
Expand Down

0 comments on commit df2cea5

Please sign in to comment.