Rework uri_encode/uri_decode to more cleanly work with bytes/strings.
[cumulus.git] / python / cumulus / rebuild_database.py
index a4af640..4ab580f 100755 (executable)
@@ -26,6 +26,8 @@ the local database.  This can be used to recover from a local database loss,
 given data from a previous backup.
 """
 
+from __future__ import division, print_function, unicode_literals
+
 import base64
 import hashlib
 import itertools
@@ -38,6 +40,7 @@ import tarfile
 import time
 
 import cumulus
+from cumulus import util
 
 CHECKSUM_ALGORITHM = "sha224"
 CHUNKER_PROGRAM = "cumulus-chunker-standalone"
@@ -275,7 +278,7 @@ class DatabaseRebuilder(object):
 
     def insert_segment_info(self, segment, info):
         id = self.segment_to_id(segment)
-        for k, v in list(info.items()):
+        for k, v in info.items():
             self.cursor.execute("update segments set " + k + " = ? "
                                 "where segmentid = ?",
                                 (v, id))
@@ -417,8 +420,8 @@ class SegmentStateRebuilder(object):
                 data_size += tarinfo.size
                 object_count += 1
 
-        return {"segment": cumulus.uri_encode(segment_name),
-                "path": cumulus.uri_encode(relative_path),
+        return {"segment": util.uri_encode_pathname(segment_name),
+                "path": util.uri_encode_pathname(relative_path),
                 "checksum": checksum,
                 "data_size": data_size,
                 "disk_size": disk_size,