def addFolder(self, path, name): """Create a new directory in the filesystem within the given path. """ path = path.encode('utf-8') name = name.encode('utf-8') code = 0 error = '' absolutePath = self.getAbsolutePath(path) newPath = os.path.join(absolutePath, name) if not os.path.isdir(absolutePath): error = translate(_(u'filemanager_invalid_parent', default=u"Parent folder not found."), context=self.request) code = 1 else: if not validateFilename(name): error = translate(_(u'filemanager_invalid_foldername', default=u"Invalid folder name."), context=self.request) code = 1 elif os.path.exists(newPath): error = translate(_(u'filemanager_error_folder_exists', default=u"Folder already exists."), context=self.request) code = 1 else: try: os.mkdir(newPath) except OSError, e: if e.errno == 13: error = translate(_(u'filemanager_error_unauthorized', default=(u"You are not allowed to create a " "folder in \"%s\"." % path)), context=self.request) code = 1 else: error = translate(_(u'filemanager_error_unknown', default=(u"Something bad happened: " "\"%s\"." % e.strerror)), context=self.request) code = 1
def addNew(self, path, name): """Add a new empty file in the given directory """ path = path.encode('utf-8') name = name.encode('utf-8') absolutePath = self.getAbsolutePath(path) error = '' code = 0 newPath = os.path.join(absolutePath, name) if not os.path.isdir(absolutePath): error = translate(_(u'filemanager_invalid_parent', default=u"Parent folder not found."), context=self.request) code = 1 else: if not validateFilename(name): error = translate(_(u'filemanager_invalid_filename', default=u"Invalid file name."), context=self.request) code = 1 elif os.path.exists(newPath): error = translate(_(u'filemanager_error_file_exists', default=u"File already exists."), context=self.request) code = 1 else: openedFile = open(newPath, 'w') openedFile.close() return { "parent": self.normalizeReturnPath(path), "name": name, "error": error, "code": code, }