- py3k updates

This commit is contained in:
L.C. Rees 2012-05-31 23:31:27 -06:00
parent e0e3cd91cb
commit 140e8781df
32 changed files with 145 additions and 164 deletions

View File

@ -62,7 +62,7 @@ class Master(object):
'--log-level',
dest='log_level',
default='warning',
choices=salt.log.LOG_LEVELS.keys(),
choices=list(salt.log.LOG_LEVELS.keys()),
help='Console log level. One of %s. For the logfile settings '
'see the config file. Default: \'%%default\'.' %
', '.join([repr(l) for l in salt.log.LOG_LEVELS.keys()])
@ -93,7 +93,7 @@ class Master(object):
salt.log.setup_logfile_logger(
self.opts['log_file'], self.opts['log_level']
)
for name, level in self.opts['log_granular_levels'].iteritems():
for name, level in self.opts['log_granular_levels'].items():
salt.log.set_logger_level(name, level)
import logging
log = logging.getLogger(__name__)
@ -153,10 +153,10 @@ class Minion(object):
'--log-level',
dest='log_level',
default='warning',
choices=salt.log.LOG_LEVELS.keys(),
choices=list(salt.log.LOG_LEVELS.keys()),
help='Console log level. One of %s. For the logfile settings '
'see the config file. Default: \'%%default\'.' %
', '.join([repr(l) for l in salt.log.LOG_LEVELS.keys()]))
', '.join([repr(l) for l in list(salt.log.LOG_LEVELS.keys())]))
options, args = parser.parse_args()
log_format = '%(asctime)s,%(msecs)03.0f [%(name)-15s][%(levelname)-8s] %(message)s'
@ -181,7 +181,7 @@ class Minion(object):
salt.log.setup_logfile_logger(
self.opts['log_file'], self.opts['log_level']
)
for name, level in self.opts['log_granular_levels'].iteritems():
for name, level in self.opts['log_granular_levels'].items():
salt.log.set_logger_level(name, level)
import logging
# Late import so logging works correctly
@ -272,7 +272,7 @@ class Syndic(object):
'--log-level',
dest='log_level',
default='warning',
choices=salt.log.LOG_LEVELS.keys(),
choices=list(salt.log.LOG_LEVELS.keys()),
help=('Console log level. One of %s. For the logfile settings '
'see the config file. Default: \'%%default\'.' %
', '.join([repr(l) for l in salt.log.LOG_LEVELS.keys()]))
@ -300,7 +300,7 @@ class Syndic(object):
salt.log.setup_logfile_logger(
self.opts['log_file'], self.opts['log_level']
)
for name, level in self.opts['log_granular_levels'].iteritems():
for name, level in self.opts['log_granular_levels'].items():
salt.log.set_logger_level(name, level)
import logging

View File

@ -10,6 +10,11 @@ except ImportError:
# True if we are running on Python 3.
PY3 = sys.version_info[0] == 3
if PY3:
MAX_SIZE = sys.maxsize
else:
MAX_SIZE = sys.maxint
if PY3:
string_types = str,
integer_types = int,
@ -25,11 +30,6 @@ else:
binary_type = str
long = long
if PY3:
range = range
else:
range = xrange
if PY3:
def callable(obj):
return any('__call__' in klass.__dict__ for klass in type(obj).__mro__)
@ -124,26 +124,6 @@ else:
def url_unquote_native(v, encoding='utf-8', errors='replace'):
return native_(url_unquote_text(v, encoding, errors))
if PY3:
def iteritems_(d):
return d.items()
def itervalues_(d):
return d.values()
def iterkeys_(d):
return d.keys()
else:
def iteritems_(d):
return d.iteritems()
def itervalues_(d):
return d.itervalues()
def iterkeys_(d):
return d.iterkeys()
if PY3:
zip = zip
else:

View File

@ -113,7 +113,7 @@ class Batch(object):
# Gather returns until we get to the bottom
ncnt = 0
while True:
part = queue.next()
part = next(queue)
if part is None:
time.sleep(0.01)
ncnt += 1

View File

@ -2,10 +2,6 @@
Classes that manage file clients
'''
# Import python libs
try:
import BaseHTTPServer
except:
import http.server as BaseHTTPServer
import contextlib
import logging
import hashlib
@ -13,12 +9,6 @@ import os
import shutil
import string
import subprocess
try:
import urllib2
import urlparse
except:
import urllib.request as urllib2
import urllib.parse as urlparse
# Import third-party libs
import yaml
@ -32,6 +22,8 @@ import salt.loader
import salt.utils
import salt.payload
import salt.utils.templates
from salt._compat import (
URLError, HTTPError, BaseHTTPServer, urlparse, url_open)
log = logging.getLogger(__name__)
@ -293,7 +285,7 @@ class Client(object):
'''
Get a single file from a URL.
'''
url_data = urlparse.urlparse(url)
url_data = urlparse(url)
if url_data.scheme == 'salt':
return self.get_file(url, dest, makedirs, env)
if dest:
@ -315,16 +307,16 @@ class Client(object):
if not os.path.isdir(destdir):
os.makedirs(destdir)
try:
with contextlib.closing(urllib2.urlopen(url)) as srcfp:
with contextlib.closing(url_open(url)) as srcfp:
with open(dest, 'wb') as destfp:
shutil.copyfileobj(srcfp, destfp)
return dest
except urllib2.HTTPError as ex:
except HTTPError as ex:
raise MinionError('HTTP error {0} reading {1}: {3}'.format(
ex.code,
url,
*BaseHTTPServer.BaseHTTPRequestHandler.responses[ex.code]))
except urllib2.URLError as ex:
except URLError as ex:
raise MinionError('Error reading {0}: {1}'.format(url, ex.reason))
return ''
@ -340,7 +332,7 @@ class Client(object):
Cache a file then process it as a template
'''
kwargs['env'] = env
url_data = urlparse.urlparse(url)
url_data = urlparse(url)
sfn = self.cache_file(url, env)
if not os.path.exists(sfn):
return ''
@ -526,7 +518,7 @@ class LocalClient(Client):
if 'classes' in ndata:
if isinstance(ndata['classes'], dict):
ret[env] = ndata['classes'].keys()
ret[env] = list(ndata['classes'].keys())
elif isinstance(ndata['classes'], list):
ret[env] = ndata['classes']
else:

View File

@ -482,7 +482,7 @@ class AESFuncs(object):
if 'classes' in ndata:
if isinstance(ndata['classes'], dict):
ret[env] = ndata['classes'].keys()
ret[env] = list(ndata['classes'].keys())
elif isinstance(ndata['classes'], list):
ret[env] = ndata['classes']
else:

View File

@ -63,7 +63,7 @@ def detect_kwargs(func, args, data=None):
defaults = [] if defaults is None else defaults
starti = len(spec_args) - len(defaults)
kwarg_spec = set()
for ind in xrange(len(defaults)):
for ind in range(len(defaults)):
kwarg_spec.add(spec_args[starti])
starti += 1
_args = []

View File

@ -60,7 +60,7 @@ def __write_aliases_file(lines):
os.chmod(out.name, stat.S_IMODE(st.st_mode))
os.chown(out.name, st.st_uid, st.st_gid)
else:
os.chmod(out.name, 0644)
os.chmod(out.name, 0o644)
os.chown(out.name, 0, 0)
for (line_alias, line_target, line_comment) in lines:

View File

@ -45,7 +45,7 @@ def get_file(path, dest, env='base'):
salt '*' cp.get_file salt://path/to/file /minion/dest
'''
if not hash_file(path,env):
if not hash_file(path, env):
return ''
else:
client = salt.fileclient.get_file_client(__opts__)

View File

@ -252,7 +252,7 @@ def set_env(user, name, value=None):
else:
return jret
return 'present'
print value
print(value)
env = {'name': name, 'value': value}
lst['env'].append(env)
comdat = _write_cron(user, _render_tab(lst))

View File

@ -36,7 +36,7 @@ def command(settings_module,
for arg in args:
cmd = '{0} --{1}'.format(cmd, arg)
for key, value in kwargs.iteritems():
for key, value in kwargs.items():
if not key.startswith('__'):
cmd = '{0} --{1}={2}'.format(cmd, key, value)

View File

@ -12,7 +12,6 @@ Required python modules: libvirt
# Import Python Libs
import os
import shutil
import StringIO
import subprocess
from xml.dom import minidom
@ -28,6 +27,7 @@ import yaml
# Import Salt Modules
import salt.utils
from salt._compat import StringIO
VIRT_STATE_NAME_MAP = {0: "running",
1: "running",
@ -455,7 +455,7 @@ def get_disks(name):
salt '*' hyper.get_disks <vm name>
'''
disks = {}
doc = minidom.parse(StringIO.StringIO(get_conf(name)))
doc = minidom.parse(StringIO(get_conf(name)))
for elem in doc.getElementsByTagName('disk'):
sources = elem.getElementsByTagName('source')
targets = elem.getElementsByTagName('target')
@ -467,8 +467,8 @@ def get_disks(name):
target = targets[0]
else:
continue
if 'dev' in target.attributes.keys() \
and 'file' in source.attributes.keys():
if 'dev' in list(target.attributes.keys()) \
and 'file' in list(source.attributes.keys()):
disks[target.getAttribute('dev')] = \
{'file': source.getAttribute('file')}
for dev in disks:

View File

@ -34,7 +34,7 @@ def __virtual__():
'''
Only load this module if the mysql config is set
'''
if any(k.startswith('mysql.') for k in __opts__.keys()):
if any(k.startswith('mysql.') for k in list(__opts__.keys())):
if has_mysqldb:
return 'mysql'
return False
@ -116,7 +116,7 @@ def status():
db = connect()
cur = db.cursor()
cur.execute('SHOW STATUS')
for i in xrange(cur.rowcount):
for i in range(cur.rowcount):
row = cur.fetchone()
ret[row[0]] = row[1]
return ret

View File

@ -78,7 +78,7 @@ def db_list(user=None, host=None, port=None):
for line in lines[1:]:
line = [x.strip() for x in line.split("|")]
if not line[0] == "":
ret.append(zip(header[:-1], line[:-1]))
ret.append(list(zip(header[:-1], line[:-1])))
return ret

View File

@ -46,7 +46,7 @@ def top(num_processes=5, interval=3):
start_usage[p] = user + sys
time.sleep(interval)
usage = set()
for p, start in start_usage.iteritems():
for p, start in start_usage.items():
user, sys = p.get_cpu_times()
now = user + sys
diff = now - start
@ -62,9 +62,9 @@ def top(num_processes=5, interval=3):
info = {'cmd': cmdline,
'pid': p.pid,
'create_time': p.create_time}
for k, v in p.get_cpu_times()._asdict().iteritems():
for k, v in p.get_cpu_times()._asdict().items():
info['cpu.' + k] = v
for k, v in p.get_memory_info()._asdict().iteritems():
for k, v in p.get_memory_info()._asdict().items():
info['mem.' + k] = v
result.append(info)

View File

@ -11,7 +11,11 @@ try:
import _winreg
has_windows_modules = True
except ImportError:
has_windows_modules = False
try:
import winreg as _winreg
has_windows_modules = True
except ImportError:
has_windows_modules = False
import salt.utils
import logging
@ -19,6 +23,7 @@ from salt.exceptions import CommandExecutionError
log = logging.getLogger(__name__)
class Registry(object):
'''
Delay '_winreg' usage until this module is used

View File

@ -60,13 +60,13 @@ verbose : True
'''
# Import Python Libs
import urllib2
import json
import os
# Import Salt libs
import salt.utils
from salt._compat import string_types
from salt._compat import string_types, url_open
#sane defaults
__opts__ = {'solr.cores': [],
@ -244,13 +244,14 @@ def _http_request(url, request_timeout=None):
request_timeout = __opts__['solr.request_timeout']
if request_timeout is None:
data = json.load(urllib2.urlopen(url))
data = json.load(url_open(url))
else:
data = json.load(urllib2.urlopen(url, timeout=request_timeout))
data = json.load(url_open(url, timeout=request_timeout))
return _get_return_dict(True, data, [])
except Exception as e:
return _get_return_dict(False, {}, ["{0} : {1}".format(url, e)])
def _replication_request(command, host=None, core_name=None, params=[]):
'''
PRIVATE METHOD

View File

@ -1,6 +1,7 @@
'''
Support for SQLite3
'''
from __future__ import absolute_import
try:
import sqlite3

View File

@ -4,7 +4,8 @@ Manage users with the useradd command
import grp
import pwd
from salt._compat import string_types
from salt._compat import string_types, callable
def __virtual__():
@ -77,15 +78,15 @@ def add(name,
# user does exist, and B) running useradd again would result in a
# nonzero exit status and be interpreted as a False result.
if fullname:
chfullname(name,fullname)
chfullname(name, fullname)
if roomnumber:
chroomnumber(name,roomnumber)
chroomnumber(name, roomnumber)
if workphone:
chworkphone(name,workphone)
chworkphone(name, workphone)
if homephone:
chhomephone(name,homephone)
chhomephone(name, homephone)
if other:
chother(name,other)
chother(name, other)
return True
@ -236,7 +237,7 @@ def chfullname(name, fullname):
pre_info = info(name)
if fullname == pre_info['fullname']:
return True
cmd = 'chfn -f "{0}" {1}'.format(fullname,name)
cmd = 'chfn -f "{0}" {1}'.format(fullname, name)
__salt__['cmd.run'](cmd)
post_info = info(name)
if post_info['fullname'] != pre_info['fullname']:
@ -255,7 +256,7 @@ def chroomnumber(name, roomnumber):
pre_info = info(name)
if roomnumber == pre_info['roomnumber']:
return True
cmd = 'chfn -r "{0}" {1}'.format(roomnumber,name)
cmd = 'chfn -r "{0}" {1}'.format(roomnumber, name)
__salt__['cmd.run'](cmd)
post_info = info(name)
if post_info['roomnumber'] != pre_info['roomnumber']:
@ -274,7 +275,7 @@ def chworkphone(name, workphone):
pre_info = info(name)
if workphone == pre_info['workphone']:
return True
cmd = 'chfn -w "{0}" {1}'.format(workphone,name)
cmd = 'chfn -w "{0}" {1}'.format(workphone, name)
__salt__['cmd.run'](cmd)
post_info = info(name)
if post_info['workphone'] != pre_info['workphone']:
@ -293,7 +294,7 @@ def chhomephone(name, homephone):
pre_info = info(name)
if homephone == pre_info['homephone']:
return True
cmd = 'chfn -h "{0}" {1}'.format(homephone,name)
cmd = 'chfn -h "{0}" {1}'.format(homephone, name)
__salt__['cmd.run'](cmd)
post_info = info(name)
if post_info['homephone'] != pre_info['homephone']:
@ -312,7 +313,7 @@ def chother(name, other):
pre_info = info(name)
if other == pre_info['other']:
return True
cmd = 'chfn -o "{0}" {1}'.format(other,name)
cmd = 'chfn -o "{0}" {1}'.format(other, name)
__salt__['cmd.run'](cmd)
post_info = info(name)
if post_info['other'] != pre_info['other']:
@ -343,11 +344,11 @@ def info(name):
# Assign empty strings for any unspecified GECOS fields
while len(gecos_field) < 5:
gecos_field.append('')
ret['fullname'] = gecos_field[0]
ret['fullname'] = gecos_field[0]
ret['roomnumber'] = gecos_field[1]
ret['workphone'] = gecos_field[2]
ret['homephone'] = gecos_field[3]
ret['other'] = gecos_field[4]
ret['workphone'] = gecos_field[2]
ret['homephone'] = gecos_field[3]
ret['other'] = gecos_field[4]
except KeyError:
ret['gid'] = ''
ret['groups'] = ''

View File

@ -9,20 +9,19 @@ Required python modules: libvirt
import os
import re
import shutil
import StringIO
import subprocess
from xml.dom import minidom
from salt.exceptions import CommandExecutionError
# Import Third Party Libs
try:
import libvirt
has_libvirt = True
except ImportError:
has_libvirt = False
# Import Third Party Libs
import yaml
from salt._compat import StringIO
from salt.exceptions import CommandExecutionError
VIRT_STATE_NAME_MAP = {0: "running",
1: "running",
@ -210,7 +209,7 @@ def get_nics(vm_):
salt '*' virt.get_nics <vm name>
'''
nics = {}
doc = minidom.parse(StringIO.StringIO(get_xml(vm_)))
doc = minidom.parse(StringIO(get_xml(vm_)))
for node in doc.getElementsByTagName("devices"):
i_nodes = node.getElementsByTagName("interface")
for i_node in i_nodes:
@ -249,7 +248,7 @@ def get_macs(vm_):
salt '*' virt.get_macs <vm name>
'''
macs = []
doc = minidom.parse(StringIO.StringIO(get_xml(vm_)))
doc = minidom.parse(StringIO(get_xml(vm_)))
for node in doc.getElementsByTagName("devices"):
i_nodes = node.getElementsByTagName("interface")
for i_node in i_nodes:
@ -271,7 +270,7 @@ def get_graphics(vm_):
'port': 'None',
'type': 'vnc'}
xml = get_xml(vm_)
ssock = StringIO.StringIO(xml)
ssock = StringIO(xml)
doc = minidom.parse(ssock)
for node in doc.getElementsByTagName("domain"):
g_nodes = node.getElementsByTagName("graphics")
@ -290,7 +289,7 @@ def get_disks(vm_):
salt '*' virt.get_disks <vm name>
'''
disks = {}
doc = minidom.parse(StringIO.StringIO(get_xml(vm_)))
doc = minidom.parse(StringIO(get_xml(vm_)))
for elem in doc.getElementsByTagName('disk'):
sources = elem.getElementsByTagName('source')
targets = elem.getElementsByTagName('target')
@ -302,13 +301,13 @@ def get_disks(vm_):
target = targets[0]
else:
continue
if 'dev' in target.attributes.keys() \
and 'file' in source.attributes.keys():
disks[target.getAttribute('dev')] = \
{'file': source.getAttribute('file')}
if 'dev' in list(target.attributes.keys()) \
and 'file' in list(source.attributes.keys()):
disks[target.getAttribute('dev')] = {
'file': source.getAttribute('file')}
for dev in disks:
try:
disks[dev].update(yaml.safe_load(subprocess.Popen('qemu-img info ' \
disks[dev].update(yaml.safe_load(subprocess.Popen('qemu-img info '
+ disks[dev]['file'],
shell=True,
stdout=subprocess.PIPE).communicate()[0]))

View File

@ -222,7 +222,7 @@ def interfaces():
configstart = configstart + 1
continue
for iface in ifaces:
for key, val in iface.iteritems():
for key, val in iface.items():
item = {}
itemdict = {'Physical Address': 'hwaddr',
'IPv4 Address': 'ipaddr',
@ -230,7 +230,7 @@ def interfaces():
'Subnet Mask': 'netmask',
}
item['broadcast'] = None
for k, v in itemdict.iteritems():
for k, v in itemdict.items():
if k in val:
item[v] = val[k].rstrip('(Preferred)')
if 'IPv4 Address' in val:

View File

@ -88,8 +88,8 @@ def list_pkgs(*args):
pythoncom.CoInitialize()
if len(args) == 0:
pkgs = dict(
_get_reg_software().items() +
_get_msi_software().items())
list(_get_reg_software().items()) +
list(_get_msi_software().items()))
else:
# get package version for each package in *args
pkgs = {}
@ -106,9 +106,9 @@ def _search_software(target):
'''
search_results = {}
software = dict(
_get_reg_software().items() +
_get_msi_software().items())
for key, value in software.iteritems():
list(_get_reg_software().items()) +
list(_get_msi_software().items()))
for key, value in software.items():
if key is not None:
if target.lower() in key.lower():
search_results[key] = value
@ -153,9 +153,9 @@ def _get_reg_software():
]
#attempt to corral the wild west of the multiple ways to install
#software in windows
reg_entries = dict(_get_user_keys().items() +
_get_machine_keys().items())
for reg_hive, reg_keys in reg_entries.iteritems():
reg_entries = dict(list(_get_user_keys().items()) +
list(_get_machine_keys().items()))
for reg_hive, reg_keys in reg_entries.items():
for reg_key in reg_keys:
try:
reg_handle = win32api.RegOpenKeyEx(

View File

@ -143,7 +143,7 @@ class Pillar(object):
'''
envs = set(['base'])
if 'file_roots' in self.opts:
envs.update(self.opts['file_roots'].keys())
envs.update(list(self.opts['file_roots'].keys()))
return envs
def get_tops(self):

View File

@ -52,7 +52,7 @@ def returner(ret):
columns = {'fun': ret['fun'],
'id': ret['id']}
if isinstance(ret['return'], dict):
for key, value in ret['return'].iteritems():
for key, value in ret['return'].items():
columns['return.%s' % (key,)] = str(value)
else:
columns['return'] = str(ret['return'])

View File

@ -29,7 +29,7 @@ import salt.loader
import salt.minion
import salt.pillar
import salt.fileclient
from salt._compat import string_types
from salt._compat import string_types, callable
from salt.template import (
compile_template,
@ -68,8 +68,9 @@ def trim_req(req):
'''
Trim any function off of a requisite
'''
if '.' in req.keys()[0]:
return {req.keys()[0].split('.')[0]: req[req.keys()[0]]}
reqfirst = list(req.keys())[0]
if '.' in reqfirst:
return {reqfirst.split('.')[0]: req[reqfirst]}
return req
@ -87,7 +88,7 @@ def state_args(id_, state, high):
continue
if len(item) != 1:
continue
args.add(item.keys()[0])
args.add(list(item.keys())[0])
return args
@ -110,7 +111,7 @@ def find_name(name, state, high):
continue
if len(arg) != 1:
continue
if arg[arg.keys()[0]] == name:
if arg[list(arg.keys())[0]] == name:
ext_id = nid
return ext_id
@ -132,8 +133,8 @@ def format_log(ret):
if isinstance(chg['diff'], string_types):
msg = 'File changed:\n{0}'.format(
chg['diff'])
if isinstance(chg[chg.keys()[0]], dict):
if 'new' in chg[chg.keys()[0]]:
if isinstance(chg[list(chg.keys())[0]], dict):
if 'new' in chg[list(chg.keys())[0]]:
# This is the return data from a package install
msg = 'Installed Packages:\n'
for pkg in chg:
@ -352,8 +353,8 @@ class State(object):
if reqdec:
for req in data[reqdec]:
if data['state'] == req.keys()[0]:
if fnmatch.fnmatch(data['name'], req[req.keys()[0]]) \
or fnmatch.fnmatch(data['__id__'], req[req.keys()[0]]):
if fnmatch.fnmatch(data['name'], req[list(req.keys())[0]]) \
or fnmatch.fnmatch(data['__id__'], req[list(req.keys())[0]]):
err = ('Recursive require detected in SLS {0} for'
' require {1} in ID {2}').format(
data['__sls__'],
@ -412,9 +413,9 @@ class State(object):
#
# Add the requires to the reqs dict and check them
# all for recursive requisites.
if arg.keys()[0] == 'require' \
or arg.keys()[0] == 'watch':
if not isinstance(arg[arg.keys()[0]], list):
if list(arg.keys())[0] == 'require' \
or list(arg.keys())[0] == 'watch':
if not isinstance(arg[list(arg.keys())[0]], list):
errors.append(('The require or watch'
' statement in state "{0}" in sls "{1}" needs'
' to be formed as a list').format(
@ -425,7 +426,7 @@ class State(object):
# list are all single key dicts.
else:
reqs[name] = {}
for req in arg[arg.keys()[0]]:
for req in arg[list(arg.keys())[0]]:
if not isinstance(req, dict):
err = ('Requisite declaration {0}'
' in SLS {1} is not formed as a'
@ -434,7 +435,7 @@ class State(object):
body['__sls__'])
errors.append(err)
continue
req_key = req.keys()[0]
req_key = list(req.keys())[0]
req_val = req[req_key]
if not ishashable(req_val):
errors.append((
@ -456,7 +457,7 @@ class State(object):
)
errors.append(err)
# Make sure that there is only one key in the dict
if len(arg.keys()) != 1:
if len(list(arg.keys())) != 1:
errors.append(('Multiple dictionaries defined'
' in argument of state "{0}" in sls {1}').format(
name,
@ -642,13 +643,13 @@ class State(object):
if isinstance(arg, dict) and \
isinstance(high[name][state][hind], dict):
# It is an option, make sure the options match
if (arg.keys()[0] ==
high[name][state][hind].keys()[0]):
if (list(arg.keys())[0] ==
list(high[name][state][hind].keys())[0]):
# They match, check if the option is a
# watch or require, append, otherwise
# replace
if arg.keys()[0] == 'require' or \
arg.keys()[0] == 'watch':
if list(arg.keys())[0] == 'require' or \
list(arg.keys())[0] == 'watch':
# Extend the list
(high[name][state][hind][arg.keys()[0]]
.extend(arg[arg.keys()[0]]))
@ -681,7 +682,7 @@ class State(object):
# How did we get this far?
continue
# Split out the components
key = arg.keys()[0]
key = list(arg.keys())[0]
if not key in req_in:
continue
rkey = key.split('_')[0]
@ -697,7 +698,7 @@ class State(object):
if not _state in extend[name]:
extend[name][_state] = []
for ind in range(len(extend[name][_state])):
if extend[name][_state][ind].keys()[0] == rkey:
if list(extend[name][_state][ind].keys())[0] == rkey:
# Extending again
extend[name][_state][ind][rkey].append(
{state: id_}
@ -718,7 +719,7 @@ class State(object):
continue
if len(ind) < 1:
continue
_state = ind.keys()[0]
_state = list(ind.keys())[0]
name = ind[_state]
if key == 'use_in':
# Add the running states args to the
@ -737,7 +738,7 @@ class State(object):
continue
if len(arg) != 1:
continue
if arg.keys()[0] in ignore_args:
if list(arg.keys())[0] in ignore_args:
continue
extend[ext_id][_state].append(arg)
continue
@ -758,7 +759,7 @@ class State(object):
continue
if len(arg) != 1:
continue
if arg.keys()[0] in ignore_args:
if list(arg.keys())[0] in ignore_args:
continue
extend[id_][state].append(arg)
continue
@ -768,7 +769,7 @@ class State(object):
if not _state in extend[name]:
extend[name][_state] = []
for ind in range(len(extend[name][_state])):
if extend[name][_state][ind].keys()[0] == rkey:
if list(extend[name][_state][ind].keys())[0] == rkey:
# Extending again
extend[name][_state][ind][rkey].append(
{state: id_}
@ -858,8 +859,7 @@ class State(object):
present = True
if not present:
return 'met'
reqs = {'require': [],
'watch': []}
reqs = {'require': [], 'watch': []}
status = 'unmet'
for r_state in reqs.keys():
if r_state in low:
@ -867,7 +867,7 @@ class State(object):
req = trim_req(req)
found = False
for chunk in chunks:
req_key = req.keys()[0]
req_key = list(req.keys())[0]
req_val = req[req_key]
if (fnmatch.fnmatch(chunk['name'], req_val) or
fnmatch.fnmatch(chunk['__id__'], req_val)):
@ -920,11 +920,11 @@ class State(object):
req = trim_req(req)
found = False
for chunk in chunks:
req_key = req.keys()[0]
req_key = list(req.keys())[0]
req_val = req[req_key]
if (fnmatch.fnmatch(chunk['name'], req_val) or
fnmatch.fnmatch(chunk['__id__'], req_val)):
if chunk['state'] == req.keys()[0]:
if chunk['state'] == req_key:
reqs.append(chunk)
found = True
if not found:
@ -1070,7 +1070,7 @@ class BaseHighState(object):
'''
envs = set(['base'])
if 'file_roots' in self.opts:
envs.update(self.opts['file_roots'].keys())
envs.update(list(self.opts['file_roots'].keys()))
return envs
def get_tops(self):
@ -1258,7 +1258,7 @@ class BaseHighState(object):
'''
if not self.opts['autoload_dynamic_modules']:
return
syncd = self.state.functions['saltutil.sync_all'](matches.keys())
syncd = self.state.functions['saltutil.sync_all'](list(matches.keys()))
if syncd[2]:
self.opts['grains'] = salt.loader.grains(self.opts)
faux = {'state': 'file', 'fun': 'recurse'}

View File

@ -83,12 +83,12 @@ import difflib
import hashlib
import logging
import tempfile
import urlparse
import copy
# Import Salt libs
import salt.utils.templates
from salt._compat import string_types
from salt._compat import string_types, urlparse
logger = logging.getLogger(__name__)
@ -231,7 +231,7 @@ def _source_list(source, source_hash, env):
continue
single_src = single.keys()[0]
single_hash = single[single_src]
proto = urlparse.urlparse(single_src).scheme
proto = urlparse(single_src).scheme
if proto == 'salt':
if single_src in mfiles:
source = single_src
@ -311,13 +311,13 @@ def _get_managed(
else:
# Copy the file down if there is a source
if source:
if urlparse.urlparse(source).scheme == 'salt':
if urlparse(source).scheme == 'salt':
source_sum = __salt__['cp.hash_file'](source, env)
if not source_sum:
return '', {}, 'Source file {0} not found'.format(source)
elif source_hash:
protos = ['salt', 'http', 'ftp']
if urlparse.urlparse(source_hash).scheme in protos:
if urlparse(source_hash).scheme in protos:
# The sourc_hash is a file on a server
hash_fn = __salt__['cp.cache_file'](source_hash)
if not hash_fn:
@ -1127,13 +1127,13 @@ def directory(name,
'user {0} (user does not ' \
'exist)'.format(user)
# Remove 'user' from list of recurse targets
targets = filter(lambda x: x != 'user', targets)
targets = list(x for x in targets if x != 'user')
else:
ret['result'] = False
ret['comment'] = 'user not specified, but configured as ' \
'a target for recursive ownership management'
# Remove 'user' from list of recurse targets
targets = filter(lambda x: x != 'user', targets)
targets = list(x for x in targets if x != 'user')
if 'group' in targets:
if group:
gid = __salt__['file.group_to_gid'](group)
@ -1143,13 +1143,13 @@ def directory(name,
ret['comment'] = 'Failed to enforce group ownership ' \
'for group {0}'.format(group, user)
# Remove 'group' from list of recurse targets
targets = filter(lambda x: x != 'group', targets)
targets = list(x for x in targets if x != 'group')
else:
ret['result'] = False
ret['comment'] = 'group not specified, but configured ' \
'as a target for recursive ownership management'
# Remove 'group' from list of recurse targets
targets = filter(lambda x: x != 'group', targets)
targets = list(x for x in targets if x != 'group')
needs_fixed = {}
if targets:

View File

@ -163,7 +163,7 @@ def managed(
elif old != new:
diff = difflib.unified_diff(old, new)
ret['changes']['interface'] = ''.join(diff)
except AttributeError, error:
except AttributeError as error:
ret['result'] = False
ret['comment'] = error.message
return ret
@ -178,7 +178,7 @@ def managed(
elif old != new:
diff = difflib.unified_diff(old, new)
ret['changes']['bond'] = ''.join(diff)
except AttributeError, error:
except AttributeError as error:
#TODO Add a way of reversing the interface changes.
ret['result'] = False
ret['comment'] = error.message
@ -190,7 +190,7 @@ def managed(
__salt__['ip.up'](name)
else:
__salt__['ip.down'](name)
except Exception, error:
except Exception as error:
ret['result'] = False
ret['comment'] = error.message
return ret

View File

@ -98,8 +98,8 @@ def installed(name,
runas=user,
cwd=cwd):
pkg_list = __salt__['pip.list'](name, bin_env, runas=user, cwd=cwd)
version = pkg_list.values()[0]
pkg_name = pkg_list.keys()[0]
version = list(pkg_list.values())[0]
pkg_name = list(pkg_list.keys())[0]
ret['result'] = True
ret['changes']["{0}=={1}".format(pkg_name, version)] = 'Installed'
ret['comment'] = 'Package was successfully installed'

View File

@ -1,6 +1,7 @@
'''
Some of the utils used by salt
'''
from __future__ import absolute_import
# Import Python libs
import os
@ -118,7 +119,7 @@ def daemonize():
0)
sys.exit(0)
else:
import saltminionservice
from . import saltminionservice
import win32serviceutil
import win32service
import winerror
@ -335,7 +336,7 @@ def required_module_list(docstring=None):
ret = []
txt = 'Required python modules: '
data = docstring.split('\n') if docstring else []
mod_list = filter(lambda x: x.startswith(txt), data)
mod_list = list(x for x in data if x.startswith(txt))
if not mod_list:
return []
modules = mod_list[0].replace(txt, '').split(', ')

View File

@ -87,6 +87,7 @@ import stat
import sys
import time
from salt._compat import MAX_SIZE
# Set up logger
log = logging.getLogger(__name__)
@ -185,7 +186,7 @@ def _parse_size(value):
max_size = num
elif style == '+':
min_size = num
max_size = sys.maxint
max_size = MAX_SIZE
else:
min_size = num
max_size = num + multiplier - 1
@ -494,7 +495,7 @@ class Finder(object):
criteria = {_REQUIRES_PATH: list(),
_REQUIRES_STAT: list(),
_REQUIRES_CONTENTS: list()}
for key, value in options.iteritems():
for key, value in options.items():
if key.startswith('_'):
# this is a passthrough object, continue
continue
@ -573,7 +574,7 @@ if __name__ == '__main__':
criteria[key] = value
try:
f = Finder(criteria)
except ValueError, ex:
except ValueError as ex:
sys.stderr.write('error: {0}\n'.format(ex))
sys.exit(1)

View File

@ -1,4 +1,4 @@
from winservice import Service, instart
from salt.utils.winservice import Service, instart
import win32serviceutil
import win32service
import winerror

View File

@ -97,7 +97,7 @@ class Swarm(object):
'''
Prepare the confs set
'''
for ind in xrange(self.opts['minions']):
for ind in range(self.opts['minions']):
self.mkconf()
def clean_configs(self):

View File

@ -49,7 +49,7 @@ class TestRvmState(TestCase):
'jruby-1.6.5.1': True,
'jruby-1.6': False,
'jruby-1.9.3': False,
'jruby-1.9.3-p125': False}.iteritems():
'jruby-1.9.3-p125': False}.items():
ret = rvm._check_ruby({'changes': {}, 'result': False}, ruby)
self.assertEqual(result, ret['result'])