DrTrigon has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/77554


Change subject: introduce keyword expansion (like svn:keywords) hooks
......................................................................

introduce keyword expansion (like svn:keywords) hooks

Change-Id: I8803e54eaeeafa404a38260e25959ab57a44263a
---
M .gitattributes
A maintenance/rcs-keyword
M wikipedia.py
3 files changed, 34 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/compat 
refs/changes/54/77554/1

diff --git a/.gitattributes b/.gitattributes
index 274c91d..441ea05 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1 +1,2 @@
 *.py ident
+*.py filter=rcs-keyword
diff --git a/maintenance/rcs-keyword b/maintenance/rcs-keyword
new file mode 100755
index 0000000..a08531c
--- /dev/null
+++ b/maintenance/rcs-keyword
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+""" Simple python script keyword expansion (like svn:keywords) in python files:
+* expands $pwbId$ keyword on checkout
+* (more keywords named like $pwbSomeKeyword$ or $pwb-some-keyword$ can be
+  added easily)
+"""
+#
+# (C) 2013 DrTrigon
+# (C) Pywikipedia bot team, 2013
+#
+# Distributed under the terms of the MIT license.
+#
+
+import sys, re, subprocess
+
+INPUT = sys.stdin.read()[:-1]
+
+if '--clean' in sys.argv:
+    print re.sub('(\$pwb[-\w]+)([^\n\r\$]*)\$', '\g<1>$', INPUT)
+else:
+    # executing 2 'git' shell commands PER file is VERY SLOW:
+    rev  = subprocess.Popen('git rev-list HEAD | wc -l',
+                            shell=True,
+                            stdout=subprocess.PIPE).stdout.read().strip()
+    info = subprocess.Popen("git log --pretty=format:'%ad %an %h%d'"
+                            " --abbrev-commit --date=iso -1 | cat -",
+                            shell=True,
+                            stdout=subprocess.PIPE).stdout.read().strip()
+
+    # $pwbId$
+    print re.sub('(\$pwbId)([^\n\r\$]*)\$', '\g<1>: %s %s %s $' %\
+                     ('(filename n/a)', rev, info), INPUT)
diff --git a/wikipedia.py b/wikipedia.py
index ccdc5d7..1fa2de9 100644
--- a/wikipedia.py
+++ b/wikipedia.py
@@ -131,6 +131,7 @@
 # Distributed under the terms of the MIT license.
 #
 __version__ = '$Id$'
+__ver_git__ = '$pwbId$'
 
 import os, sys
 import httplib, socket, urllib, urllib2, cookielib

-- 
To view, visit https://gerrit.wikimedia.org/r/77554
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8803e54eaeeafa404a38260e25959ab57a44263a
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: DrTrigon <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to