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