3
# entry.py: module to parse '.svn/entries' file
5
# Subversion is a tool for revision control.
6
# See http://subversion.tigris.org for more information.
8
# ====================================================================
9
# Copyright (c) 2000-2004 CollabNet. All rights reserved.
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.
17
######################################################################
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.
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.
29
import xml.parsers.expat # you may need to install this package
32
"An object that represents an entry from an 'entries' file."
34
def __init__(self, attributes): # constructor
35
self.atts = attributes
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
45
class svn_entryparser:
46
"A class to parse an 'entries' file."
48
def __init__(self): # constructor
50
self.parser = xml.parsers.expat.ParserCreate()
51
self.parser.StartElementHandler = self.handle_start_tag
53
def handle_start_tag(self, name, attrs):
54
"Expat callback that receives a new open-tag."
56
if attrs.has_key('name'):
57
entry = svn_entry(attrs) # create new entry object
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'] + '/' \
72
self.entry_dict[attrs['name']] = entry # store the new entry
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."
79
entryparser = svn_entryparser() # make a parser instance
81
entryparser.parser.ParseFile(fp)
83
return entryparser.entry_dict