From 567bd6a883eaa54d10ca61d0b6083da09bf48085 Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Tue, 28 Jan 2014 08:28:22 -0800 Subject: [PATCH] Manual 2to3 fixups. --- cumulus-store | 2 ++ cumulus-sync | 2 ++ cumulus-util | 2 ++ python/cumulus/__init__.py | 20 +++++++++++++++----- python/cumulus/cmd_util.py | 2 ++ python/cumulus/config.py | 7 ++++++- python/cumulus/main.py | 2 ++ python/cumulus/metadata.py | 2 ++ python/cumulus/rebuild_database.py | 4 +++- python/cumulus/retention.py | 2 ++ python/cumulus/store/__init__.py | 12 +++++++++--- python/cumulus/store/file.py | 2 ++ python/cumulus/store/ftp.py | 2 ++ python/cumulus/store/s3.py | 2 ++ python/cumulus/store/sftp.py | 1 + 15 files changed, 54 insertions(+), 10 deletions(-) diff --git a/cumulus-store b/cumulus-store index ac58c28..93a10d7 100755 --- a/cumulus-store +++ b/cumulus-store @@ -32,6 +32,8 @@ # written to stdout, which is either "OK" (for success) or "ERR" (if an error # occurred). +from __future__ import division, print_function, unicode_literals + import os, sys, traceback # Automatically set Python path, based on script directory. This should be diff --git a/cumulus-sync b/cumulus-sync index 4953091..9f31a29 100755 --- a/cumulus-sync +++ b/cumulus-sync @@ -20,6 +20,8 @@ # Tool for copying cumulus archives from one source to another. +from __future__ import division, print_function, unicode_literals + import os, sys # Automatically set Python path, based on script directory. This should be diff --git a/cumulus-util b/cumulus-util index 669efc7..7233f8d 100755 --- a/cumulus-util +++ b/cumulus-util @@ -20,6 +20,8 @@ # Utility for managing Cumulus archives. +from __future__ import division, print_function, unicode_literals + import os, sys # Automatically set Python path, based on script directory. This should be diff --git a/python/cumulus/__init__.py b/python/cumulus/__init__.py index 8dc4c98..0e39d37 100644 --- a/python/cumulus/__init__.py +++ b/python/cumulus/__init__.py @@ -26,19 +26,29 @@ various parts of a Cumulus archive: - reading and maintaining the local object database """ +from __future__ import division, print_function, unicode_literals import hashlib import itertools import os import re import sqlite3 +import sys import tarfile import tempfile -import _thread +try: + import _thread +except ImportError: + import thread as _thread import cumulus.store import cumulus.store.file +if sys.version < '3': + StringTypes = (str, unicode) +else: + StringTypes = (str,) + # The largest supported snapshot format that can be understood. FORMAT_VERSION = (0, 11) # Cumulus Snapshot v0.11 @@ -264,7 +274,7 @@ class BackendWrapper(object): store may either be a Store object or URL. """ - if type(backend) in (str, str): + if type(backend) in StringTypes: if backend.find(":") >= 0: self._backend = cumulus.store.open(backend) else: @@ -295,7 +305,7 @@ class BackendWrapper(object): def prefetch_generic(self): """Calls scan on directories to prefetch file metadata.""" directories = set() - for typeinfo in list(SEARCH_PATHS.values()): + for typeinfo in SEARCH_PATHS.values(): directories.update(typeinfo.directories()) for d in directories: print("Prefetch", d) @@ -566,7 +576,7 @@ class MetadataItem: @staticmethod def decode_device(s): """Decode a device major/minor number.""" - (major, minor) = list(map(MetadataItem.decode_int, s.split("/"))) + (major, minor) = map(MetadataItem.decode_int, s.split("/")) return (major, minor) class Items: pass @@ -578,7 +588,7 @@ class MetadataItem: self.object_store = object_store self.keys = [] self.items = self.Items() - for (k, v) in list(fields.items()): + for (k, v) in fields.items(): if k in self.field_types: decoder = self.field_types[k] setattr(self.items, k, decoder(v)) diff --git a/python/cumulus/cmd_util.py b/python/cumulus/cmd_util.py index 0827cb0..fa761b6 100644 --- a/python/cumulus/cmd_util.py +++ b/python/cumulus/cmd_util.py @@ -18,6 +18,8 @@ """Implementation of the Cumulus command-line utility program.""" +from __future__ import division, print_function, unicode_literals + import getpass, os, stat, sys, time from optparse import OptionParser diff --git a/python/cumulus/config.py b/python/cumulus/config.py index 32c20da..aeb24ae 100644 --- a/python/cumulus/config.py +++ b/python/cumulus/config.py @@ -22,7 +22,12 @@ See the Cumulus documentation for a description of the configuration file format. """ -import configparser +from __future__ import division, print_function, unicode_literals + +try: + import configparser +except ImportError: + import ConfigParser as configparser import datetime import re diff --git a/python/cumulus/main.py b/python/cumulus/main.py index af50e26..8d4156c 100644 --- a/python/cumulus/main.py +++ b/python/cumulus/main.py @@ -22,6 +22,8 @@ This implements maintenance functions and is a wrapper around the C++ cumulus-backup program. """ +from __future__ import division, print_function, unicode_literals + import datetime import re import sys diff --git a/python/cumulus/metadata.py b/python/cumulus/metadata.py index ac92ec4..af668c1 100644 --- a/python/cumulus/metadata.py +++ b/python/cumulus/metadata.py @@ -23,6 +23,8 @@ underlying metadata log have been generated by a depth-first-search traversal of the filesystem, in sorted order. """ +from __future__ import division, print_function, unicode_literals + import cumulus class Metadata: diff --git a/python/cumulus/rebuild_database.py b/python/cumulus/rebuild_database.py index a4af640..3f391d8 100755 --- a/python/cumulus/rebuild_database.py +++ b/python/cumulus/rebuild_database.py @@ -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 @@ -275,7 +277,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)) diff --git a/python/cumulus/retention.py b/python/cumulus/retention.py index e447b54..210b257 100644 --- a/python/cumulus/retention.py +++ b/python/cumulus/retention.py @@ -23,6 +23,8 @@ for example keeping daily snapshots for short periods of time but retaining weekly snapshots going back further in time. """ +from __future__ import division, print_function, unicode_literals + import calendar import datetime diff --git a/python/cumulus/store/__init__.py b/python/cumulus/store/__init__.py index e368c57..e638bc5 100644 --- a/python/cumulus/store/__init__.py +++ b/python/cumulus/store/__init__.py @@ -16,7 +16,13 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -import exceptions, re, urllib.parse +from __future__ import division, print_function, unicode_literals + +import re +try: + from urllib.parse import urlparse +except ImportError: + from urlparse import urlparse type_patterns = { 'checksums': re.compile(r"^snapshot-(.*)\.(\w+)sums$"), @@ -24,7 +30,7 @@ type_patterns = { 'snapshots': re.compile(r"^snapshot-(.*)\.(cumulus|lbs)$") } -class NotFoundError(exceptions.KeyError): +class NotFoundError(KeyError): """Exception thrown when a file is not found in a repository.""" pass @@ -39,7 +45,7 @@ class Store (object): if cls != Store: return super(Store, cls).__new__(cls, url, **kw) (scheme, netloc, path, params, query, fragment) \ - = urllib.parse.urlparse(url) + = urlparse(url) try: cumulus = __import__('cumulus.store.%s' % scheme, globals()) diff --git a/python/cumulus/store/file.py b/python/cumulus/store/file.py index 6d23a58..6aea58b 100644 --- a/python/cumulus/store/file.py +++ b/python/cumulus/store/file.py @@ -16,6 +16,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import division, print_function, unicode_literals + import os, sys, tempfile import cumulus.store diff --git a/python/cumulus/store/ftp.py b/python/cumulus/store/ftp.py index ba2e4e7..3bd7104 100644 --- a/python/cumulus/store/ftp.py +++ b/python/cumulus/store/ftp.py @@ -16,6 +16,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +from __future__ import division, print_function, unicode_literals + from ftplib import FTP, all_errors, error_temp from netrc import netrc, NetrcParseError from cumulus.store import Store, type_patterns, NotFoundError diff --git a/python/cumulus/store/s3.py b/python/cumulus/store/s3.py index 4898583..ef40113 100644 --- a/python/cumulus/store/s3.py +++ b/python/cumulus/store/s3.py @@ -18,6 +18,8 @@ """Amazon S3 storage backend. Uses a URL of the form s3://BUCKET/PATH/.""" +from __future__ import division, print_function, unicode_literals + import os, sys, tempfile import boto from boto.exception import S3ResponseError diff --git a/python/cumulus/store/sftp.py b/python/cumulus/store/sftp.py index bbc4aff..6c8852c 100644 --- a/python/cumulus/store/sftp.py +++ b/python/cumulus/store/sftp.py @@ -18,6 +18,7 @@ #needed for python 2.5 +from __future__ import division, print_function, unicode_literals from paramiko import Transport, SFTPClient, RSAKey, DSSKey from paramiko.config import SSHConfig -- 2.20.1