def makeDir (dir): if not ek.ek(os.path.isdir, dir): try: ek.ek(os.makedirs, dir) except OSError: return False return True
def moveFile(srcFile, destFile): try: ek.ek(os.rename, srcFile, destFile) fixSetGroupID(destFile) except OSError: copyFile(srcFile, destFile) ek.ek(os.unlink, srcFile)
def rename_file(old_path, new_name): old_path_list = ek.ek(os.path.split, old_path) old_file_ext = os.path.splitext(old_path_list[1])[1] new_path = ek.ek(os.path.join, old_path_list[0], sanitizeFileName(new_name) + old_file_ext) logger.log(u"Renaming from " + old_path + " to " + new_path) try: ek.ek(os.rename, old_path, new_path) except (OSError, IOError), e: logger.log(u"Failed renaming " + old_path + " to " + new_path + ": " + ex(e), logger.ERROR) return False
def saveGeneral(self, admin_user=None, general_user=None): if len(results) > 0: for x in results: logger.log(x, logger.ERROR) ui.notifications.error('Error(s) Saving Configuration', '<br />\n'.join(results)) else: ui.notifications.message('Configuration Saved', ek.ek(os.path.join, sickbeard.CONFIG_FILE) )
def fixSetGroupID(childPath): if os.name == 'nt' or os.name == 'ce': return parentPath = ek.ek(os.path.dirname, childPath) parentStat = os.stat(parentPath) parentMode = stat.S_IMODE(parentStat[stat.ST_MODE]) if parentMode & stat.S_ISGID: parentGID = parentStat[stat.ST_GID] childGID = os.stat(childPath)[stat.ST_GID] if childGID == parentGID: return try: ek.ek(os.chown, childPath, -1, parentGID) logger.log(u"Respecting the set-group-ID bit on the parent directory for %s" % (childPath), logger.DEBUG) except OSError: logger.log(u"Failed to respect the set-group-ID bit on the parent directory for %s (setting group ID %i)" % (childPath, parentGID), logger.ERROR)
def chmodAsParent(childPath): if os.name == 'nt' or os.name == 'ce': return parentPath = ek.ek(os.path.dirname, childPath) if not parentPath: logger.log(u"No parent path provided in "+childPath+", unable to get permissions from it", logger.DEBUG) return parentMode = stat.S_IMODE(os.stat(parentPath)[stat.ST_MODE]) if ek.ek(os.path.isfile, childPath): childMode = fileBitFilter(parentMode) else: childMode = parentMode try: ek.ek(os.chmod, childPath, childMode) logger.log(u"Setting permissions for %s to %o as parent directory has %o" % (childPath, childMode, parentMode), logger.DEBUG) except OSError: logger.log(u"Failed to set permission for %s to %o" % (childPath, childMode), logger.ERROR)
def copyFile(srcFile, destFile): ek.ek(shutil.copyfile, srcFile, destFile) try: ek.ek(shutil.copymode, srcFile, destFile) except OSError: pass