BVB Source Codes

Gource Show svn-gource.py Source code

Return Download Gource: download svn-gource.py Source code - Download Gource Source code - Type:.py
  1. #!/usr/bin/python
  2. ## Copyright (c) 2009 Cameron Hart (cam@bitshifter.net.nz)
  3. ## All rights reserved.
  4. ##
  5. ## Redistribution and use in source and binary forms, with or without
  6. ## modification, are permitted provided that the following conditions
  7. ## are met:
  8. ## 1. Redistributions of source code must retain the above copyright
  9. ##    notice, this list of conditions and the following disclaimer.
  10. ## 2. Redistributions in binary form must reproduce the above copyright
  11. ##    notice, this list of conditions and the following disclaimer in the
  12. ##    documentation and/or other materials provided with the distribution.
  13. ## 3. The name of the author may not be used to endorse or promote products
  14. ##    derived from this software without specific prior written permission.
  15. ##
  16. ## THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  17. ## IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  18. ## OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  19. ## IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. ## INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. ## NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. ## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. ## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. ## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  25. ## THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. import sys
  27. import time
  28. import getopt
  29. import re
  30. from xml.etree import ElementTree
  31.  
  32. opt_filter_dirs = False
  33.  
  34. _USAGE = """
  35. svn-gource.py [--help] [--filter-dirs] <file>
  36.  
  37. The input file must be the output of the command svn log --verbose --xml.
  38. """
  39.  
  40. # regular expression for matching any file with an extension
  41. extn_prog = re.compile(".*/?[^/]+\.[^\.]+$")
  42.  
  43. def reverse(data):
  44.     """Returns the log entries in reverse."""
  45.     for index in range(len(data)-1, -1, -1):
  46.         yield data[index]
  47.  
  48. def processXmltree(xmltree):
  49.     global opt_filter_dirs
  50.     for logentry in reverse(xmltree.getiterator("logentry")):
  51.         datetext = logentry.find("date").text
  52.  
  53.         # svn xml logs always use UTC
  54.         timestamp = (time.mktime(time.strptime(datetext[:-8], "%Y-%m-%dT%H:%M:%S")))
  55.         # a bit of a hack to get it into local time again...
  56.         #timestamp = timestamp - time.timezone
  57.  
  58.         #author might not exist
  59.         try:
  60.             author = logentry.find("author").text
  61.         except:
  62.             author = ""
  63.  
  64.         # output all affected files
  65.         for pathentry in logentry.getiterator("path"):
  66.  
  67.             # apply directory filtering strategy
  68.             if opt_filter_dirs and not re.match(extn_prog, pathentry.text):
  69.                 continue;
  70.  
  71.             # join output
  72.             print( "|".join( ( "%d" % int(timestamp), "%s" % author.encode("utf-8"), "%s" % pathentry.get("action"), "%s" % pathentry.text.encode("utf-8"), "" ) ) )
  73.  
  74. def printUsage(message):
  75.     sys.stderr.write(_USAGE)
  76.     if message:
  77.         sys.exit('\nFATAL ERROR: ' + message)
  78.     else:
  79.         sys.exit(1)
  80.  
  81. def processArguments():
  82.     global opt_filter_dirs
  83.  
  84.     try:
  85.         opts, filenames = getopt.getopt(sys.argv[1:], '', ['help', 'filter-dirs'])
  86.     except getopt.GetoptError:
  87.         printUsage('Invalid arguments.')
  88.  
  89.     for (opt, val) in opts:
  90.         if opt == '--help':
  91.             printUsage(None)
  92.         elif opt == '--filter-dirs':
  93.             opt_filter_dirs = True
  94.  
  95.     if not filenames:
  96.         printUsage('No input file specified.')
  97.  
  98.     return filenames[0]
  99.  
  100.  
  101. if __name__ == "__main__":
  102.     filename = processArguments()
  103.  
  104.     xmltree = ElementTree.parse(filename)
  105.  
  106.     processXmltree(xmltree)
  107.  
  108.  
  109.  
  110.  
downloadsvn-gource.py Source code - Download Gource Source code
Related Source Codes/Software:
FDFullscreenPopGesture - A UINavigationController's category to enable full... 2017-01-10
node-style-guide - A guide for styling your node.js / JavaScript code... 2017-01-09
ImageOptim - GUI image optimizer for Mac htt... 2017-01-09
falcon - Falcon is a low-level, high-performance Python fra... 2017-01-09
prerender - Node server that uses phantomjs to render a javasc... 2017-01-09
che - Eclipse Che: Next-generation Eclipse IDE. Open sou... 2017-01-10
notepad-plus-plus - Notepad++ official repository h... 2017-01-10
waterline - An adapter-based ORM for Node.js with support for ... 2017-01-10
Workerman - An asynchronous event driven PHP framework for eas... 2017-01-10
structor - An advanced visual editor for React components ... 2017-01-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top