Fixing up gunthers new adjustments.

This commit is contained in:
Joshua Harlow
2012-02-06 11:20:24 -08:00
parent 0f2b5951fb
commit 872c41482f
5 changed files with 66 additions and 39 deletions

View File

@@ -84,10 +84,11 @@ class HorizonInstaller(comp.PythonInstallComponent):
return places
def _get_symlinks(self):
return {
comp.PythonInstallComponent._get_target_config_name(self, HORIZON_APACHE_CONF):\
sh.joinpths(*HORIZON_APACHE_TGT)
}
src = self._get_target_config_name(HORIZON_APACHE_CONF)
tgt = sh.joinpths(*HORIZON_APACHE_TGT)
links = dict()
links[src] = tgt
return links
def _check_ug(self):
(user, group) = self._get_apache_user_group()

View File

@@ -20,15 +20,29 @@ import re
from devstack import log as logging
from devstack import shell as sh
from devstack import env
LOG = logging.getLogger("devstack.downloader")
EXT_REG = re.compile(r"^(.*?)\.git\s*$", re.IGNORECASE)
GIT_MASTER_BRANCH = "master"
GIT_CACHE_DIR_ENV = "GIT_CACHE_DIR"
def _git_cache_download(storewhere, uri, branch=None):
cdir = env.get_key(GIT_CACHE_DIR_ENV)
if cdir and sh.isdir(cdir):
#TODO
pass
return False
def _gitdownload(storewhere, uri, branch=None):
dirsmade = sh.mkdirslist(storewhere)
LOG.info("Downloading from %s to %s" % (uri, storewhere))
#check if already done
if _git_cache_download(storewhere, uri, branch):
return dirsmade
#have to do it...
cmd = ["git", "clone"] + [uri, storewhere]
sh.execute(*cmd)
if branch and branch != GIT_MASTER_BRANCH:

View File

@@ -24,6 +24,7 @@ from devstack import version
HELP_WIDTH = 80
LOG = logging.getLogger("devstack.opts")
DEF_DIR_NAME = 'stack'
def _format_list(in_list):
@@ -31,9 +32,12 @@ def _format_list(in_list):
return "[" + ", ".join(sorted_list) + "]"
def _get_def_dir():
return sh.joinpths(sh.gethomedir(), DEF_DIR_NAME)
def parse():
#version
version_str = "%prog v" + version.version_string()
help_formatter = IndentedHelpFormatter(width=HELP_WIDTH)
parser = OptionParser(version=version_str, formatter=help_formatter)
@@ -55,8 +59,8 @@ def parse():
dest="dir",
metavar="DIR",
help=("empty root DIR for install or "
"DIR with existing components for start/stop/uninstall"),
default='/opt/stack' if sh.geteuid() == 0 else sh.joinpths(sh.gethomedir(), 'stack'))
"DIR with existing components for start/stop/uninstall (default: %default)"),
default=_get_def_dir())
base_group.add_option("-i", "--ignore-deps",
action="store_false",
dest="ensure_deps",
@@ -93,10 +97,7 @@ def parse():
output['ref_components'] = options.r_component
output['action'] = options.action
output['force'] = options.force
if options.ensure_deps:
output['ignore_deps'] = False
else:
output['ignore_deps'] = True
output['ignore_deps'] = not options.ensure_deps
output['keep_packages'] = options.keep_packages
output['extras'] = args
return output

View File

@@ -95,10 +95,11 @@ def execute(*cmd, **kwargs):
for (k, v) in env_overrides.items():
process_env[k] = str(v)
rc = None
result = None
try:
if run_as_root:
root_mode()
obj = subprocess.Popen(execute_cmd,
stdin=stdin_fh,
stdout=stdout_fh,
@@ -107,22 +108,19 @@ def execute(*cmd, **kwargs):
cwd=cwd,
shell=shell,
env=process_env)
result = None
if process_input is not None:
result = obj.communicate(str(process_input))
else:
result = obj.communicate()
if (stdin_fh != subprocess.PIPE
and obj.stdin and close_stdin):
obj.stdin.close()
rc = obj.returncode
LOG.debug('Cmd result had exit code: %s' % rc)
finally:
user_mode()
if run_as_root:
user_mode()
if (not ignore_exit_code) and (rc not in check_exit_code):
(stdout, stderr) = result
@@ -188,10 +186,10 @@ def prompt_password(pw_prompt=None):
return rc.strip()
def chown_r(path, uid, gid):
def chown_r(path, uid, gid, run_as_root=True):
try:
root_mode()
if run_as_root:
root_mode()
if(isdir(path)):
LOG.debug("Changing ownership of %s to %s:%s" % (path, uid, gid))
os.chown(path, uid, gid)
@@ -205,7 +203,8 @@ def chown_r(path, uid, gid):
os.chown(joinpths(root, f), uid, gid)
LOG.debug("Changing ownership of %s to %s:%s" % (joinpths(root, f), uid, gid))
finally:
user_mode()
if run_as_root:
user_mode()
def password(prompt_=None, pw_len=8):
@@ -293,12 +292,12 @@ def deldir(path, run_as_root=False):
try:
if run_as_root:
root_mode()
if isdir(path):
LOG.debug("Recursively deleting directory tree starting at \"%s\"" % (path))
shutil.rmtree(path)
finally:
user_mode()
if run_as_root:
user_mode()
def rmdir(path, quiet=True, run_as_root=False):
@@ -307,7 +306,6 @@ def rmdir(path, quiet=True, run_as_root=False):
try:
if run_as_root:
root_mode()
LOG.debug("Deleting directory \"%s\" with the cavet that we will fail if it's not empty." % (path))
os.rmdir(path)
LOG.debug("Deleted directory \"%s\"" % (path))
@@ -317,24 +315,23 @@ def rmdir(path, quiet=True, run_as_root=False):
else:
pass
finally:
user_mode()
if run_as_root:
user_mode()
def symlink(source, link, force=True, run_as_root=True):
try:
if run_as_root:
root_mode()
path = dirname(link)
mkdirslist(path)
LOG.debug("Creating symlink from %s => %s" % (link, source))
if force and exists(link):
unlink(link, True)
os.symlink(source, link)
finally:
user_mode()
if run_as_root:
user_mode()
def exists(path):
@@ -383,7 +380,8 @@ def getuid(username):
def gethomedir():
return pwd.getpwuid(geteuid())[5]
#TODO will just using os.path.expanduser("~") work??
return pwd.getpwuid(geteuid()).pw_dir
def getgid(groupname):
@@ -469,7 +467,8 @@ def replace_in_file(fname, search, replace, run_as_root=False):
line = line.replace(search, replace)
print line,
finally:
user_mode()
if run_as_root:
user_mode()
def copy_replace_file(fsrc, fdst, map_):

28
stack
View File

@@ -29,30 +29,42 @@ if(log_fn == None):
log_fn = os.path.normpath(os.path.join("conf", 'logging.ini'))
logging.config.fileConfig(log_fn)
#this handles our option parsing
from devstack import opts
from devstack import utils
from devstack import settings
from devstack import shell as sh
from devstack import utils
#these are the program runtimes that actually do the running
from devstack.progs import actions
#the user who's user id should be 0
ROOT_USER = 'root'
def main():
# will need root to setup openstack
#names!
prog_name = os.path.basename(sys.argv[0])
pretty_name = settings.PROG_NICE_NAME
#do this first so people can see the help message...
args = opts.parse()
#will need root to setup openstack
if not sh.got_root():
print("%s needs to run as root" % os.path.basename(sys.argv[0]))
msg = "%s needs to be ran as %s!" % (pretty_name, ROOT_USER)
print(utils.color_text(msg, 'red', True))
msg = "Perhaps you should try %s" % \
(utils.color_text("sudo %s" % (prog_name), "red", True))
print(msg)
return 1
# drop to usermode
#drop to usermode
sh.user_mode()
args = opts.parse()
try:
# now let's go
started_ok = actions.run(args)
if not started_ok:
me = utils.color_text((os.path.basename(sys.argv[0])), "red", True)
me = utils.color_text(prog_name, "red", True)
me += " " + utils.color_text('--help', 'red')
print("Perhaps you should try %s" % (me))
return 1