~svn/ubuntu/raring/subversion/ppa

« back to all changes in this revision

Viewing changes to subversion/tests/clients/cmdline/svntest/entry.py

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:26:14 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205012614-qom4xfypgtsqc2xq
Tags: 1.2.3dfsg1-3ubuntu1
Merge with the final Debian release of 1.2.3dfsg1-3, bringing in
fixes to the clean target, better documentation of the libdb4.3
upgrade and build fixes to work with swig1.3_1.3.27.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
#
 
3
#  entry.py:  module to parse '.svn/entries' file
 
4
#
 
5
#  Subversion is a tool for revision control. 
 
6
#  See http://subversion.tigris.org for more information.
 
7
#    
 
8
# ====================================================================
 
9
# Copyright (c) 2000-2004 CollabNet.  All rights reserved.
 
10
#
 
11
# This software is licensed as described in the file COPYING, which
 
12
# you should have received as part of this distribution.  The terms
 
13
# are also available at http://subversion.tigris.org/license-1.html.
 
14
# If newer versions of this license are posted there, you may use a
 
15
# newer version instead, at your option.
 
16
#
 
17
######################################################################
 
18
#
 
19
# Usage:
 
20
#
 
21
#    Just call svn_entry.get_entries(path), where PATH is exact path
 
22
#    to an 'entries' file.  You'll get back a hash of svn_entry
 
23
#    objects keyed by name.
 
24
#
 
25
#    Each object contains a hash 'atts' that you can examine: name,
 
26
#    kind, revision, ancestor.  Other optional keys *might* be
 
27
#    present, such as prop-time, text-time, add, delete, conflict.
 
28
 
 
29
import xml.parsers.expat  # you may need to install this package
 
30
 
 
31
class svn_entry:
 
32
  "An object that represents an entry from an 'entries' file."
 
33
 
 
34
  def __init__(self, attributes):   # constructor
 
35
    self.atts = attributes
 
36
 
 
37
  def prettyprint(self):
 
38
    print " Entryname:", self.atts['name']
 
39
    print "      Kind:", self.atts['kind']
 
40
    print "  Revision:", self.atts['revision']
 
41
    print "  Ancestor:", self.atts['ancestor']
 
42
    print "  all atts:", self.atts
 
43
    print
 
44
 
 
45
class svn_entryparser:
 
46
  "A class to parse an 'entries' file."
 
47
 
 
48
  def __init__(self):   # constructor
 
49
    self.entry_dict = {}
 
50
    self.parser = xml.parsers.expat.ParserCreate()
 
51
    self.parser.StartElementHandler = self.handle_start_tag
 
52
 
 
53
  def handle_start_tag(self, name, attrs):
 
54
    "Expat callback that receives a new open-tag."
 
55
 
 
56
    if attrs.has_key('name'):
 
57
      entry = svn_entry(attrs) # create new entry object
 
58
      
 
59
      # Derive missing values
 
60
      if not entry.atts.has_key('kind'):
 
61
        entry.atts['kind'] = 'file' # default kind if none mentioned
 
62
      if not entry.atts.has_key('revision'):
 
63
        if self.entry_dict.has_key(""):
 
64
          parent = self.entry_dict[""]
 
65
          entry.atts['revision'] = parent.atts['revision']
 
66
      if not entry.atts.has_key('ancestor'):
 
67
        if self.entry_dict.has_key(""):
 
68
          parent = self.entry_dict[""]
 
69
          entry.atts['ancestor'] = parent.atts['ancestor'] + '/' \
 
70
                                   + entry.atts['name']
 
71
                  
 
72
      self.entry_dict[attrs['name']] = entry  # store the new entry
 
73
 
 
74
 
 
75
# The main exported routine
 
76
def get_entries(path):
 
77
  "Parse the entries file at PATH and return a list of svn_entry objects."
 
78
 
 
79
  entryparser = svn_entryparser() # make a parser instance
 
80
  fp = open(path, 'r')
 
81
  entryparser.parser.ParseFile(fp)
 
82
  fp.close()
 
83
  return entryparser.entry_dict
 
84
 
 
85
 
 
86
### End of file.