def import_commands(ruck_dir): import glob, imp sysdir = ruck_dir + "/commands" sys.path.append(sysdir) loaded_modules = [] # First load modules in our current directory, for developers, and then # out of the system dir. files = glob.glob("*cmds.py") files = files + glob.glob("%s/*cmds.py" % sysdir) for file in files: (path, name) = os.path.split(file) (name, ext) = os.path.splitext(name) if name in loaded_modules: continue (file, filename, data) = imp.find_module(name, [path]) try: module = imp.load_module(name, file, filename, data) except ImportError: rucktalk.warning("Can't import module " + filename) else: loaded_modules.append(name) if file: file.close()
def extract_command_from_argv(argv): command = None i = 0 unknown_commands = [] while i < len(argv) and not command: if argv[i][0] != "-": command = construct(argv[i]) if command: argv.pop(i) else: unknown_commands.append(argv[i]) else: takes_arg = 0 for o in default_opt_table: if not (argv[i][1:] == o[0] or argv[i][2:] == o[1]): continue if o[2] != "": takes_arg = 1 break if takes_arg and string.find(argv[i], "=") == -1: i = i + 1 i = i + 1 if not command: map(lambda x:rucktalk.warning("Unknown command '%s'" % x), unknown_commands) rucktalk.warning("No command found on command line.") if "--help" in argv or "-?" in argv: usage_full() else: usage_basic() sys.exit(1) return command
def start_transaction(self, dryrun=False, download_only=False): yum = self.yum() if not download_only: (rescode, resmsgs) = self.resolve_deps() if rescode != 2: for resmsg in resmsgs: rucktalk.error(resmsg) return False self.show_ts_packages() if self.tsInfo_is_empty(yum.tsInfo): rucktalk.warning("Nothing to do.") return False downloadpkgs = self.get_pkgs_to_download() if len(downloadpkgs) > 0: total_size = 0 for p in downloadpkgs: try: size = int(p.size()) total_size += size except: pass if total_size > 0: rucktalk.message("\nTotal download size: %s\n" % (ruckformat.bytes_to_str(total_size))) if self.need_prompt(): answer = raw_input('\nProceed with transaction? (y/N) ') if len(answer) != 1 or answer[0] != 'y': rucktalk.message('Transaction Canceled') return False problems = yum.downloadPkgs(downloadpkgs) if len(problems.keys()) > 0: rucktalk.error("Error downloading packages:") for key in problems.keys(): for error in unique(problems[key]): rucktalk.message(" %s: %s" % (key, error)) return False if download_only: for pkg in downloadpkgs: dest = ruckformat.package_to_str(pkg, repo=False) + ".rpm" shutil.move(pkg.localpath, dest) rucktalk.message ("Downloaded '%s'" % dest) return True # Check GPG signatures if not self.gpgsigcheck(downloadpkgs): return False tsConf = {} for feature in ['diskspacecheck']: # more to come, I'm sure tsConf[feature] = getattr(yum.conf, feature) if dryrun: testcb = ruckyum.RPMInstallCallback(output=1) testcb.tsInfo = yum.tsInfo # clean out the ts b/c we have to give it new paths to the rpms del yum.ts yum.initActionTs() yum.populateTs(keepold=0) # sigh tserrors = yum.ts.test(testcb, conf=tsConf) del testcb if len(tserrors) > 0: errstring = '' for descr in tserrors: errstring += ' %s\n' % descr rucktalk.error(errstring) return False else: rucktalk.message('Running Transaction Test') testcb = ruckyum.RPMInstallCallback(output=0) testcb.tsInfo = yum.tsInfo # clean out the ts b/c we have to give it new paths to the rpms del yum.ts yum.initActionTs() # save our dsCallback out dscb = yum.dsCallback yum.dsCallback = None # dumb, dumb dumb dumb! yum.populateTs(keepold=0) # sigh tserrors = yum.ts.test(testcb, conf=tsConf) del testcb if len(tserrors) > 0: errstring = 'Transaction Check Error: ' for descr in tserrors: errstring += ' %s\n' % descr rucktalk.error(errstring) return False rucktalk.message('Transaction Test Succeeded\n') del yum.ts yum.initActionTs() # make a new, blank ts to populate yum.populateTs(keepold=0) # populate the ts yum.ts.check() #required for ordering yum.ts.order() # order # put back our depcheck callback yum.dsCallback = dscb cb = ruckyum.RPMInstallCallback(output=1) cb.tsInfo = yum.tsInfo yum.runTransaction(cb=cb) rucktalk.message('\nTransaction Finished') return True