summaryrefslogtreecommitdiff
path: root/rdiff-backup/misc
diff options
context:
space:
mode:
authorben <ben@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109>2002-03-21 07:22:43 +0000
committerben <ben@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109>2002-03-21 07:22:43 +0000
commit8c37a5bdfdd46d5cfad6e9d67925ddef9ca382bf (patch)
tree8f19be83962ef31d8ad58429d575c6f17d89c0ea /rdiff-backup/misc
parent8259a0d8a9ad1396a93cd6320943dc33446ac6ed (diff)
downloadrdiff-backup-8c37a5bdfdd46d5cfad6e9d67925ddef9ca382bf.tar.gz
First checkin
git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/trunk@2 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
Diffstat (limited to 'rdiff-backup/misc')
-rwxr-xr-xrdiff-backup/misc/find2dirs30
-rwxr-xr-xrdiff-backup/misc/init_files.py69
-rwxr-xr-xrdiff-backup/misc/myrm16
-rw-r--r--rdiff-backup/misc/remove-comments.py32
4 files changed, 147 insertions, 0 deletions
diff --git a/rdiff-backup/misc/find2dirs b/rdiff-backup/misc/find2dirs
new file mode 100755
index 0000000..9d919d3
--- /dev/null
+++ b/rdiff-backup/misc/find2dirs
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+
+from __future__ import generators
+import sys, os, stat
+
+def usage():
+ print "Usage: find2dirs dir1 dir2"
+ print
+ print "Given the name of two directories, list all the files in both, one"
+ print "per line, but don't repeat a file even if it is in both directories"
+ sys.exit(1)
+
+def getlist(base, ext = ""):
+ """Return iterator yielding filenames from directory"""
+ if ext: yield ext
+ else: yield "."
+
+ fullname = os.path.join(base, ext)
+ if stat.S_ISDIR(stat.S_IFMT(os.lstat(fullname)[stat.ST_MODE])):
+ for subfile in os.listdir(fullname):
+ for fn in getlist(base, os.path.join(ext, subfile)): yield fn
+
+def main(dir1, dir2):
+ d = {}
+ for fn in getlist(dir1): d[fn] = 1
+ for fn in getlist(dir2): d[fn] = 1
+ for fn in d.keys(): print fn
+
+if not len(sys.argv) == 3: usage()
+else: main(sys.argv[1], sys.argv[2])
diff --git a/rdiff-backup/misc/init_files.py b/rdiff-backup/misc/init_files.py
new file mode 100755
index 0000000..1d8651a
--- /dev/null
+++ b/rdiff-backup/misc/init_files.py
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+
+"""init_smallfiles.py
+
+This program makes a number of files of the given size in the
+specified directory.
+
+"""
+
+import os, stat, sys, math
+
+if len(sys.argv) > 5 or len(sys.argv) < 4:
+ print "Usage: init_files [directory name] [file size] [file count] [base]"
+ print
+ print "Creates file_count files in directory_name of size file_size."
+ print "The created directory has a tree type structure where each level"
+ print "has at most base files or directories in it. Default is 50."
+ sys.exit(1)
+
+dirname = sys.argv[1]
+filesize = int(sys.argv[2])
+filecount = int(sys.argv[3])
+block_size = 16384
+block = "." * block_size
+block_change = "." * (filesize % block_size)
+if len(sys.argv) == 4: base = 50
+else: base = int(sys.argv[4])
+
+def make_file(path):
+ """Make the file at path"""
+ fp = open(path, "w")
+ for i in xrange(int(math.floor(filesize/block_size))): fp.write(block)
+ fp.write(block_change)
+ fp.close()
+
+def find_sublevels(count):
+ """Return number of sublevels required for count files"""
+ return int(math.ceil(math.log(count)/math.log(base)))
+
+def make_dir(dir, count):
+ """Make count files in the directory, making subdirectories if necessary"""
+ print "Making directory %s with %d files" % (dir, count)
+ os.mkdir(dir)
+ level = find_sublevels(count)
+ assert count <= pow(base, level)
+ if level == 1:
+ for i in range(count): make_file(os.path.join(dir, "file%d" %i))
+ else:
+ files_per_subdir = pow(base, level-1)
+ full_dirs = int(count/files_per_subdir)
+ assert full_dirs <= base
+ for i in range(full_dirs):
+ make_dir(os.path.join(dir, "subdir%d" % i), files_per_subdir)
+
+ change = count - full_dirs*files_per_subdir
+ assert change >= 0
+ if change > 0:
+ make_dir(os.path.join(dir, "subdir%d" % full_dirs), change)
+
+def start(dir):
+ try: os.stat(dir)
+ except os.error: pass
+ else:
+ print "Directory %s already exists, exiting." % dir
+ sys.exit(1)
+
+ make_dir(dirname, filecount)
+
+start(dirname)
diff --git a/rdiff-backup/misc/myrm b/rdiff-backup/misc/myrm
new file mode 100755
index 0000000..1d8350f
--- /dev/null
+++ b/rdiff-backup/misc/myrm
@@ -0,0 +1,16 @@
+#!/usr/bin/python
+
+import sys, os
+
+curdir = os.getcwd()
+os.chdir("../src")
+execfile("destructive_stepping.py")
+os.chdir(curdir)
+
+lc = Globals.local_connection
+
+for filename in sys.argv[1:]:
+ #print "Deleting %s" % filename
+ rp = RPath(lc, filename)
+ if rp.lstat(): rp.delete()
+
diff --git a/rdiff-backup/misc/remove-comments.py b/rdiff-backup/misc/remove-comments.py
new file mode 100644
index 0000000..e24e3ba
--- /dev/null
+++ b/rdiff-backup/misc/remove-comments.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+
+"""remove-comments.py
+
+Given a python program on standard input, spit one out on stdout that
+should work the same, but has blank and comment lines removed.
+
+"""
+
+import sys, re
+
+triple_regex = re.compile('"""')
+
+def eattriple(initial_line_stripped):
+ """Keep reading until end of doc string"""
+ assert initial_line_stripped.startswith('"""')
+ if triple_regex.search(initial_line_stripped[3:]): return
+ while 1:
+ line = sys.stdin.readline()
+ if not line or triple_regex.search(line): break
+
+while 1:
+ line = sys.stdin.readline()
+ if not line: break
+ stripped = line.strip()
+ if not stripped: continue
+ if stripped[0] == "#": continue
+ if stripped.startswith('"""'):
+ eattriple(stripped)
+ continue
+ sys.stdout.write(line)
+