* cvs2svn: Use gnu_getopt when available (Python >= 2.3) for more flexible
[cvs2svn.git] / cvs2svn_lib / key_generator.py
blobafeb68848475d98327df067497a5e6244d8bb924
1 # (Be in -*- python -*- mode.)
3 # ====================================================================
4 # Copyright (c) 2000-2006 CollabNet. All rights reserved.
6 # This software is licensed as described in the file COPYING, which
7 # you should have received as part of this distribution. The terms
8 # are also available at http://subversion.tigris.org/license-1.html.
9 # If newer versions of this license are posted there, you may use a
10 # newer version instead, at your option.
12 # This software consists of voluntary contributions made by many
13 # individuals. For exact contribution history, see the revision
14 # history and logs, available at http://cvs2svn.tigris.org/.
15 # ====================================================================
17 """This module contains the KeyGenerator class."""
20 import sys
21 import os
22 import marshal
24 from boolean import *
27 class KeyGenerator:
28 """Generate a series of unique keys."""
30 def __init__(self, key_base=1L):
31 """Initialize a KeyGenerator with the specified KEY_BASE.
33 KEY_BASE should be an int or long, and the generated keys will be
34 of the same type."""
36 self.key_base = key_base
38 def gen_id(self):
39 """Generate and return a previously-unused key, as an integer."""
41 id = self.key_base
42 self.key_base += 1
44 return id
46 def gen_key(self):
47 """Generate and return a previously-unused key, as a string."""
49 return '%x' % self.gen_id()