def addFolder(self, cx, folder): parentFolderNode = None if cx is not None: parentFolderNode = cx.localFolder _, path = paths.ResolveFolder(parentFolderNode, folder) if path in self.files_: entry = self.files_[path] if type(entry) is not nodes.FolderNode: self.ensureUnique(path) # Will always throw. return entry try: os.makedirs(path) except OSError as exn: if not (exn.errno == errno.EEXIST and os.path.isdir(path)): raise obj = nodes.FolderNode(path) self.files_[path] = obj return obj
def generateFolder(self, parent, folder): parent_path, path = paths.ResolveFolder(parent, folder) # Quick check. If this folder is not in our old folder list, and it's in # the DB, then we already have an entry for it that has already negotiated # its parent paths. old_entry = self.db.query_path(path) if old_entry and self.isValidFolderEntry(old_entry): return old_entry components = [] while folder: folder, name = os.path.split(folder) if not name: break components.append(name) path = parent_path while len(components): name = components.pop() path = os.path.join(path, name) entry = self.db.query_path(path) if not entry: if self.refactoring: util.con_err(util.ConsoleRed, 'New folder introduced: ', util.ConsoleBlue, path, util.ConsoleNormal) raise Exception('Refactoring error: new folder') entry = self.db.add_folder(parent, path) elif entry.type == nodetypes.Output or entry.type == nodetypes.SharedOutput: if entry.type == nodetypes.Output: cmd_entries = [self.db.query_command_of(entry)] elif entry.type == nodetypes.SharedOutput: cmd_entries = self.db.query_shared_commands_of(entry) for cmd_entry in cmd_entries: if cmd_entry not in self.old_commands_: util.con_err( util.ConsoleRed, 'Folder has the same path as an output file generated by:\n', util.ConsoleBlue, cmd_entry.format(), util.ConsoleNormal) raise Exception( 'Output has been duplicated: {0}'.format( entry.path)) if self.refactoring: util.con_err(util.ConsoleRed, 'Path "', util.ConsoleBlue, entry.path, util.ConsoleRed, '" has changed from a file to a folder.', util.ConsoleNormal) raise Exception( 'Refactoring error: path changed from file to folder') self.rm_list_.append(entry.path) self.db.change_to_folder(entry) elif entry.type == nodetypes.Mkdir: # We let the same folder be generated twice, so use discard, not remove. self.old_folders_.discard(entry) else: util.con_err(util.ConsoleRed, 'Folder has the same node signature as: ', util.ConsoleBlue, entry.format(), util.ConsoleNormal) raise Exception('Output has been duplicated: {0}'.format( entry.path)) parent = entry return entry