예제 #1
0
	def get_number(self, path) :
		count = {'jpg':0, 'video':0}
		tool = FileTools(path) 
		tool.remove_empty()

		for root, dirs, files in os.walk(path) :
			for d in dirs :
				d = os.path.join(root, d)

				if os.path.basename(d) not in ['Video', 'System', 'Other'] :
					print('{0} abnomal folder name'.format(d))
					return None

			for f in files :
				f = os.path.join(root, f)

				basename, ext = os.path.splitext(f)
				if re.match('\.(jpg)', ext.lower()) is not None :
					count['jpg']+= 1
				elif FileTools.is_media(f)
					count['video'] += 1
				elif SevenZ.is_archive(f) :
					os.remove(f)
				elif re.match('.*Thumbs.db', f) is not None :
					os.remove(f)
				else :
					print("{0} abnomal".format(f))
					return None

		return count
예제 #2
0
def doRename(root):
    root = os.path.join(root, "rename")
    for name in os.listdir(root):
        name = os.path.join(root, name)
        if SevenZ.is_archive(name):
            renamer = Renamer(name)
            renamer.rename()
예제 #3
0
	def unzip(self) :
		dst = os.path.splitext(self.src)[0]
		filetools = FileTools(self.src, dst)
		dst = filetools.check_conflict()
		if dst is None :
			return

		os.mkdir(dst)
		sevenz = SevenZ(self.src, dst)
		print("UNZIP : {0} started".format(os.path.basename(self.src)))

		if not sevenz.unzip() :
			# unzip failed
			shutil.rmtree(dst)
			print("UNZIP : {0} fail".format(os.path.basename(self.src)))
			return

		# trance code to jpg 
		mogrify = Mogrify(dst)
		mogrify.start()

		print("UNZIP : {0} done".format(os.path.basename(dst)))

		if not self.isTop :
			try :
				shutil.rmtree(self.src)
			except : 
				print("{0}".format(self.src))

		# run sub folder
		exclude = '(ch|char|bg)'
		for root, dirs, files in os.walk(dst) :
			for name in files :
				path = os.path.join(root, name)
				if SevenZ.is_archive(path) and not re.search(exclude, name) :
					unzipper = Unzipper(path, False)
					unzipper.unzip()

		self.dst = dst
예제 #4
0
	def rename(self) :
		root = self.paths['rename']
		for name in os.listdir(root) :
			name = os.path.join(root, name) 
			if not SevenZ.is_archive(name) :
				continue

			dest = self.make_new_name(name)
			if dest is None :
				continue

			tool = FileTools(name, dest)
			tool.safe_rename()
예제 #5
0
def doUnzip(root):
    next_phase = os.path.join(root, "wait")
    if not os.path.isdir(next_phase):
        os.mkdir(next_phase)

    backup = os.path.join(next_phase, "#backup")
    if not os.path.isdir(backup):
        os.mkdir(backup)

    root = os.path.join(root, "unzip")

    for name in os.listdir(root):
        name = os.path.join(root, name)
        if SevenZ.is_archive(name):
            unzipper = Unzipper(name, True)
            unzipper.unzip()
            unzipper.done(next_phase, backup)