Add python3 support
This commit is contained in:
1 parent
b7d2f3d8bd
commit
051976f560
1 file changed
+14
-6
+14
-6
@@ -1,8 +1,8 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf8 -*-
|
# -*- coding: utf8 -*-
|
||||||
from __future__ import division
|
from __future__ import division
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import ConfigParser
|
|
||||||
import logging
|
import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
import os.path
|
import os.path
|
||||||
@@ -12,7 +12,13 @@ import threading
|
|||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from collections import Counter, defaultdict
|
from collections import Counter, defaultdict
|
||||||
from cStringIO import StringIO
|
|
||||||
|
if sys.version_info[0] > 2:
|
||||||
|
import configparser
|
||||||
|
from io import StringIO
|
||||||
|
else:
|
||||||
|
import ConfigParser as configparser
|
||||||
|
from cStringIO import StringIO
|
||||||
|
|
||||||
# Global variables
|
# Global variables
|
||||||
config = None
|
config = None
|
||||||
@@ -50,7 +56,9 @@ def snapraid_command(command, args={}, ignore_errors=False):
|
|||||||
p = subprocess.Popen(
|
p = subprocess.Popen(
|
||||||
[config["snapraid"]["executable"], command] + arguments,
|
[config["snapraid"]["executable"], command] + arguments,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE,
|
||||||
|
universal_newlines=True
|
||||||
|
)
|
||||||
out = []
|
out = []
|
||||||
threads = [
|
threads = [
|
||||||
tee_log(p.stdout, out, logging.OUTPUT),
|
tee_log(p.stdout, out, logging.OUTPUT),
|
||||||
@@ -132,7 +140,7 @@ def finish(is_success):
|
|||||||
|
|
||||||
def load_config(args):
|
def load_config(args):
|
||||||
global config
|
global config
|
||||||
parser = ConfigParser.RawConfigParser()
|
parser = configparser.RawConfigParser()
|
||||||
parser.read(args.conf)
|
parser.read(args.conf)
|
||||||
sections = ["snapraid", "logging", "email", "smtp", "scrub"]
|
sections = ["snapraid", "logging", "email", "smtp", "scrub"]
|
||||||
config = dict((x, defaultdict(lambda: "")) for x in sections)
|
config = dict((x, defaultdict(lambda: "")) for x in sections)
|
||||||
@@ -213,14 +221,14 @@ def main():
|
|||||||
load_config(args)
|
load_config(args)
|
||||||
except:
|
except:
|
||||||
print("unexpected exception while loading config")
|
print("unexpected exception while loading config")
|
||||||
print traceback.format_exc()
|
print(traceback.format_exc())
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
setup_logger()
|
setup_logger()
|
||||||
except:
|
except:
|
||||||
print("unexpected exception while setting up logging")
|
print("unexpected exception while setting up logging")
|
||||||
print traceback.format_exc()
|
print(traceback.format_exc())
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in new issue
Block a user