def install(self, tarf, username, groupname, clobber, force=False): """Install package from file. """ if self.domain.is_frozen(): raise utils.SSMExitException("error: domain is frozen") force = force or globls.force cwd = os.getcwd() if self.exists() and not (force or clobber): raise utils.SSMExitException("error: package already installed") try: utils.chdir(self.domain.path) for member in tarf.getmembers(): try: path = os.path.normpath(member.name) if path.startswith(self.name): if os.path.exists(path): if not clobber: utils.print_warning( "warning: clobbering not enabled (%s)" % path) continue elif os.path.isdir(path): utils.print_warning( "warning: cannot clobber directory (%s)" % path) continue elif os.path.isfile(path): utils.print_warning( "warning: clobbering file (%s)" % path) utils.remove(path) member.uname = username member.gname = groupname utils.print_verbose("extracting member (%s)" % member.name) tarf.extract(member) elif path != ".": utils.print_warning( "warning: rejecting member not part of package (%s)" % path) except: if globls.debug: traceback.print_exc() utils.print_error("error: could not extract file (%s)" % path) self.execute_script("post-install") self.domain.add_installed(self.path) self.domain.remove_broken(self.path) except: if globls.debug: traceback.print_exc() raise utils.SSMExitException("error: could not install") utils.chdir(cwd)
def _add_state(self, state_path, pkg_path, platform=None): path = os.path.realpath(pkg_path) link_dir = self._get_state_link_dir(state_path, platform) link_name = "%s/%s" % (link_dir, os.path.basename(path)) if os.path.lexists(link_name): utils.remove(link_name) if not os.path.isdir(link_dir): os.makedirs(link_dir) utils.symlink(path, link_name)
def unpublish_package(self, package, platform=None): """Unpublish package from domain. Match tail of published links against <package_name>/<tail> . Note: os.path.realpath(pub_path) resolves all symlinks, we want to resolve only the published one, therefore using os.readlink(pub_path). """ if self.is_frozen(): raise utils.SSMExitException("error: domain is frozen") try: inst_package = self._find_package(package.name) inst_package.execute_script("pre-unpublish", package.domain) if platform == None: package.platform pub_dir = os.path.join(self.path, platform) pub_dir_len = len(pub_dir) for root, dirnames, filenames in os.walk(pub_dir, topdown=False): for name in dirnames: pub_path = os.path.join(root, name) if os.path.islink(pub_path): link_path = os.readlink(pub_path) if not link_path.startswith("/"): link_path = os.path.join(os.path.dirname(pub_path), link_path) if os.path.islink(link_path): # publish symlink to install symlink to a dir filenames.append(name) elif len(os.listdir(pub_path)) == 0: utils.rmdir(pub_path) for name in filenames: pub_path = os.path.join(root, name) tail_pub_path = pub_path[pub_dir_len + 1:] match_path = os.path.join(package.name, tail_pub_path) try: real_pub_path = os.readlink(pub_path) except: utils.print_warning( "warning: skipping unexpected non-symlink file (%s)" % pub_path) continue if real_pub_path.endswith(match_path): utils.remove(pub_path) inst_package.execute_script("post-unpublish", package.domain) self.remove_published(package.path, platform) self.remove_broken(package.path) except: if globls.debug: traceback.print_exc() self.add_broken(package.path) raise utils.SSMExitException("error: could not unpublish")
def publish_package(self, package, platform=None): """Publish package to domain. """ if self.is_frozen(): raise utils.SSMExitException("error: domain is frozen") if package.domain.is_broken(package.name) and not globls.force: raise utils.SSMExitException("error: package is broken") try: if platform == None: platform = package.platform pkg_path_len = len(package.path) + 1 pub_dir = os.path.join(self.path, platform) if not os.path.exists(pub_dir): utils.makedirs(pub_dir) package.execute_script("pre-publish", self) for path in package.get_publishable_paths(PUBLISHABLE_NAMES): rel_path = path[pkg_path_len:] pub_path = os.path.join(pub_dir, rel_path) real_path = os.path.realpath(path) linkname = os.path.islink(path) and os.readlink(path) if rel_path in PUBLISHABLE_NAMES: # enforce directory creation for publishable # names even if the package uses a symlink if not os.path.exists(pub_path): utils.makedirs(pub_path) elif os.path.isdir(path) \ and (linkname == False or linkname[:2]+linkname[-2:] == ".//."): if not os.path.exists(pub_path): utils.makedirs(pub_path) elif os.path.isfile(path) or os.path.islink(path): if globls.force: utils.remove(pub_path) utils.symlink(path, pub_path) package.execute_script("post-publish", self) self.add_published(package.path, platform) self.remove_broken(package.path) except: if globls.debug: traceback.print_exc() self.add_broken(package.path) raise utils.SSMExitException("error: could not publish")
def get(self, package_name): """Download package and return TarFile object. """ tarf = None url = self.find(package_name) if url: try: path, headers = urllib.urlretrieve(url) tarf = tarfile.open(path) tarf.errorlevel = 1 # exception on fatal errors if url.startswith("http://") or url.startswith("ftp://"): # delete temp file utils.remove(path) except: #traceback.print_exc() tarf = None return tarf
"a+").write(SSM_LOGIN_TEMPLATE.format(ssmd_login_path)) if SSM_PROFILE_STAMP_END not in utils.loads(profile_path): open(profile_path, "a+").write(SSM_PROFILE_TEMPLATE.format(ssmd_profile_path)) # point to domain-specific profile/login files if not os.path.isdir(ssmd_dir_path): utils.makedirs(ssmd_dir_path) if not globls.force and not globls.auto_yes \ and (os.path.exists(ssmd_login_path) or os.path.exists(ssmd_profile_path)): # should unsubscribe first! if utils.prompt("Overwrite the current subscription (y/n)?").lower( ) not in ["y"]: utils.print_exit("operation aborted") utils.remove(ssmd_login_path) utils.remove(ssmd_profile_path) utils.symlink(os.path.join(domain_home, "etc/ssm.d/login"), ssmd_login_path) utils.symlink(os.path.join(domain_home, "etc/ssm.d/profile"), ssmd_profile_path) except SystemExit: raise except utils.SSMExitException, detail: utils.print_exit(detail) except: if globls.debug: traceback.print_exc() utils.print_exit("error: operation failed") sys.exit(0)
def unfreeze(self): """Remove "frozen" mark. """ utils.remove(self.frozen_path)
def _remove_state(self, state_path, pkg_path, platform=None): path = os.path.realpath(pkg_path) link_dir = self._get_state_link_dir(state_path, platform) link_name = "%s/%s" % (link_dir, os.path.basename(path)) if os.path.lexists(link_name): utils.remove(link_name)