Browse Source

Add a Mercurial dates plugin.

Basically just about the same as the Git dates plugin, but using
hg instead of git.
main
Elliott Sales de Andrade 13 years ago
committed by Lakshmi Vyasarajan
parent
commit
8b03bcdddc
1 changed files with 49 additions and 0 deletions
  1. +49
    -0
      hyde/ext/plugins/vcs.py

+ 49
- 0
hyde/ext/plugins/vcs.py View File

@@ -66,3 +66,52 @@ class GitDatesPlugin(Plugin):
modified = modified.replace(tzinfo=None) modified = modified.replace(tzinfo=None)
resource.meta.modified = modified resource.meta.modified = modified



#
# Mercurial Dates
#

class MercurialDatesPlugin(Plugin):
"""
Extract creation and last modification date from mercurial and
include them in the meta data if they are set to "hg". Creation
date is put in `created` and last modification date in `modified`.
"""

def __init__(self, site):
super(MercurialDatesPlugin, self).__init__(site)

def begin_site(self):
"""
Initialize plugin. Retrieve dates from mercurial
"""
for node in self.site.content.walk():
for resource in node.resources:
created = None
modified = None
try:
created = resource.meta.created
modified = resource.meta.modified
except AttributeError:
pass
# Everything is already overrided
if created != "hg" and modified != "hg":
continue
# Run hg log --template={date|isodatesec}
try:
commits = subprocess.check_output(["hg", "log", "--template={date|isodatesec}\n",
resource.path]).split('\n')
except subprocess.CalledProcessError:
self.logger.warning("Unable to get mercurial history for [%s]" % resource)
continue
commits = commits[:-1]
if not commits:
self.logger.warning("No mercurial history for [%s]" % resource)
continue
if created == "hg":
created = parse(commits[-1].strip())
resource.meta.created = created
if modified == "hg":
modified = parse(commits[0].strip())
resource.meta.modified = modified


Loading…
Cancel
Save