summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgenbackupdata28
-rw-r--r--genbackupdatalib/__init__.py6
-rw-r--r--genbackupdatalib/generator.py10
-rw-r--r--genbackupdatalib/generator_tests.py12
-rw-r--r--genbackupdatalib/names.py28
-rw-r--r--genbackupdatalib/names_tests.py10
6 files changed, 47 insertions, 47 deletions
diff --git a/genbackupdata b/genbackupdata
index 168961b..42cce19 100755
--- a/genbackupdata
+++ b/genbackupdata
@@ -1,16 +1,16 @@
#!/usr/bin/python
# Copyright 2011 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -27,39 +27,39 @@ class GenbackupdataApp(cliapp.Application):
def add_settings(self):
self.settings.bytesize(
- ['create', 'c'],
+ ['create', 'c'],
'how much data to create (default: %default)')
self.settings.bytesize(
- ['file-size'],
+ ['file-size'],
'size of one file',
default=16*1024)
self.settings.bytesize(
- ['chunk-size'],
+ ['chunk-size'],
'generate data in chunks of this size',
default=16*1024)
self.settings.integer(
- ['depth'],
+ ['depth'],
'depth of directory tree',
default=3)
self.settings.integer(
- ['max-files'],
+ ['max-files'],
'max files/dirs per dir',
default=128)
self.settings.integer(
- ['seed'],
+ ['seed'],
'seed for random number generator',
default=0)
self.settings.boolean(
['quiet'],
'do not report progress')
-
+
def process_args(self, args):
outputdir = args[0]
bytes = self.settings['create']
self.gen = genbackupdatalib.DataGenerator(self.settings['seed'])
self.names = genbackupdatalib.NameGenerator(
outputdir, self.settings['depth'], self.settings['max-files'])
-
+
self.setup_ttystatus()
self.status['total'] = bytes
while bytes > 0:
@@ -70,7 +70,7 @@ class GenbackupdataApp(cliapp.Application):
def create_file(self, bytes):
'''Generate one output file.'''
-
+
file_size = self.settings['file-size']
chunk_size = self.settings['chunk-size']
pathname = self.names.new()
@@ -88,7 +88,7 @@ class GenbackupdataApp(cliapp.Application):
chunk = self.gen.generate(bytes)
f.write(chunk)
self.status['written'] += bytes
-
+
def setup_ttystatus(self):
self.status = ttystatus.TerminalStatus(period=0.1)
if self.settings['quiet']:
@@ -98,7 +98,7 @@ class GenbackupdataApp(cliapp.Application):
self.status.format(
'Generating %ByteSize(written) of %ByteSize(total) '
'%PercentDone(written,total) (%ByteSpeed(written))')
-
+
if __name__ == '__main__':
GenbackupdataApp().run()
diff --git a/genbackupdatalib/__init__.py b/genbackupdatalib/__init__.py
index 47e517c..9de0909 100644
--- a/genbackupdatalib/__init__.py
+++ b/genbackupdatalib/__init__.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
diff --git a/genbackupdatalib/generator.py b/genbackupdatalib/generator.py
index 9e3dea2..bfc48d5 100644
--- a/genbackupdatalib/generator.py
+++ b/genbackupdatalib/generator.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -22,9 +22,9 @@ import Crypto.Cipher.ARC4
class DataGenerator(object):
'''Generate random binary data.'''
-
+
_data = 'x' * 1024**2
-
+
def __init__(self, seed):
key = struct.pack('!Q', seed)
self._arc4 = Crypto.Cipher.ARC4.new(key)
diff --git a/genbackupdatalib/generator_tests.py b/genbackupdatalib/generator_tests.py
index 80d12b4..695d106 100644
--- a/genbackupdatalib/generator_tests.py
+++ b/genbackupdatalib/generator_tests.py
@@ -1,15 +1,15 @@
# Copyright 2010 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -24,16 +24,16 @@ class DataGeneratorTests(unittest.TestCase):
def setUp(self):
self.g1 = genbackupdatalib.DataGenerator(0)
self.g2 = genbackupdatalib.DataGenerator(0)
-
+
def test_every_generator_returns_same_sequence(self):
amount = 1024
self.assertEqual(self.g1.generate(amount), self.g2.generate(amount))
-
+
def test_returns_different_sequence_for_different_seed(self):
amount = 1024
g3 = genbackupdatalib.DataGenerator(1)
self.assertNotEqual(self.g1.generate(amount), g3.generate(amount))
-
+
def test_returns_distinct_64k_chunks(self):
size = 64 * 1024
chunk1 = self.g1.generate(size)
diff --git a/genbackupdatalib/names.py b/genbackupdatalib/names.py
index 287112d..1517400 100644
--- a/genbackupdatalib/names.py
+++ b/genbackupdatalib/names.py
@@ -1,15 +1,15 @@
# Copyright 2011 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -20,38 +20,38 @@ import os
class NameGenerator(object):
'''Generate names for new output files.
-
+
If the target directory is empty, the sequence of output files is
always the same for the same parameters.
-
+
A directory structure is also generated. The shape of the tree is
defined by two parameters: 'max' and 'depth'. 'depth' is the number
of levels of subdirectories to create, and 'max' is the maximum
number of files/dirs to allow per output directory. Thus, if max is
3 and depth is 2, the output files are: 0/0/0, 0/0/1, 0/0/2,
0/1/0, 0/1/1, etc.
-
+
If depth is zero, all output files go directly to the target
directory, and max is ignored.
-
+
'''
-
+
def __init__(self, dirname, depth, max):
self.dirname = dirname
self.depth = depth
self.max = max
self.counter = 0
-
+
def _path_tuple(self, n):
'''Return tuple for dir/file numbers for nth output file.
-
+
The last item in the tuple gives the file number, the precding
items the directory numbers. Thus, a tuple (1, 2, 3) would
mean path '1/2/3', but it is given as a tuple for easier
manipulation.
-
+
'''
-
+
if self.depth == 0:
return (n,)
else:
@@ -62,12 +62,12 @@ class NameGenerator(object):
items.append(n)
items.reverse()
return tuple(items)
-
+
def _next_candidate_name(self):
items = self._path_tuple(self.counter)
self.counter += 1
return os.path.join(self.dirname, *[str(i) for i in items])
-
+
def new(self):
while True:
name = self._next_candidate_name()
diff --git a/genbackupdatalib/names_tests.py b/genbackupdatalib/names_tests.py
index 60b4d79..c8ec439 100644
--- a/genbackupdatalib/names_tests.py
+++ b/genbackupdatalib/names_tests.py
@@ -1,15 +1,15 @@
# Copyright 2011 Lars Wirzenius
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -29,10 +29,10 @@ class NameGeneratorTests(unittest.TestCase):
self.depth = 2
self.max = 3
self.names = self.new()
-
+
def tearDown(self):
shutil.rmtree(self.tempdir)
-
+
def new(self):
return genbackupdatalib.NameGenerator(self.tempdir, self.depth,
self.max)