Skip to content

Commit ed2d574

Browse files
code: fix typos and grammar
1 parent cf52940 commit ed2d574

File tree

11 files changed

+45
-45
lines changed

11 files changed

+45
-45
lines changed

src/borg_import/borg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55

66
def get_borg_archives(repository):
7-
"""Get all archive metadata discovered in the Borg repository."""
8-
# Get list of archives with their timestamps
7+
"""Return metadata for all archives discovered in the Borg repository."""
8+
# Get a list of archives with their timestamps
99
borg_cmdline = ["borg", "list", "--format", "{name}{TAB}{time}{NL}", repository]
1010
output = subprocess.check_output(borg_cmdline).decode()
1111

src/borg_import/helpers/discover.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
def discover(root, depth):
66
"""
7-
recurse starting from <root> path and yield relative dir paths with wanted <depth>.
7+
Recurse from the given root path and yield relative directory paths at the specified depth.
88
"""
99

1010
def _discover(root, current_dir, current_depth, wanted_depth):
@@ -23,6 +23,7 @@ def _discover(root, current_dir, current_depth, wanted_depth):
2323

2424

2525
def parser(rel_path, regex):
26+
"""Parse rel_path with regex and return a dict of named groups, or None if no match."""
2627
m = re.match(regex, rel_path)
2728
if m:
2829
return m.groupdict()

src/borg_import/helpers/names.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33

44
def make_name(*args, dt_format="%Y-%m-%dT%H:%M:%S"):
55
"""
6-
assemble borg archive names from components.
6+
Assemble Borg archive names from components.
77
8-
args can be anything that converts to str, plus:
8+
Arguments can be anything that converts to str, plus:
99
1010
- bytes objects, which are safely decoded
1111
- datetime objects, which are formatted using dt_format
1212
13-
invalid chars are replaced or removed, so the resulting archive name
13+
Invalid characters are replaced or removed, so the resulting archive name
1414
should be valid.
1515
16-
E.g.:
16+
Examples:
1717
make_name(b'hostname', b'üser', 1)
1818
-> 'hostname-üser-1'
1919
@@ -28,12 +28,12 @@ def make_name(*args, dt_format="%Y-%m-%dT%H:%M:%S"):
2828
s = arg.strftime(dt_format)
2929
else:
3030
s = str(arg)
31-
# we don't want to have blanks for practical shell-usage reasons:
31+
# Avoid spaces for practical shell-usage reasons:
3232
s = s.replace(" ", "_")
33-
# the slash is not allowed in archive names
33+
# A slash is not allowed in archive names
3434
# (archive name = FUSE directory name)
3535
s = s.replace("/", "!")
36-
# :: is repo::archive separator, not allowed in archive names
36+
# "::" is the repo::archive separator, not allowed in archive names
3737
s = s.replace("::", ":")
3838
components.append(s)
3939
return "-".join(components)

src/borg_import/helpers/testsuite/test_names.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
def test_make_name():
7-
# str (some with invalid/unwanted chars)
7+
# str (some with invalid/unwanted characters)
88
assert make_name("backup name") == "backup_name"
99
assert make_name("backup/name") == "backup!name"
1010
assert make_name("backup::name") == "backup:name"

src/borg_import/helpers/testsuite/test_timestamps.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def test_datetime_from_string():
2121
dfs = datetime_from_string("1999-12-31T23:59:59")
2222
dt_trg = datetime(1999, 12, 31, 23, 59, 59).astimezone(tz=timezone.utc)
2323
assert dfs == dt_trg
24-
# Of course, two datetimes can be equal in different timezones. Make
25-
# sure the timezone info matches UTC, which borg itself expects.
24+
# Two datetimes can be equal in different time zones. Make
25+
# sure the time zone info matches UTC, which Borg itself expects.
2626
assert dfs.tzinfo == dt_trg.tzinfo == timezone.utc
2727

2828
# FIXME: When this format is passed to datetime_from_string, the internal
@@ -34,7 +34,7 @@ def test_datetime_from_string():
3434
assert dfs == dt_trg
3535
assert dfs.tzinfo == dt_trg.tzinfo == timezone.utc
3636

37-
# rsync-time-backup format.
37+
# rsync-time-backup format:
3838
dfs = datetime_from_string("2022-12-21-063019")
3939
dt_trg = datetime(2022, 12, 21, 6, 30, 19).astimezone(tz=timezone.utc)
4040
assert dfs == dt_trg

src/borg_import/helpers/timestamps.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,24 @@
33

44
def datetime_from_mtime(path):
55
"""
6-
discover backup timestamp from a (single) filesystem object.
6+
Discover the backup timestamp from a (single) filesystem object.
77
8-
e.g. from a root/TIMESTAMP file created by "touch" at backup time,
8+
For example, from a root/TIMESTAMP file created by "touch" at backup time,
99
or from root/ (assuming that the directory timestamp was modified
1010
at backup time).
1111
"""
1212
t = path.stat().st_mtime
13-
# Borg needs tz-aware timestamps in UTC timezone.
13+
# Borg needs timezone-aware timestamps in UTC.
1414
return datetime.fromtimestamp(t, tz=timezone.utc)
1515

1616

1717
def datetime_from_string(s):
1818
"""
19-
parse datetime from a string
19+
Parse a datetime from a string.
2020
21-
returns a tz-aware datetime object in UTC timezone if the format could be
22-
parsed.
21+
Return a timezone-aware datetime object in UTC if the format could be parsed.
2322
24-
raises ValueError if not.
23+
Raise ValueError otherwise.
2524
"""
2625
s = s.strip()
2726
for ts_format in [
@@ -40,36 +39,36 @@ def datetime_from_string(s):
4039
]:
4140
try:
4241
if ts_format in ("%a %b %d %H:%M:%S %Z %Y",) and "UTC" in s:
43-
# %Z returns a naive datetime, despite a timezone being specified.
42+
# %Z returns a naive datetime, despite a time zone being specified.
4443
# However, strptime %Z only tends to work on local times and
4544
# UTC.
4645
#
4746
# Per astimezone docs:
4847
# If self is naive, it is presumed to represent time in the
49-
# system timezone.
48+
# system time zone.
5049
#
51-
# If we had a UTC timezone, prevent conversion to aware
52-
# datetime from assuming a local timezone before conversion
50+
# If we had a UTC time zone, prevent conversion to an aware
51+
# datetime from assuming a local time zone before conversion
5352
# to UTC.
5453
return datetime.strptime(s, ts_format).replace(tzinfo=timezone.utc)
5554
else:
5655
# If "UTC" wasn't specified using the above ts_format, assume
57-
# the timezone specified was local and hope for the best.
56+
# the time zone specified was local and hope for the best.
5857
# This handles all other ts_formats as well, which are assumed
59-
# to be local since they don't carry timezone.
58+
# to be local since they don't carry a time zone.
6059
return datetime.strptime(s, ts_format).astimezone(tz=timezone.utc)
6160
except ValueError:
62-
# didn't work with this format, try next
61+
# Didn't work with this format; try the next.
6362
pass
6463
else:
6564
raise ValueError("could not parse %r" % s)
6665

6766

6867
def datetime_from_file(path):
6968
"""
70-
discover backup timestamp from contents of a file.
69+
Discover the backup timestamp from the contents of a file.
7170
72-
e.g. root/TIMESTAMP contains: Mon Oct 31 23:35:50 CET 2016
71+
For example, root/TIMESTAMP contains: Mon Oct 31 23:35:50 CET 2016
7372
"""
7473
with path.open() as f:
7574
ts = f.readline().strip()

src/borg_import/main.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def borg_import(args, archive_name, path, timestamp=None):
3333
except subprocess.CalledProcessError as cpe:
3434
if cpe.returncode != 1:
3535
raise
36-
log.debug("Borg exited with a warning (being quiet about it since Borg spoke already)")
36+
log.debug("Borg exited with a warning (not repeating details since Borg already reported them)")
3737

3838

3939
def list_borg_archives(args):
@@ -72,7 +72,7 @@ class rsnapshotImporter(Importer):
7272
7373
The directory is called "borg-import-dir" inside the rsnapshot root,
7474
and borg-import will note which snapshot is currently located there
75-
in a file called "borg-import-dir.snapshot" besides it, in case
75+
in a file called "borg-import-dir.snapshot" beside it, in case
7676
things go wrong.
7777
7878
Otherwise nothing in the rsnapshot root is modified, and neither
@@ -146,7 +146,7 @@ def import_rsnapshot(self, args):
146146

147147
class rsynchlImporter(Importer):
148148
name = "rsynchl"
149-
description = "import rsync+hardlink backups"
149+
description = "import rsync-with-hard-links backups"
150150
epilog = """
151151
Imports from rsync backup sets by renaming each snapshot to a common
152152
name independent of the snapshot, which allows the Borg files cache
@@ -159,7 +159,7 @@ class rsynchlImporter(Importer):
159159
160160
The directory is called "borg-import-dir" inside the specified root,
161161
and borg-import will note which snapshot is currently located there
162-
in a file called "borg-import-dir.snapshot" besides it, in case
162+
in a file called "borg-import-dir.snapshot" beside it, in case
163163
things go wrong.
164164
165165
Otherwise nothing in the rsync root is modified, and neither
@@ -237,7 +237,7 @@ class rsyncTmBackupImporter(Importer):
237237
238238
The directory is called "borg-import-dir" inside the specified root,
239239
and borg-import will note which snapshot is currently located there
240-
in a file called "borg-import-dir.snapshot" besides it, in case
240+
in a file called "borg-import-dir.snapshot" beside it, in case
241241
things go wrong.
242242
243243
Otherwise nothing in the rsync root is modified, and neither
@@ -305,7 +305,7 @@ class borgImporter(Importer):
305305
This is useful when a Borg repository needs to be rebuilt and all archives
306306
transferred from the old repository to a new one.
307307
308-
The importer extracts each archive from the source repository to a intermediate
308+
The importer extracts each archive from the source repository to an intermediate
309309
directory inside the current work directory (make sure there is enough space!)
310310
and then creates a new archive with the same name and timestamp in the destination
311311
repository.
@@ -419,7 +419,7 @@ def build_parser():
419419

420420
def main():
421421
if not shutil.which("borg"):
422-
print("The 'borg' command can't be found in the PATH. Please correctly install borgbackup first.")
422+
print("The 'borg' command cannot be found in PATH. Please install BorgBackup first.")
423423
print("See instructions at https://borgbackup.readthedocs.io/en/stable/installation.html")
424424
return 1
425425

src/borg_import/rsnapshots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
def get_snapshots(root):
9-
"""Get all snapshot metadata discovered in the rsnapshot root directory."""
9+
"""Return metadata for all snapshots discovered in the rsnapshot root directory."""
1010
regex = re.compile(r"(?P<snapshot_id>.+)/(?P<backup_set>.+)")
1111
for path in discover(str(root), 2):
1212
parsed = parser(path, regex)

src/borg_import/rsync_tmbackup.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88

99
def get_tmbackup_snapshots(root, prefix):
10-
"""Get all snapshot metadata discovered in the rsync root directory."""
10+
"""Return metadata for all snapshots discovered in the rsync root directory."""
1111
regex = re.compile(r"(?P<snapshot_date>.+)")
1212

1313
if not Path("backup.marker").exists():
14-
raise FileNotFoundError("backup.marker file should exist for rsync-time-backup import")
14+
raise FileNotFoundError("The backup.marker file must exist for rsync-time-backup import")
1515

1616
for path in discover(str(root), 1):
1717
parsed = parser(path, regex)
@@ -24,9 +24,9 @@ def get_tmbackup_snapshots(root, prefix):
2424
)
2525
yield meta
2626
elif parsed["snapshot_date"] in ("latest",):
27-
# latest is a symlink to the most recent build. Import it anyway
28-
# in case user wants to do borg mount/has existing references
29-
# to latest.
27+
# "latest" is a symlink to the most recent backup. Import it anyway
28+
# in case the user wants to do borg mount or has existing references
29+
# to "latest".
3030
abs_path = root / path
3131
timestamp = Path("latest").resolve().name
3232
meta = dict(

src/borg_import/rsynchl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
def get_rsyncsnapshots(root):
9-
"""Get all snapshot metadata discovered in the rsync root directory."""
9+
"""Return metadata for all snapshots discovered in the rsync root directory."""
1010
regex = re.compile(r"(?P<snapshot_name>.+)")
1111
for path in discover(str(root), 1):
1212
parsed = parser(path, regex)

0 commit comments

Comments
 (0)