1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-08 12:34:16 +00:00

add ability to add auto-generated dotdrop header in dotfiles

This commit is contained in:
deadc0de6
2018-09-01 17:28:02 +02:00
parent 0d097c8a77
commit 33361ddea6
4 changed files with 136 additions and 3 deletions

View File

@@ -35,6 +35,7 @@ class Templategen:
variable_end_string=VAR_END,
comment_start_string=COMMENT_START,
comment_end_string=COMMENT_END)
self.env.globals['header'] = self._header
self.log = Logger()
def generate(self, src, profile):
@@ -42,6 +43,10 @@ class Templategen:
return ''
return self._handle_file(src, profile)
def _header(self, prepend=''):
"""add a comment usually in the header of a dotfile"""
return '{}{}'.format(prepend, utils.header())
def _handle_file(self, src, profile):
"""generate the file content from template"""
filetype = utils.run(['file', '-b', src], raw=False, debug=self.debug)

View File

@@ -9,10 +9,12 @@ import subprocess
import tempfile
import os
import shlex
import datetime
from shutil import rmtree
# local import
from dotdrop.logger import Logger
from dotdrop.version import __version__ as VERSION
LOG = Logger()
@@ -65,3 +67,11 @@ def samefile(path1, path2):
if not os.path.exists(path2):
return False
return os.path.samefile(path1, path2)
def header():
header = 'This dotfile is managed using dotdrop'
header += ' v{}'.format(VERSION)
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
header += ' / last updated {}'.format(now)
return header