Explorar el Código

Merge pull request #1752 from ThomasWaldmann/borgversion-enhanced

implement borgmajor/minor/patch placeholders, fixes #1694
TW hace 8 años
padre
commit
ab8b26b9ac
Se han modificado 3 ficheros con 23 adiciones y 4 borrados
  1. 4 1
      borg/__init__.py
  2. 15 3
      borg/archiver.py
  3. 4 0
      borg/helpers.py

+ 4 - 1
borg/__init__.py

@@ -1,3 +1,6 @@
-# This is a python package
+from distutils.version import LooseVersion
 
 
 from ._version import version as __version__
 from ._version import version as __version__
+
+
+__version_tuple__ = tuple(LooseVersion(__version__).version[:3])

+ 15 - 3
borg/archiver.py

@@ -949,7 +949,19 @@ class Archiver:
 
 
         {borgversion}
         {borgversion}
 
 
-            The version of borg.
+            The version of borg, e.g.: 1.0.8rc1
+
+        {borgmajor}
+
+            The version of borg, only the major version, e.g.: 1
+
+        {borgminor}
+
+            The version of borg, only major and minor version, e.g.: 1.0
+
+        {borgpatch}
+
+            The version of borg, only major, minor and patch version, e.g.: 1.0.8
 
 
        Examples::
        Examples::
 
 
@@ -1229,8 +1241,8 @@ class Archiver:
         '.checkpoint.N' (with N being a number), because these names are used for
         '.checkpoint.N' (with N being a number), because these names are used for
         checkpoints and treated in special ways.
         checkpoints and treated in special ways.
 
 
-        In the archive name, you may use the following format tags:
-        {now}, {utcnow}, {fqdn}, {hostname}, {user}, {pid}, {borgversion}
+        In the archive name, you may use the following placeholders:
+        {now}, {utcnow}, {fqdn}, {hostname}, {user} and some others.
 
 
         To speed up pulling backups over sshfs and similar network file systems which do
         To speed up pulling backups over sshfs and similar network file systems which do
         not provide correct inode information the --ignore-inode flag can be used. This
         not provide correct inode information the --ignore-inode flag can be used. This

+ 4 - 0
borg/helpers.py

@@ -28,6 +28,7 @@ from fnmatch import translate
 from operator import attrgetter
 from operator import attrgetter
 
 
 from . import __version__ as borg_version
 from . import __version__ as borg_version
+from . import __version_tuple__ as borg_version_tuple
 from . import hashindex
 from . import hashindex
 from . import chunker
 from . import chunker
 from . import crypto
 from . import crypto
@@ -585,6 +586,9 @@ def replace_placeholders(text):
         'utcnow': current_time.utcnow(),
         'utcnow': current_time.utcnow(),
         'user': uid2user(os.getuid(), os.getuid()),
         'user': uid2user(os.getuid(), os.getuid()),
         'borgversion': borg_version,
         'borgversion': borg_version,
+        'borgmajor': '%d' % borg_version_tuple[:1],
+        'borgminor': '%d.%d' % borg_version_tuple[:2],
+        'borgpatch': '%d.%d.%d' % borg_version_tuple[:3],
     }
     }
     return format_line(text, data)
     return format_line(text, data)