This file is indexed.

/usr/share/pyshared/DITrack/SVN.py is in ditrack 0.8-1.2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#
# SVN.py - Subversion interface
#
# Copyright (c) 2006-2007 The DITrack Project, www.ditrack.org.
#
# $Id: SVN.py 1944 2007-08-24 23:38:42Z vss $
# $HeadURL: https://svn.xiolabs.com/ditrack/src/tags/0.8/DITrack/SVN.py $
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#  * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#  * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

import os
import re
import sys

import DITrack.Backend.Common
import DITrack.Util.Misc

at_rev_re = re.compile("^At revision (\\d+).$")
update_file_re = re.compile("^([ADU])\\s+(.+)$")
updated_rev_re = re.compile("^Updated to revision (\\d+).$")

class Error(DITrack.Backend.Common.Error):
    def __init__(self, cmd, message, details):

        # XXX: we should really call the parent class constructor here
        self.cmd = cmd
        self.message = message
        self.details = details


class UpdateStatus(DITrack.Backend.Common.UpdateStatus):
    """
    Class representing a result of the update operation.
    """

    def __init__(self, lines):
        """
        LINES is the list of lines produced by 'svn up' command to be parsed.

        Raises ValueError is the data passed is somehow unparseable.
        """
        if not lines:
            raise ValueError, "Empty input"

        self.modifications = []

        if len(lines) == 1:
            m = at_rev_re.match(lines[0])
            if not m:
                raise ValueError, "At unknown revision"

        else:
            m = updated_rev_re.match(lines[-1])
            if not m:
                raise ValueError, "Updated to unknown revision"

            for str in lines[:-1]:
                str = str.rstrip()

                fm = update_file_re.match(str)

                if not fm:
                    raise ValueError, "Can't parse: '%s'" % str

                status, fname = fm.group(1), fm.group(2)

                # XXX: will need to probably wrap into a class later
                self.modifications.append((status, fname))

        # Should convert without problem since matched by the regexp.
        self.revision = int(m.group(1))

    def __str__(self):
        """
        Mimics Subversion 'update' command output.
        """

        if self.modifications:
            return "%s\nUpdated to revision %d.\n" \
                % (
                    "\n".join(
                        map(
                            lambda (x, y): "%s    %s" % (x, y), 
                            self.modifications
                        )
                    ),
                    self.revision
                )
        else:
            return "At revision %d.\n" % self.revision


# XXX: this needs to be moved to the Client class
def propget(propname, path, svn_path):
    p = os.popen("\"%s\" propget %s %s" % (svn_path, propname, path))

    str = ""

    while 1:
        s = p.readline()
        if not s: break

        str = str + s

    ec = p.close()

    if not ec:
        return str.rstrip("\n")

    return None

class Transaction:
    """
    Single Subversion transaction which end with a commit.
    """

    def __init__(self, svn):
        self.files = {}
        self.svn = svn

    def add(self, name):
        """
        Add new file/directory into the transaction.
        """
        self.svn.add(name)
        self.include(name)

    def commit(self, logmsg):
        """
        Perform Subversion commit.
        """

        fnames = self.files.keys()

        self.svn.commit(logmsg, fnames)

    def include(self, fname):
        """
        Include file FNAME into the transaction.
        """

        self.files[fname] = True

    def remove(self, name):
        """
        Remove file/directory (nonrecursive) from the version control within
        the transaction.
        """
        self.svn.remove(name)
        self.include(name)


class Client:
    """
    Subversion interface class. All Subversion-related operations come through
    this class instance.
    """

    def __init__(self, svn_path):
        """
        SVN_PATH is a path to Subversion command line client.
        """

        self.svn_path = svn_path

    def add(self, fname):
        """
        Schedule addition of a file.
        """

        args = [ self.svn_path, "add", "-Nq", fname ]

        # XXX: raise exception on failure here
        return DITrack.Util.Misc.spawnvp(os.P_WAIT, self.svn_path, args)

    def commit(self, logmsg, fnames):

        assert(fnames)
        assert(logmsg)
        
        if os.name == "posix":
            args = [ self.svn_path, "commit", "-q", "-m", logmsg ] + fnames
        elif os.name == "nt":
            # XXX: spaces in file names should be handled by 
            # DITrack.Util.Misc.spawnvp()
            args = [ self.svn_path, "commit", "-q", "-m", "\"%s\"" % logmsg ] + fnames
        # XXX: raise exception on failure here
        return DITrack.Util.Misc.spawnvp(os.P_WAIT, self.svn_path, args)

    def remove(self, fname):
        """
        Schedule the removal of a file FNAME.
        """

        args = [ self.svn_path, "rm", "-q", fname ]

        # XXX: raise exception on failure here
        return DITrack.Util.Misc.spawnvp(os.P_WAIT, self.svn_path, args)

    def start_txn(self):
        """
        Start a new transaction.
        """

        return Transaction(self)

    def update(self, wc_path):
        
        cmd = "%s update %s" % (self.svn_path, wc_path)

        p = os.popen(cmd)
        output = p.readlines()

        # The close method returns the exit status of the process. See 
        # `pydoc os.popen`.
        status = p.close()
        if status:
            raise Error(cmd, "'svn update' didn't succeed", 
                ["Exit status: %d" % status]
            )

        try:
            us = UpdateStatus(output)
        except ValueError:
            raise Error(cmd, "Can't parse the output",
                map(lambda x: x.rstrip(), output)
            )

        return us