Browse Source

pulling os dates from files in git.py

main
Henning@Mac 12 years ago
committed by Lakshmi Vyasarajan
parent
commit
1e56c51a7d
1 changed files with 16 additions and 8 deletions
  1. +16
    -8
      hyde/ext/plugins/git.py

+ 16
- 8
hyde/ext/plugins/git.py View File

@@ -5,8 +5,10 @@ Contains classes and utilities to extract information from git repository


from hyde.plugin import Plugin from hyde.plugin import Plugin


import subprocess
from datetime import datetime
from dateutil.parser import parse from dateutil.parser import parse
import os.path
import subprocess


class GitDatesPlugin(Plugin): class GitDatesPlugin(Plugin):
""" """
@@ -38,18 +40,24 @@ class GitDatesPlugin(Plugin):
try: try:
commits = subprocess.check_output(["git", "log", "--pretty=%ai", commits = subprocess.check_output(["git", "log", "--pretty=%ai",
resource.path]).split("\n") resource.path]).split("\n")
commits = commits[:-1]
if not commits:
self.logger.warning("No git history for [%s]" % resource)
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
self.logger.warning("Unable to get git history for [%s]" % resource) self.logger.warning("Unable to get git history for [%s]" % resource)
continue
commits = commits[:-1]
if not commits:
self.logger.warning("No git history for [%s]" % resource)
continue
commits = None

if created == "git": if created == "git":
created = parse(commits[-1].strip())
if commits:
created = parse(commits[-1].strip())
else:
created = datetime.utcfromtimestamp(os.path.getctime(resource.path))
created = created.replace(tzinfo=None) created = created.replace(tzinfo=None)
resource.meta.created = created resource.meta.created = created
if modified == "git": if modified == "git":
modified = parse(commits[0].strip())
if commits:
modified = parse(commits[0].strip())
else:
modified = datetime.utcfromtimestamp(os.path.getmtime(resource.path))
modified = modified.replace(tzinfo=None) modified = modified.replace(tzinfo=None)
resource.meta.modified = modified resource.meta.modified = modified

Loading…
Cancel
Save