Merge "removed "runthis" and other unused functions from utils.py"
This commit is contained in:
commit
cabd706b48
@ -22,13 +22,9 @@
|
||||
|
||||
|
||||
import ConfigParser
|
||||
import datetime
|
||||
import inspect
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from quantum.common import exceptions as exception
|
||||
from quantum.common import flags
|
||||
@ -79,67 +75,6 @@ def execute(cmd, process_input=None, addl_env=None, check_exit_code=True):
|
||||
return result
|
||||
|
||||
|
||||
def abspath(s):
|
||||
return os.path.join(os.path.dirname(__file__), s)
|
||||
|
||||
|
||||
# TODO(sirp): when/if utils is extracted to common library, we should remove
|
||||
# the argument's default.
|
||||
def default_flagfile(filename='quantum.conf'):
|
||||
for arg in sys.argv:
|
||||
if arg.find('flagfile') != -1:
|
||||
break
|
||||
else:
|
||||
if not os.path.isabs(filename):
|
||||
# turn relative filename into an absolute path
|
||||
script_dir = os.path.dirname(inspect.stack()[-1][1])
|
||||
filename = os.path.abspath(os.path.join(script_dir, filename))
|
||||
if os.path.exists(filename):
|
||||
sys.argv.insert(1, '--flagfile=%s' % filename)
|
||||
|
||||
|
||||
def debug(arg):
|
||||
logging.debug('debug in callback: %s', arg)
|
||||
return arg
|
||||
|
||||
|
||||
def runthis(prompt, cmd, check_exit_code=True):
|
||||
logging.debug("Running %s" % (cmd))
|
||||
exit_code = subprocess.call(cmd.split(" "))
|
||||
logging.debug(prompt % (exit_code))
|
||||
if check_exit_code and exit_code != 0:
|
||||
raise ProcessExecutionError(exit_code=exit_code,
|
||||
stdout=None,
|
||||
stderr=None,
|
||||
cmd=cmd)
|
||||
|
||||
|
||||
def generate_uid(topic, size=8):
|
||||
return '%s-%s' % (topic, ''.join(
|
||||
[random.choice('01234567890abcdefghijklmnopqrstuvwxyz')
|
||||
for x in xrange(size)]))
|
||||
|
||||
|
||||
def generate_mac():
|
||||
mac = [0x02, 0x16, 0x3e, random.randint(0x00, 0x7f),
|
||||
random.randint(0x00, 0xff), random.randint(0x00, 0xff)]
|
||||
return ':'.join(map(lambda x: "%02x" % x, mac))
|
||||
|
||||
|
||||
def last_octet(address):
|
||||
return int(address.split(".")[-1])
|
||||
|
||||
|
||||
def isotime(at=None):
|
||||
if not at:
|
||||
at = datetime.datetime.utcnow()
|
||||
return at.strftime(TIME_FORMAT)
|
||||
|
||||
|
||||
def parse_isotime(timestr):
|
||||
return datetime.datetime.strptime(timestr, TIME_FORMAT)
|
||||
|
||||
|
||||
def get_plugin_from_config(file="config.ini"):
|
||||
Config = ConfigParser.ConfigParser()
|
||||
Config.read(file)
|
||||
|
Loading…
Reference in New Issue
Block a user