def __checkDiskInfo(self, dst, total_size): (capacity, available, used) = getDiskInfo(str(dst)) if available < total_size: self.utils.cprint(_("There is not enough space left on your USB stick for the image."), "red") self.utils.cprint(_("Unmounting image..."), "red") runCommand("fusermount -u %s" % MOUNT_ISO) return False self.utils.cprint(_("USB disk informations:"), "brightgreen") self.utils.cprint(" %s:" % _("Capacity"), "green", True) print("%dMB" % capacity) self.utils.cprint(" %s:" % _("Available"), "green", True) print("%dMB" % available) self.utils.cprint(" %s:" % _("Used"), "green", True) print("%dMB" % used) print(_("\nPlease double check your path information. If you don't type the path to the USB stick correctly, you may damage your computer. Would you like to continue?")) answer = raw_input("%s " % _("Please type CONFIRM to continue:")) if answer in (_('CONFIRM'), _('confirm')): self.utils.cprint(_("Writing image data to USB stick!"), "green") return True self.utils.cprint(_("You did not type CONFIRM. Exiting.."), "red") return False
def __createImage(self, src, dst): createUSBDirs(dst) self.utils.cprint(_("Creating boot manager..."), "yellow") if createSyslinux(dst): self.utils.cprint(_("Could not create boot manager."), "red") return False self.__copyImage(MOUNT_ISO, dst) self.utils.cprint(_("Unmounting image..."), "green") cmd = "fusermount -u %s" % MOUNT_ISO if runCommand(cmd): self.utils.cprint(_("Could not unmounted image."), "red") return False if dst == MOUNT_USB: self.utils.cprint(_("Unmounting USB disk..."), "green") cmd = "umount %s" % MOUNT_USB if runCommand(cmd): self.utils.cprint(_("Could not unmounted USB disk."), "red") return False self.utils.cprint(_("USB disk is ready. Now you can install or run Pardus from your USB disk."), "brightgreen") return True
def __createImage(self, src, dst): createUSBDirs(dst) self.utils.cprint(_("Creating boot manager..."), "yellow") if createSyslinux(dst): self.utils.cprint(_("Could not create boot manager."), "red") return False self.__copyImage(MOUNT_ISO, dst) self.utils.cprint(_("Unmounting image..."), "green") cmd = "fusermount -u %s" % MOUNT_ISO if runCommand(cmd): self.utils.cprint(_("Could not unmounted image."), "red") return False if dst == MOUNT_USB: self.utils.cprint(_("Unmounting USB disk..."), "green") cmd = "umount %s" % MOUNT_USB if runCommand(cmd): self.utils.cprint(_("Could not unmounted USB disk."), "red") return False self.utils.cprint( _("USB disk is ready. Now you can install or run Pardus from your USB disk." ), "brightgreen") return True
def __checkDiskInfo(self, dst, total_size): (capacity, available, used) = getDiskInfo(str(dst)) if available < total_size: self.utils.cprint( _("There is not enough space left on your USB stick for the image." ), "red") self.utils.cprint(_("Unmounting image..."), "red") runCommand("fusermount -u %s" % MOUNT_ISO) return False self.utils.cprint(_("USB disk informations:"), "brightgreen") self.utils.cprint(" %s:" % _("Capacity"), "green", True) print("%dMB" % capacity) self.utils.cprint(" %s:" % _("Available"), "green", True) print("%dMB" % available) self.utils.cprint(" %s:" % _("Used"), "green", True) print("%dMB" % used) print( _("\nPlease double check your path information. If you don't type the path to the USB stick correctly, you may damage your computer. Would you like to continue?" )) answer = raw_input("%s " % _("Please type CONFIRM to continue:")) if answer in (_('CONFIRM'), _('confirm')): self.utils.cprint(_("Writing image data to USB stick!"), "green") return True self.utils.cprint(_("You did not type CONFIRM. Exiting.."), "red") return False
def on_button_create_clicked(self): # FIXED issue: #1 src = unicode(str(self.line_image.displayText())) dst = str(self.line_disk.displayText()) if dst.startswith("/dev/"): from puding.pardusTools import Authorization auth = Authorization() auth.mount(dst, MOUNT_USB) dst = MOUNT_USB if not self.__checkDestination(dst): self.warningDialog(self.tr("Directory is Invalid"), self.tr("Please check the USB disk path.")) return False try: (name, md5, url) = self.__getSourceInfo(src) except TypeError: # 'bool' object is not iterable # It's not true way, you should warn to the users with WarningDialog. return False mount_point = getMounted(dst) (capacity, available, used) = getDiskInfo(dst) # Mount iso if not os.path.ismount(MOUNT_ISO): cmd = "fuseiso %s %s" % (src, MOUNT_ISO) if runCommand(cmd): # FIX ME: Should use warning dialog. return False # FIX ME: Now Puding supports only Pardus. from pardusTools import Main self.tools = Main(MOUNT_ISO, dst) total_size = self.tools.getTotalSize() if available < total_size: self.warningDialog("Warning", "There is not enough space left on your USB stick for the image.") else: self.confirm_infos = ConfirmDialog(src, dst, mount_point, name, total_size, capacity, available, used) if self.confirm_infos.exec_() == QtGui.QDialog.Accepted: createUSBDirs(dst) self.__createImage(src, dst) if dst == MOUNT_USB: auth.umount(dst) # Unmount iso cmd = "fusermount -u %s" % MOUNT_ISO if runCommand(cmd): # FIX ME: Should use warning dialog. return False
def FunctionName(): datadict = {} (output, exitCode) = COM.runCommand([ "<command>", "<param 1>", "<param 2>" ]) # <--- Notice how each parameter is a comma separated string datadict["check"] = "FunctionName" datadict["label_name1"] = output.strip() datadict["label_name2"] = "Thing to record" # Secondary command example (output2, exitCode2) = COM.runCommand(["<supp. Command>", "<param3>", "<param4>"]) datadict["label_name3"] = output2.strip() return COM.generateOutput(datadict, exitCode)
def puppet_running(): """Checks if puppet is running""" dataDict = {} (output, exitCode) = COM.runCommand(["/etc/sensu/plugins/check_puppet_agent"]) dataDict['check'] = 'puppet_running' dataDict['value'] = output.strip() return COM.generateOutput(dataDict, exitCode)
def puppet_ssl_expiry_autofix(): """Copy of the puppet_ssl_expiry definition""" dataDict = {} (output, exitCode) = COM.runCommand([ "/etc/sensu/plugins/check-ssl-cert.rb", "-c", "89", "-w", "90", "-P", "/etc/puppetlabs/puppet/ssl/certs/tukp-sensuserver-2.papt.to.pem" ]) dataDict['check'] = 'puppet_ssl_expiry_autofix' dataDict['value'] = output.strip() return COM.generateOutput(dataDict, exitCode)
def puppet_ssl_expiry(): """Checks if the puppet cert is expiring within the next 80 days""" dataDict = {} (output, exitCode) = COM.runCommand([ "/etc/sensu/plugins/check-ssl-cert.rb", "-c", "30", "-w", "80", "-P", "/etc/puppetlabs/puppet/ssl/certs/tukp-sensuserver-2.papt.to.pem" ]) dataDict['check'] = 'puppet_ssl_expiry' dataDict['value'] = output.strip() return COM.generateOutput(dataDict, exitCode)
def __init__(self, src, dst): self.utils = Utils() self.progressbar = ProgressBar(src) self.iso_dir = tempfile.mkdtemp(suffix="_isoPuding") if not dst: self.partutils = PartitionUtils() if not self.partutils.detectRemovableDrives(): self.utils.cprint(_("USB device not found."), "red") sys.exit() else: device, dst = self.__askDestination() # FIX ME: You should not use it. if not dst: dst = tempfile.mkdtemp(suffix="_usbPuding") cmd = "mount -t vfat %s %s" % (device, dst) self.utils.cprint(_("Mounting USB device..."), "green") runCommand(cmd) self.utils.cprint(_("Mounting image..."), "green") cmd = "fuseiso %s %s" % (src, self.iso_dir) if runCommand(cmd): self.utils.cprint(_("Could not mounted image."), "red") sys.exit(1) if self.__checkSource(src) and self.__checkDestination(dst): from pardusTools import Main tools = Main(self.iso_dir, dst) if self.__checkDiskInfo(dst, tools.getTotalSize()): self.__createImage(src, dst) else: self.utils.cprint(_("The path you have typed as second argument is invalid. Please check the USB directory."), "red") unmountDirs() sys.exit(1)
def __init__(self, src, dst): self.utils = Utils() self.progressbar = ProgressBar(src) if dst == None: self.partutils = PartitionUtils() if not self.partutils.detectRemovableDrives(): self.utils.cprint(_("USB device not found."), "red") sys.exit() else: device, dst = self.__askDestination() # FIX ME: You should not use it. if not dst: cmd = "mount -t vfat %s %s" % (device, MOUNT_USB) self.utils.cprint(_("Mounting USB device..."), "green") runCommand(cmd) dst = MOUNT_USB self.utils.cprint(_("Mounting image..."), "green") cmd = "fuseiso %s %s" % (src, MOUNT_ISO) if runCommand(cmd): self.utils.cprint(_("Could not mounted image."), "red") sys.exit(1) if self.__checkSource(src) and self.__checkDestination(dst): from pardusTools import Main tools = Main(MOUNT_ISO, dst) if self.__checkDiskInfo(dst, tools.getTotalSize()): self.__createImage(src, dst) else: self.utils.cprint( _("The path you have typed is invalid. If you think the path is valid, make sure you have mounted USB stick to the path you gave. To check the path, you can use: mount | grep %s" % dst), "red") sys.exit(1)
def __init__(self, src, dst): self.utils = Utils() self.progressbar = ProgressBar(src) if dst == None: self.partutils = PartitionUtils() if not self.partutils.detectRemovableDrives(): self.utils.cprint(_("USB device not found."), "red") sys.exit() else: device, dst = self.__askDestination() # FIX ME: You should not use it. if not dst: cmd = "mount -t vfat %s %s" % (device, MOUNT_USB) self.utils.cprint(_("Mounting USB device..."), "green") runCommand(cmd) dst = MOUNT_USB self.utils.cprint(_("Mounting image..."), "green") cmd = "fuseiso %s %s" % (src, MOUNT_ISO) if runCommand(cmd): self.utils.cprint(_("Could not mounted image."), "red") sys.exit(1) if self.__checkSource(src) and self.__checkDestination(dst): from pardusTools import Main tools = Main(MOUNT_ISO, dst) if self.__checkDiskInfo(dst, tools.getTotalSize()): self.__createImage(src, dst) else: self.utils.cprint(_("The path you have typed is invalid. If you think the path is valid, make sure you have mounted USB stick to the path you gave. To check the path, you can use: mount | grep %s" % dst), "red") sys.exit(1)
def Tree(): datadict = {} (output, exitCode) = COM.runCommand(["tree", "./", "--charset=ascii"]) datadict["check"] = "Tree" datadict["data"] = output.strip() return COM.generateOutput(datadict, exitCode)
def Pwd(): datadict = {} (output, exitCode) = COM.runCommand(["pwd"]) datadict["check"] = "Pwd" datadict["pwd"] = output.strip() return COM.generateOutput(datadict, exitCode)
def _runCommand (self,cmdString,timer): """ Run a general filesystem related command. """ return common.runCommand (self._log,cmdString,timer)
def removeLVM (self): """ Remove the old LVM structure: VGs and LVs """ # consts TOTAL_REMOVE_LVM_EXPECTED_TIME = 20 GET_VG_NAMES_COMMAND_STRING = "vgs -o name --noheading" REMOVE_VG_PATTERNS = ["vg_c[0-9][0-9]"] KEEP_VG_PATTERNS = ["vg_sys"] REMOVE_VG_COMMAND_STRING = "vgremove -f %s" try: # start timer timer = common.Timer(TOTAL_REMOVE_LVM_EXPECTED_TIME) # get list of VG names stdout,stderr,rc = common.runCommand (self._log,GET_VG_NAMES_COMMAND_STRING,timer) if (rc != 0): self._log("get-vgs-failed").error("removeLVM() faild to get VG names! (command='%s', rc=%d, stderr=%s)",GET_VG_NAMES_COMMAND_STRING,rc,stderr) return ReturnCodes.kGeneralError vgNames = stdout.strip().split("\n") vgNamesLeft = set(vgNames) # per VG, if fits the known patterns for removal - remove it failedToBeRemovedVgs = [] for vgName in vgNames: for pattern in REMOVE_VG_PATTERNS: if (re.search(pattern,vgName) != None): # found a VG for removal -> if allowed destroy and remove from vgNamesLeft if (self._disableRemoveLvm): self._log("cannot-remove-vg").error("some VGs (VG '%s') needs to be removed but disable-remove-lvm is '%s'. destruction of LVM failed!",vgName,self._disableRemoveLvm) return ReturnCodes.kGeneralError # we are good to go on the removal of this VG stdout,stderr,rc = common.runCommand (self._log,REMOVE_VG_COMMAND_STRING%vgName,timer) if (rc == 0): self._log("successful-vg-removal").info("VG '%s' was removed successfully",vgName) vgNamesLeft.remove(vgName) else: self._log("vg-removal-fail").error("VG '%s' failed to be removed!",vgName) failedToBeRemovedVgs.append(vgName) break if (len(failedToBeRemovedVgs) > 0): self._log("failed-to-be removed-vgs").error("the following VGs could not be removed %s. destruction of LVM failed!",failedToBeRemovedVgs) return ReturnCodes.kGeneralError # check for renegade VGs (ones that are not supposed to be) renegadeVgs = [] for vgName in vgNamesLeft: for pattern in KEEP_VG_PATTERNS: if (re.search(pattern,vgName) != None): break else: # here is a place where only renegade VGs get to self._log("renegade-vg-found").error("VG '%s' doesn't fit the allowed patterns nor the ones for removal",vgName) renegadeVgs.append(vgName) if (len(renegadeVgs) > 0): self._log("renegade-vgs").error("the following VGs are renegade %s. destruction of LVM failed! (patternsToRemove=%s, pattersToKeep=%s)",renegadeVgs,REMOVE_VG_PATTERNS,KEEP_VG_PATTERNS) return ReturnCodes.kGeneralError # full success self._log("lvm-removed-successfuly").info("removeLVM() done successfully") return ReturnCodes.kOk except Exception,e: self._log("remove-lvm-exception").error("removeLVM() faild! exception = '%s'",e) return ReturnCodes.kGeneralError
def isMergeCommit(commitSHA): commitInfo = runCommand(f'git show --no-patch {commitSHA}').split('\n') return commitInfo[1].startswith('Merge:')
def __call__(self, urlSuffix, msg='API request failed'): reqURL = self.projectURL + '/' + urlSuffix.lstrip('/') reqCmd = 'curl --header "token={}" "{}"'.format(self.token, reqURL) data = runCommand(reqCmd, suppressTraceBack=True, errorMessage=msg) return json.loads(data)
def _runCommand(self, cmdString, timer): """ Run a general filesystem related command. """ return common.runCommand(self._log, cmdString, timer)
def Whoami(): datadict = {} (output, exitCode) = COM.runCommand(["whoami"]) datadict["check"] = "Whoami" datadict["user"] = output.strip() return COM.generateOutput(datadict, exitCode)
def on_button_create_clicked(self): # FIXED issue: #1 src = unicode(str(self.line_image.displayText())) dst = str(self.line_disk.displayText()) if dst.startswith("/dev/"): device = dst dst = tempfile.mkdtemp(suffix="_usbPuding") from puding.pardusTools import Authorization auth = Authorization() auth.mount(device, dst) if not self.__checkDestination(dst): self.warningDialog(self.tr("Directory is Invalid"), self.tr("Please check the USB disk path.")) return False try: (name, md5, url) = self.__getSourceInfo(src) except TypeError: # 'bool' object is not iterable # It's not true way, you should warn to the users with WarningDialog. return False mount_point = getMounted(dst) (capacity, available, used) = getDiskInfo(dst) # Mount iso if not os.path.ismount(self.iso_dir): cmd = "fuseiso %s %s" % (src, self.iso_dir) if runCommand(cmd): # FIX ME: Should use warning dialog. return False # FIX ME: Now Puding supports only Pardus. from pardusTools import Main self.tools = Main(self.iso_dir, dst) total_size = self.tools.getTotalSize() if available < total_size: self.warningDialog( "Warning", "There is not enough space left on your USB stick for the image." ) else: self.confirm_infos = ConfirmDialog(src, dst, mount_point, name, total_size, capacity, available, used) if self.confirm_infos.exec_() == QtGui.QDialog.Accepted: createUSBDirs(dst) self.__createImage(src, dst) if dst.endswith("Puding"): auth.umount(dst) runCommand("fusermount -u %s" % self.iso_dir)
def removeLVM(self): """ Remove the old LVM structure: VGs and LVs """ # consts TOTAL_REMOVE_LVM_EXPECTED_TIME = 20 GET_VG_NAMES_COMMAND_STRING = "vgs -o name --noheading" REMOVE_VG_PATTERNS = ["vg_c[0-9][0-9]"] KEEP_VG_PATTERNS = ["vg_sys"] REMOVE_VG_COMMAND_STRING = "vgremove -f %s" try: # start timer timer = common.Timer(TOTAL_REMOVE_LVM_EXPECTED_TIME) # get list of VG names stdout, stderr, rc = common.runCommand( self._log, GET_VG_NAMES_COMMAND_STRING, timer) if (rc != 0): self._log("get-vgs-failed").error( "removeLVM() faild to get VG names! (command='%s', rc=%d, stderr=%s)", GET_VG_NAMES_COMMAND_STRING, rc, stderr) return ReturnCodes.kGeneralError vgNames = stdout.strip().split("\n") vgNamesLeft = set(vgNames) # per VG, if fits the known patterns for removal - remove it failedToBeRemovedVgs = [] for vgName in vgNames: for pattern in REMOVE_VG_PATTERNS: if (re.search(pattern, vgName) != None): # found a VG for removal -> if allowed destroy and remove from vgNamesLeft if (self._disableRemoveLvm): self._log("cannot-remove-vg").error( "some VGs (VG '%s') needs to be removed but disable-remove-lvm is '%s'. destruction of LVM failed!", vgName, self._disableRemoveLvm) return ReturnCodes.kGeneralError # we are good to go on the removal of this VG stdout, stderr, rc = common.runCommand( self._log, REMOVE_VG_COMMAND_STRING % vgName, timer) if (rc == 0): self._log("successful-vg-removal").info( "VG '%s' was removed successfully", vgName) vgNamesLeft.remove(vgName) else: self._log("vg-removal-fail").error( "VG '%s' failed to be removed!", vgName) failedToBeRemovedVgs.append(vgName) break if (len(failedToBeRemovedVgs) > 0): self._log("failed-to-be removed-vgs").error( "the following VGs could not be removed %s. destruction of LVM failed!", failedToBeRemovedVgs) return ReturnCodes.kGeneralError # check for renegade VGs (ones that are not supposed to be) renegadeVgs = [] for vgName in vgNamesLeft: for pattern in KEEP_VG_PATTERNS: if (re.search(pattern, vgName) != None): break else: # here is a place where only renegade VGs get to self._log("renegade-vg-found").error( "VG '%s' doesn't fit the allowed patterns nor the ones for removal", vgName) renegadeVgs.append(vgName) if (len(renegadeVgs) > 0): self._log("renegade-vgs").error( "the following VGs are renegade %s. destruction of LVM failed! (patternsToRemove=%s, pattersToKeep=%s)", renegadeVgs, REMOVE_VG_PATTERNS, KEEP_VG_PATTERNS) return ReturnCodes.kGeneralError # full success self._log("lvm-removed-successfuly").info( "removeLVM() done successfully") return ReturnCodes.kOk except Exception, e: self._log("remove-lvm-exception").error( "removeLVM() faild! exception = '%s'", e) return ReturnCodes.kGeneralError
suffix = pipelineApiSuffix(pipeLine['id']) jobs = requester(suffix.rstrip('/') + '/jobs/') return any(j in jobs for j in args['exclude_jobs']) def findPipeline(commits): for commit in commits: pipeLine = getLastPipeline(commit) if pipeLine is not None: if hasMatchingStatus(pipeLine) and not hasExcludeJob(pipeLine): return pipeLine return None if args['look_for'] == 'HEAD': commits = [runCommand('git rev-list HEAD --max-count=1').strip('\n')] if isMergeCommit(commits[0]): preSHA = runCommand('git rev-list HEAD --max-count=2').split('\n')[1] commits.append(preSHA) pipeLine = findPipeline(commits) elif args['look_for'] == 'latest': count = args['max_tree_depth'] commits = filter( None, runCommand(f'git rev-list HEAD --max-count={count}').split('\n')) pipeLine = findPipeline(commits) elif args['look_for'] == 'latest-merge': count = args['max_tree_depth'] commits = filter(