~ubuntu-branches/ubuntu/trusty/subversion/trusty-proposed

« back to all changes in this revision

Viewing changes to tools/dev/scramble-tree.py

  • Committer: Package Import Robot
  • Author(s): Andy Whitcroft
  • Date: 2012-06-21 15:36:36 UTC
  • mfrom: (0.4.13 sid)
  • Revision ID: package-import@ubuntu.com-20120621153636-amqqmuidgwgxz1ly
Tags: 1.7.5-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Create pot file on build.
  - Build a python-subversion-dbg package.
  - Build-depend on python-dbg.
  - Build-depend on default-jre-headless/-jdk.
  - Do not apply java-build patch.
  - debian/rules: Manually create the doxygen output directory, otherwise
    we get weird build failures when running parallel builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
2
#
 
3
#
 
4
# Licensed to the Apache Software Foundation (ASF) under one
 
5
# or more contributor license agreements.  See the NOTICE file
 
6
# distributed with this work for additional information
 
7
# regarding copyright ownership.  The ASF licenses this file
 
8
# to you under the Apache License, Version 2.0 (the
 
9
# "License"); you may not use this file except in compliance
 
10
# with the License.  You may obtain a copy of the License at
 
11
#
 
12
#   http://www.apache.org/licenses/LICENSE-2.0
 
13
#
 
14
# Unless required by applicable law or agreed to in writing,
 
15
# software distributed under the License is distributed on an
 
16
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 
17
# KIND, either express or implied.  See the License for the
 
18
# specific language governing permissions and limitations
 
19
# under the License.
 
20
#
 
21
#
 
22
#
3
23
# scramble-tree.py:  (See scramble-tree.py --help.)
4
24
#
5
25
# Makes multiple random file changes to a directory tree, for testing.
40
60
except AttributeError:
41
61
  my_getopt = getopt.getopt
42
62
import random
43
 
import md5
 
63
try:
 
64
  # Python >=2.5
 
65
  from hashlib import md5 as hashlib_md5
 
66
except ImportError:
 
67
  # Python <2.5
 
68
  from md5 import md5 as hashlib_md5
44
69
import base64
45
70
 
46
71
 
95
120
 
96
121
  def __init__(self, rootdir):
97
122
    self.allfiles = []
98
 
    os.path.walk(rootdir, self.walker_callback, len(rootdir))
 
123
    for dirpath, dirs, files in os.walk(rootdir):
 
124
      self.walker_callback(len(rootdir), dirpath, dirs + files)
99
125
 
100
126
  def gen_seed(self):
101
127
    # Return a base64-encoded (kinda ... strip the '==\n' from the
102
128
    # end) MD5 hash of sorted tree listing.
103
129
    self.allfiles.sort()
104
 
    return base64.encodestring(md5.md5(''.join(self.allfiles)).digest())[:-3]
 
130
    return base64.encodestring(hashlib_md5(''.join(self.allfiles)).digest())[:-3]
105
131
 
106
132
  def walker_callback(self, baselen, dirname, fnames):
107
133
    if ((dirname == '.svn') or (dirname == 'CVS')):
275
301
  if seed is None:
276
302
    seed = hashDir(rootdir).gen_seed()
277
303
  scrambler = Scrambler(seed, vc_actions, dry_run, quiet)
278
 
  os.path.walk(rootdir, walker_callback, scrambler)
 
304
  for dirpath, dirs, files in os.walk(rootdir):
 
305
    walker_callback(scrambler, dirpath, dirs + files)
279
306
  scrambler.enact(limit)
280
307
 
281
308
if __name__ == '__main__':