def kwargs_from_list(self, list, klass): """Make dict from list of args, as they go in csv file""" if klass is Item: return { "article": list[0].decode("utf-8"), "name": list[2].decode("utf-8"), "price": Decimal(list[3].decode("utf-8")), "slug": urlify(list[2].decode("utf-8")), } elif klass is Section: return {"name": list[1].decode("utf-8"), "slug": urlify(list[1].decode("utf-8"))}
def get_available_name(self, full_name): path, tail = os.path.split(full_name) source_name, ext = os.path.splitext(tail) source_name = urlify(source_name, max_length=None, remove_dots=False, default='noname', stop_words=[]) if ext: ext = urlify(ext, max_length=None, remove_dots=False, default='', stop_words=[]) name = self.get_first_name(source_name) while True: if not self.exists(path): break directories, files = self.listdir(path) for value in directories + files: if smart_unicode(os.path.splitext(value)[0]) == name: break else: break name = self.get_obfuscated_name(source_name) return os.path.join(path, name + ext)
def get_available_name(self, full_name): path, tail = os.path.split(full_name) name, ext = os.path.splitext(tail) name = urlify(name, max_length=None, remove_dots=False) if ext: ext = urlify(ext, max_length=None, remove_dots=False) source_name = name while True: try: if not self.exists(path): break directories, files = self.listdir(path) for directory in directories: if directory == name + ext: raise FileWasFound() for file in files: if smart_unicode(os.path.splitext(file)[0]) == name: raise FileWasFound() break except FileWasFound: name = source_name + ("-%04x" % random.randint(0, 0x10000)) return os.path.join(path, name + ext)