@@ -86,20 +86,20 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, | |||
if e.errno == errno.ENOENT: | |||
continue | |||
if verbose: | |||
print("unable to run %s" % dispcmd) | |||
print(("unable to run %s" % dispcmd)) | |||
print(e) | |||
return None, None | |||
else: | |||
if verbose: | |||
print("unable to find command, tried %s" % (commands,)) | |||
print(("unable to find command, tried %s" % (commands,))) | |||
return None, None | |||
stdout = p.communicate()[0].strip() | |||
if sys.version_info[0] >= 3: | |||
stdout = stdout.decode() | |||
if p.returncode != 0: | |||
if verbose: | |||
print("unable to run %s (error)" % dispcmd) | |||
print("stdout was %s" % stdout) | |||
print(("unable to run %s (error)" % dispcmd)) | |||
print(("stdout was %s" % stdout)) | |||
return None, p.returncode | |||
return stdout, p.returncode | |||
@@ -124,8 +124,8 @@ def versions_from_parentdir(parentdir_prefix, root, verbose): | |||
root = os.path.dirname(root) # up a level | |||
if verbose: | |||
print("Tried directories %s but none started with prefix %s" % | |||
(str(rootdirs), parentdir_prefix)) | |||
print(("Tried directories %s but none started with prefix %s" % | |||
(str(rootdirs), parentdir_prefix))) | |||
raise NotThisMethod("rootdir doesn't start with parentdir_prefix") | |||
@@ -192,15 +192,15 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): | |||
# "stabilization", as well as "HEAD" and "master". | |||
tags = set([r for r in refs if re.search(r'\d', r)]) | |||
if verbose: | |||
print("discarding '%s', no digits" % ",".join(refs - tags)) | |||
print(("discarding '%s', no digits" % ",".join(refs - tags))) | |||
if verbose: | |||
print("likely tags: %s" % ",".join(sorted(tags))) | |||
print(("likely tags: %s" % ",".join(sorted(tags)))) | |||
for ref in sorted(tags): | |||
# sorting will prefer e.g. "2.0" over "2.0rc1" | |||
if ref.startswith(tag_prefix): | |||
r = ref[len(tag_prefix):] | |||
if verbose: | |||
print("picking %s" % r) | |||
print(("picking %s" % r)) | |||
return {"version": r, | |||
"full-revisionid": keywords["full"].strip(), | |||
"dirty": False, "error": None, | |||
@@ -229,7 +229,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): | |||
hide_stderr=True) | |||
if rc != 0: | |||
if verbose: | |||
print("Directory %s not under git control" % root) | |||
print(("Directory %s not under git control" % root)) | |||
raise NotThisMethod("'git rev-parse --git-dir' returned error") | |||
# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty] | |||
@@ -278,7 +278,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): | |||
if not full_tag.startswith(tag_prefix): | |||
if verbose: | |||
fmt = "tag '%s' doesn't start with prefix '%s'" | |||
print(fmt % (full_tag, tag_prefix)) | |||
print((fmt % (full_tag, tag_prefix))) | |||
pieces["error"] = ("tag '%s' doesn't start with prefix '%s'" | |||
% (full_tag, tag_prefix)) | |||
return pieces | |||
@@ -4,7 +4,7 @@ from nilmdb.utils.printf import * | |||
import threading | |||
import subprocess | |||
import cStringIO | |||
import io | |||
import sys | |||
import os | |||
import signal | |||
@@ -23,7 +23,7 @@ class LogReceiver(object): | |||
and stores them locally.""" | |||
def __init__(self, pipe): | |||
self.pipe = pipe | |||
self.log = cStringIO.StringIO() | |||
self.log = io.StringIO() | |||
self.thread = threading.Thread(target = self.run) | |||
self.thread.start() | |||
@@ -39,7 +39,7 @@ class LogReceiver(object): | |||
return self.log.getvalue() | |||
def clear(self): | |||
self.log = cStringIO.StringIO() | |||
self.log = io.StringIO() | |||
class Process(object): | |||
"""Spawn and manage a subprocess, and capture its output.""" | |||
@@ -197,7 +197,7 @@ class ProcessManager(object): | |||
def _atexit(self): | |||
# Kill remaining processes, remove their dirs | |||
for pid in self.processes.keys(): | |||
for pid in list(self.processes.keys()): | |||
try: | |||
self.processes[pid].terminate() | |||
del self.processes[pid] | |||
@@ -207,7 +207,7 @@ class ProcessManager(object): | |||
pass | |||
def __iter__(self): | |||
return iter(self.processes.keys()) | |||
return iter(list(self.processes.keys())) | |||
def __getitem__(self, key): | |||
return self.processes[key] | |||
@@ -39,20 +39,20 @@ def main(): | |||
# Print info | |||
if not args.quiet: | |||
print "NilmRun version: %s" % nilmrun.__version__ | |||
print ("Note: This server does not do any authentication! " + | |||
"Anyone who can connect can run arbitrary commands.") | |||
print("NilmRun version: %s" % nilmrun.__version__) | |||
print(("Note: This server does not do any authentication! " + | |||
"Anyone who can connect can run arbitrary commands.")) | |||
if args.address == '0.0.0.0' or args.address == '::': | |||
host = socket.getfqdn() | |||
else: | |||
host = args.address | |||
print "Server URL: http://%s:%d/" % ( host, args.port) | |||
print "----" | |||
print("Server URL: http://%s:%d/" % ( host, args.port)) | |||
print("----") | |||
server.start(blocking = True) | |||
if not args.quiet: | |||
print "Shutting down" | |||
print("Shutting down") | |||
if __name__ == "__main__": | |||
main() |
@@ -37,7 +37,7 @@ def main(): | |||
# If we're detaching, just print the PID | |||
if args.detach: | |||
print pid | |||
print(pid) | |||
raise SystemExit(0) | |||
# Otherwise, watch the log output, and kill the process when it's done | |||
@@ -15,14 +15,15 @@ import distutils.version | |||
import os | |||
import sys | |||
import threading | |||
import cStringIO | |||
import io | |||
import simplejson as json | |||
import unittest | |||
import warnings | |||
import time | |||
import re | |||
import urllib2 | |||
from urllib2 import urlopen, HTTPError | |||
import urllib.request, urllib.error, urllib.parse | |||
from urllib.request import urlopen | |||
from urllib.error import HTTPError | |||
import requests | |||
import pprint | |||
import textwrap | |||
@@ -391,12 +392,12 @@ class TestClient(object): | |||
# Unicode should work | |||
verify("echo -n hello", "hello") | |||
verify(u"echo -n ☠", u"☠") | |||
verify("echo -ne \\\\xe2\\\\x98\\\\xa0", u"☠") | |||
verify("echo -n ☠", "☠") | |||
verify("echo -ne \\\\xe2\\\\x98\\\\xa0", "☠") | |||
# Programs that spit out invalid UTF-8 should get replacement | |||
# markers | |||
verify("echo -ne \\\\xae", u"\ufffd") | |||
verify("echo -ne \\\\xae", "\ufffd") | |||
def test_client_11_atexit(self): | |||
# Leave a directory and running process behind, for the atexit | |||
@@ -1,7 +1,7 @@ | |||
# Just some helpers for test functions | |||
def myrepr(x): | |||
if isinstance(x, basestring): | |||
if isinstance(x, str): | |||
return '"' + x + '"' | |||
else: | |||
return repr(x) | |||
@@ -276,11 +276,11 @@ https://creativecommons.org/publicdomain/zero/1.0/ . | |||
""" | |||
from __future__ import print_function | |||
try: | |||
import configparser | |||
except ImportError: | |||
import ConfigParser as configparser | |||
import configparser as configparser | |||
import errno | |||
import json | |||
import os | |||