summaryrefslogtreecommitdiff
path: root/genbackupdatalib/names.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-01-20 20:43:21 +0000
committerLars Wirzenius <liw@liw.fi>2011-01-20 20:43:21 +0000
commit6865d3ff7d9d0718fdbc6b8b8deb36bca9534dfb (patch)
tree652173e3b4956ec630b396f4f163f59d2f69a3b1 /genbackupdatalib/names.py
parentb7532e9b4f753b16808581a58d4f127db6c81ebb (diff)
downloadgenbackupdata-6865d3ff7d9d0718fdbc6b8b8deb36bca9534dfb.tar.gz
Add more functionality and tests to NameGenerator.
Diffstat (limited to 'genbackupdatalib/names.py')
-rw-r--r--genbackupdatalib/names.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/genbackupdatalib/names.py b/genbackupdatalib/names.py
index 1ce0c20..8cca24c 100644
--- a/genbackupdatalib/names.py
+++ b/genbackupdatalib/names.py
@@ -14,12 +14,23 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import os
+
+
class NameGenerator(object):
'''Generate names for new output files.'''
def __init__(self, dirname):
self.dirname = dirname
-
+ self.counter = 0
+
+ def _next_candidate_name(self):
+ self.counter += 1
+ return os.path.join(self.dirname, 'file%d' % self.counter)
+
def new(self):
- return 'foo'
+ while True:
+ name = self._next_candidate_name()
+ if not os.path.exists(name):
+ return name