if indegree == 0:
Q.append(ifname)
- while len(Q) != 0:
+ while len(Q):
# initialize queue
x = Q.popleft()
# Get dependents of x
dlist = dependency_graphs.get(x)
- if dlist == None or len(dlist) == 0:
+ if not dlist:
S.append(x)
continue
Q.append(rootifname)
- while len(Q) != 0:
+ while len(Q):
# initialize queue
x = Q.popleft()
# Get dependents of x
dlist = dependency_graph.get(x)
- if dlist == None or len(dlist) == 0:
+ if not dlist:
S.append(x)
continue
def is_config_present(self):
addr_method = self.get_addr_method()
- if addr_method is not None:
+ if addr_method:
if (addr_method.find('dhcp') != -1 or
addr_method.find('dhcp6') != -1):
return True
-
- if self.config is None:
+ if not self.config:
return False
-
- return (len(self.config) != 0)
+ else:
+ return True
def set_config_current(self, config_current):
self.config_current = config_current
def get_attr_value_first(self, attr_name):
config = self.get_config()
attr_value_list = config.get(attr_name)
- if attr_value_list is not None:
+ if attr_value_list:
return attr_value_list[0]
return None
config = self.get_config()
attr_value_list = config.get(attr_name)
- if attr_value_list is not None:
+ if attr_value_list:
try:
return attr_value_list[attr_index]
except:
return None
-
return None
def get_env(self):
- if self.env is None or len(self.env) == 0:
+ if not self.env:
self.generate_env()
return self.env
attr_env_name = 'IF_%s' %attr.upper()
env[attr_env_name] = attr_value[0]
- if len(env) > 0:
+ if env:
self.set_env(env)
def update_config(self, attr_name, attr_value):
- if self.config.get(attr_name) is None:
+ if not self.config.get(attr_name):
self.config[attr_name] = [attr_value]
else:
self.config[attr_name].append(attr_value)
%ifaceStatus.to_str(self.get_status()))
logger.info(indent + 'refcnt: %d' %self.get_refcnt())
d = self.get_lowerdevs()
- if d is not None:
+ if d:
logger.info(indent + 'lowerdevs: %s' %str(d))
else:
logger.info(indent + 'lowerdevs: None')
logger.info(indent + 'config: ')
config = self.get_config()
- if config is not None:
+ if config:
logger.info(indent + indent + str(config))
logger.info('}')
if self.get_auto():
outbuf += 'auto %s\n' %self.get_name()
outbuf += 'iface %s' %self.get_name()
- if self.get_addr_family() is not None:
+ if self.get_addr_family():
outbuf += ' %s' %self.get_addr_family()
-
- if self.get_addr_method() is not None:
+ if self.get_addr_method():
outbuf += ' %s' %self.get_addr_method()
-
outbuf += '\n'
-
config = self.get_config()
- if config is not None:
+ if config:
for cname, cvaluelist in config.items():
idx = 0
for cv in cvaluelist:
continue
dlist = module.get_dependent_ifacenames(ifaceobj,
self.ifaceobjdict.keys())
- if dlist and len(dlist):
+ if dlist:
self.logger.debug('%s: ' %ifaceobj.get_name() +
'got lowerifaces/dependents: %s' %str(dlist))
break
if ifaceobjs is None:
err_iface += ' ' + i
- if len(err_iface):
+ if err_iface:
self.logger.error('could not find interfaces: %s' %err_iface)
return -1
"""
# If the interface matches
- if excludepats and len(excludepats):
+ if excludepats:
for e in excludepats:
if re.search(e, ifacename):
return False
return False
# We check classes first
- if allow_classes and len(allow_classes):
+ if allow_classes:
for i in ifaceobjs:
- if len(i.get_classes()):
+ if i.get_classes():
common = Set([allow_classes]).intersection(
Set(i.get_classes()))
- if len(common):
+ if common:
return True
return False
filtered_ifacenames = [i for i in ifacenames
if self.iface_whitelisted(auto, allow_classes,
excludepats, i)]
- if not len(filtered_ifacenames):
+ if not filtered_ifacenames:
raise Exception('no ifaces found matching given allow lists')
self.populate_dependency_info(filtered_ifacenames, ops)
# for down we need to look at old state
self.logger.debug('Looking at old state ..')
- if len(self.statemanager.get_ifaceobjdict()):
+ if self.statemanager.get_ifaceobjdict():
self.read_old_iface_config()
- elif self.FORCE:
+ else:
# If no old state available
self.logger.info('old state not available. ' +
- 'Force option set. Loading new iface config file')
+ 'Loading new iface config file')
try:
self.read_iface_config()
except Exception, e:
raise Exception('error reading iface config (%s)' %str(e))
loaded_newconfig = True
- else:
- raise Exception('old state not available...aborting.' +
- ' try running with --force option')
if ifacenames:
# If iface list is given by the caller, always check if iface
raise Exception('all or some interfaces not found')
# if iface list not given by user, assume all from config file
- if ifacenames is None: ifacenames = self.ifaceobjdict.keys()
+ if not ifacenames: ifacenames = self.ifaceobjdict.keys()
# filter interfaces based on auto and allow classes
filtered_ifacenames = [i for i in ifacenames
if self.iface_whitelisted(auto, allow_classes,
excludepats, i)]
- if not len(filtered_ifacenames):
+ if not filtered_ifacenames:
raise Exception('no ifaces found matching given allow lists')
self.populate_dependency_info(filtered_ifacenames, ops)
filtered_ifacenames = [i for i in ifacenames
if self.iface_whitelisted(auto, allow_classes,
excludepats, i)]
- if len(filtered_ifacenames) == 0:
+ if not filtered_ifacenames:
raise Exception('no ifaces found matching ' +
'given allow lists')
new_ifaceobjdict = dict(self.get_ifaceobjdict())
new_dependency_graph = dict(self.get_dependency_graph())
- if len(self.statemanager.get_ifaceobjdict()) > 0:
+ if self.statemanager.get_ifaceobjdict():
# if old state is present, read old state and mark op for 'down'
# followed by 'up' aka: reload
# old interface config is read into self.ifaceobjdict
if ifacenames is None: ifacenames = self.ifaceobjdict.keys()
- if (op == 'reload' and ifacenames is not None and
- len(ifacenames) != 0):
+ if op == 'reload' and ifacenames:
filtered_ifacenames = [i for i in ifacenames
if self.iface_whitelisted(auto, allow_classes,
excludepats, i)]
continue
- if ifacedownlist is not None and len(ifacedownlist) > 0:
+ if ifacedownlist:
self.logger.info('Executing down on interfaces: %s'
%str(ifacedownlist))
# Generate dependency info for old config
print '\n'
if self.WITH_DEPENDS:
dlist = ifaceobj.get_lowerifaces()
- if not dlist or not len(dlist): continue
+ if not dlist: continue
self.print_ifaceobjs_pretty(dlist, format)
def print_ifaceobjs_pretty(self, ifacenames, format='native'):
if self.WITH_DEPENDS:
dlist = ifaceobj.get_lowerifaces()
- if not dlist or not len(dlist): continue
+ if not dlist: continue
self.print_ifaceobjs_pretty(dlist, format)
def dump_ifaceobjs(self, ifacenames):
if self.WITH_DEPENDS:
dlist = ifaceobj.get_lowerifaces()
- if not dlist or not len(dlist): continue
+ if not dlist: continue
self.print_ifaceobjscurr_pretty(dlist, format)
return ret
if self.WITH_DEPENDS:
dlist = ifaceobj.get_lowerifaces()
- if dlist is None or len(dlist) == 0: continue
+ if not dlist: continue
self.print_ifaceobjsrunning_pretty(dlist, format)
return
def ignore_line(self, line):
l = line.strip('\n ')
-
- if len(l) == 0 or l[0] == '#':
+ if not l or l[0] == '#':
return 1
-
return 0
def process_allow(self, lines, cur_idx, lineno):
classes = ifaceobj.set_classes(
self.get_allow_classes_for_iface(ifaceobj.get_name()))
- if classes is not None and len(classes) > 0:
+ if classes:
for c in classes:
ifaceobj.set_class(c)
def read_file(self, filename=None):
ifaces_file = filename
- if ifaces_file == None:
+ if not ifaces_file:
ifaces_file=self.ifaces_file
self.logger.debug('reading interfaces file %s' %ifaces_file)
# run through template engine
filedata = self.run_template_engine(filedata)
-
self.process_filedata(filedata)
-
def load(self, filename=None):
return self.read_file(filename)
#
import cPickle
from collections import OrderedDict
-from exceptions import *
import logging
-import pprint
import os
from iface import *
def read_saved_state(self, filename=None):
pickle_filename = filename
- if pickle_filename == None:
+ if not pickle_filename:
pickle_filename = self.state_file
if not os.path.exists(pickle_filename):
def save_state(self, ifaceobjs, filename=None):
pickle_filename = filename
- if pickle_filename == None:
+ if not pickle_filename:
pickle_filename = self.state_file
-
pickling.save(pickle_filename, ifaceobjs)
-
def compare_iface_state(ifaceobj1, ifaceobj2):
ifaceobj1_state = ifaceobj1.get_state()
ifaceobj2_state = ifaceobj2.get_state()
# compare config items
unmatched_item = set(ifaceobj.items()) ^ set(old_ifaceobj.items())
- if len(unmatched_item) != 0:
+ if unmatched_item:
return -1
return 0
def dump(self, ifacenames=None):
print 'iface state:'
- if ifacenames is not None and len(ifacenames) > 0:
+ if ifacenames:
for i in ifacenames:
ifaceobj = self.ifaces.get(i)
if ifaceobj is None:
import sys
import os
-import re
import argparse
from ifupdown.ifupdownmain import *
try:
iflist = args.iflist
- if len(args.iflist) == 0:
- iflist = None
logger.debug('creating ifupdown object ..')
cachearg=(False if (iflist or args.nocache or
args.perfmode or args.noact)
try:
iflist = args.iflist
- if len(args.iflist) == 0:
- iflist = None
if args.checkcurr:
qop='query-checkcurr'
elif args.running:
- if iflist is None:
+ if not iflist:
iflist = [i for i in os.listdir('/sys/class/net/')
if os.path.isdir('/sys/class/net/%s' %i)]
qop='query-running'
global logger
log_level = logging.WARNING
-
- if args.verbose == True:
+ if args.verbose:
log_level = logging.INFO
-
- if args.debug == True:
+ if args.debug:
log_level = logging.DEBUG
try:
update_ifquery_argparser(argparser)
elif op == 'reload':
update_ifreload_argparser(argparser)
-
return argparser.parse_args(argsv)
handlers = {'up' : run_up,
args = None
try:
op = None
- if re.search(r'ifup', argv[0]) != None:
+ if argv[0].endswith('ifup'):
op = 'up'
- elif re.search(r'ifdown', argv[0]) != None:
+ elif argv[0].endswith('ifdown'):
op = 'down'
- elif re.search(r'ifquery', argv[0]) != None:
+ elif argv[0].endswith('ifquery'):
op = 'query'
- elif re.search(r'ifreload', argv[0]) != None:
+ elif argv[0].endswith('ifreload'):
op = 'reload'
else:
print ('Unexpected executable.' +
exit(1)
# Command line arg parser
args = parse_args(argv[1:], op)
- if not len(args.iflist) and not args.all:
+ if not args.iflist and not args.all:
if op != 'query' or not args.syntaxhelp:
print '\'-a\' option or interface list are required'
exit(1)
- if len(args.iflist) and args.all:
+ if args.iflist and args.all:
print '\'-a\' option and interface list are mutually exclusive'
exit(1)
init(args)
handlers.get(op)(args)
except Exception, e:
- if str(e) == '':
+ if not str(e):
exit(1)
if args and args.debug:
raise