2016-06-23 13:31:18 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# -*- mode:python -*-
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
import codecs
|
|
|
|
from git import Repo
|
|
|
|
import locale
|
2016-06-27 09:35:25 +00:00
|
|
|
# Locales for date set up to de_DE
|
|
|
|
# Please edit to you needs
|
2016-06-23 13:31:18 +00:00
|
|
|
locale.setlocale(locale.LC_ALL, 'de_DE')
|
|
|
|
|
2016-06-27 09:35:25 +00:00
|
|
|
# set up the git repo
|
|
|
|
# path is the current working directory
|
2016-06-23 13:31:18 +00:00
|
|
|
pathrepo = os.getcwd()
|
|
|
|
repo = Repo(pathrepo)
|
|
|
|
assert not repo.bare
|
|
|
|
git = repo.git
|
|
|
|
headcommit = repo.head.commit
|
|
|
|
index = repo.index
|
|
|
|
|
2016-06-27 09:35:25 +00:00
|
|
|
# check for specific file (else) or
|
|
|
|
# every tex file within the git
|
2016-06-23 13:31:18 +00:00
|
|
|
if len(sys.argv) <= 1:
|
2016-06-27 09:35:25 +00:00
|
|
|
# get all the files within the git
|
2016-06-23 13:31:18 +00:00
|
|
|
commFiles = git.ls_files(full_name=True).split("\n")
|
|
|
|
|
2016-06-27 09:35:25 +00:00
|
|
|
# iterate through all files and read date/author/commit and
|
|
|
|
# write in the help file
|
2016-06-23 13:31:18 +00:00
|
|
|
for fl in commFiles:
|
|
|
|
flname, flext = os.path.splitext(fl)
|
|
|
|
if flext == '.tex':
|
2016-06-27 09:35:25 +00:00
|
|
|
rawdate = int(git.log('-1', fl,
|
2016-06-27 09:53:01 +00:00
|
|
|
pretty='format:"%at"').split('"')[1])
|
2016-06-23 16:53:02 +00:00
|
|
|
date = [time.strftime("%d. %B %Y %H:%M", time.localtime(rawdate)),
|
|
|
|
time.strftime("%d", time.localtime(rawdate)),
|
|
|
|
time.strftime("%m", time.localtime(rawdate)),
|
|
|
|
time.strftime("%Y", time.localtime(rawdate)),
|
|
|
|
time.strftime("%H", time.localtime(rawdate)),
|
|
|
|
time.strftime("%M", time.localtime(rawdate))]
|
2016-06-23 13:31:18 +00:00
|
|
|
author = [git.log('-1', fl, pretty='format:"%an"').split('"')[1],
|
2016-06-27 09:53:01 +00:00
|
|
|
git.log('-1', fl, pretty='format:"%ae"').split('"')[1]]
|
2016-06-23 13:31:18 +00:00
|
|
|
commit = [git.log('-1', fl, pretty='format:"%H"').split('"')[1],
|
|
|
|
git.log('-1', fl, pretty='format:"%h"').split('"')[1]]
|
|
|
|
f = codecs.open(flname+".gfi", "w", encoding="utf-8")
|
|
|
|
f.write("% gitfile-info control file\n")
|
2016-06-27 09:35:25 +00:00
|
|
|
f.write("\\gfiSetDate{" + date[1] + "}{" + date[2] + "}{" + date[3]
|
|
|
|
+ "}{" + date[4] + "}{" + date[5] + "}{" + date[0] + "}\n")
|
2016-06-23 13:31:18 +00:00
|
|
|
f.write("\\gfiSetAuthor{" + author[0] + "}{" + author[1] + "}\n")
|
|
|
|
f.write("\\gfiSetCommit{" + commit[0] + "}{" + commit[1] + "}")
|
|
|
|
f.close
|
|
|
|
else:
|
2016-06-27 09:35:25 +00:00
|
|
|
# get the specific file, read date/author/commit and
|
|
|
|
# write the help file
|
2016-06-23 13:31:18 +00:00
|
|
|
fl = sys.argv[1]
|
|
|
|
flname, flext = os.path.splitext(fl)
|
|
|
|
rawdate = int(git.log('-1', fl, pretty='format:"%at"').split('"')[1])
|
2016-06-23 16:53:02 +00:00
|
|
|
date = [time.strftime("%d. %B %Y %H:%M", time.localtime(rawdate)),
|
|
|
|
time.strftime("%d", time.localtime(rawdate)),
|
|
|
|
time.strftime("%m", time.localtime(rawdate)),
|
|
|
|
time.strftime("%Y", time.localtime(rawdate)),
|
|
|
|
time.strftime("%H", time.localtime(rawdate)),
|
|
|
|
time.strftime("%M", time.localtime(rawdate))]
|
2016-06-23 13:31:18 +00:00
|
|
|
author = [git.log('-1', fl, pretty='format:"%an"').split('"')[1],
|
|
|
|
git.log('-1', fl, pretty='format:"%ae"').split('"')[1]]
|
|
|
|
commit = [git.log('-1', fl, pretty='format:"%H"').split('"')[1],
|
2016-06-27 09:35:25 +00:00
|
|
|
git.log('-1', fl, pretty='format:"%h"').split('"')[1]]
|
2016-06-23 13:31:18 +00:00
|
|
|
f = codecs.open(flname+".gfi", "w", encoding="utf-8")
|
|
|
|
f.write("% gitfile-info control file\n")
|
2016-06-27 09:35:25 +00:00
|
|
|
f.write("\\gfiSetDate{" + date[1] + "}{" + date[2] + "}{" + date[3]
|
|
|
|
+ "}{" + date[4] + "}{" + date[5] + "}{" + date[0] + "}\n")
|
2016-06-23 13:31:18 +00:00
|
|
|
f.write("\\gfiSetAuthor{" + author[0] + "}{" + author[1] + "}\n")
|
|
|
|
f.write("\\gfiSetCommit{" + commit[0] + "}{" + commit[1] + "}")
|
|
|
|
f.close
|