Sfoglia il codice sorgente

Refactor: call getfqdn() once per call of replace_placeholders()

Gregor Kleen 7 anni fa
parent
commit
294f06b565
1 ha cambiato i file con 3 aggiunte e 2 eliminazioni
  1. 3 2
      src/borg/helpers/parseformat.py

+ 3 - 2
src/borg/helpers/parseformat.py

@@ -180,10 +180,11 @@ def format_line(format, data):
 def replace_placeholders(text):
     """Replace placeholders in text with their values."""
     current_time = datetime.now()
+    fqdn = socket.getfqdn()
     data = {
         'pid': os.getpid(),
-        'fqdn': socket.getfqdn(),
-        'reverse-fqdn': '.'.join(reversed(socket.getfqdn().split('.'))),
+        'fqdn': fqdn,
+        'reverse-fqdn': '.'.join(reversed(fqdn.split('.'))),
         'hostname': socket.gethostname(),
         'now': DatetimeWrapper(current_time.now()),
         'utcnow': DatetimeWrapper(current_time.utcnow()),