def makeAlbums(srcDir, destDir, albumCount, imageCountPerAlbum): commonlib.ensureDirExists(srcDir) commonlib.createDirIfNecessary(destDir) for i in range(albumCount): albumDir = os.path.join(destDir, str(i)) print "creating album at", albumDir, "copy", imageCountPerAlbum, "images from", srcDir _makeAlbum(srcDir, albumDir, imageCountPerAlbum)
def makeAlbums(srcDir, destDir, albumCount, imageCountPerAlbum): commonlib.ensureDirExists(srcDir) commonlib.createDirIfNecessary(destDir) for i in range(albumCount): albumDir = os.path.join(destDir, str(i)) print 'creating album at', albumDir, 'copy', imageCountPerAlbum, 'images from', srcDir _makeAlbum(srcDir, albumDir, imageCountPerAlbum)
def m101nights(src, dest): files = os.listdir(src) files = [f for f in files if f.endswith(".txt")] files = sorted(files, key=getNumber) commonlib.createDirIfNecessary(dest) counter = 0 infos = [] for file in files: counter = counter + 1 index = file.find("\xc2") if index != -1: index = index + 2 else: index = file.find(" ") index = index + 1 endIndex = file.index(".txt") bookName = file[index:endIndex] oldFile = os.path.join(src, file) newFile = os.path.join(dest, str(counter).zfill(3) + ".txt") infos.append(str(counter).zfill(3) + "@@@" + str(counter) + ". " + bookName) print oldFile, newFile appendNewLineCopy(oldFile, newFile) f = open(os.path.join(dest, "info"), "w") f.write("\n".join(infos)) f.close()
def m101nights(src, dest): files = os.listdir(src) files = [f for f in files if f.endswith('.txt')] files = sorted(files, key=getNumber) commonlib.createDirIfNecessary(dest) counter = 0 infos = [] for file in files: counter = counter + 1 index = file.find('\xc2') if index != -1: index = index + 2 else: index = file.find(' ') index = index + 1 endIndex = file.index('.txt') bookName = file[index:endIndex] oldFile = os.path.join(src, file) newFile = os.path.join(dest, str(counter).zfill(3) + '.txt') infos.append( str(counter).zfill(3) + '@@@' + str(counter) + '. ' + bookName) print oldFile, newFile appendNewLineCopy(oldFile, newFile) f = open(os.path.join(dest, 'info'), 'w') f.write('\n'.join(infos)) f.close()
def _makeAlbum(srcDir, albumDir, imageCount): commonlib.createDirIfNecessary(albumDir) srcFiles = sorted(os.listdir(srcDir)) totalLen = len(srcFiles) for i in range(imageCount): if i < totalLen: srcFile = os.path.join(srcDir, srcFiles[i]) destFile = os.path.join(albumDir, str(i + 1) + ".jpg") print "move", srcFile, "to", destFile os.rename(srcFile, destFile)
def _makeAlbum(srcDir, albumDir, imageCount): commonlib.createDirIfNecessary(albumDir) srcFiles = sorted(os.listdir(srcDir)) totalLen = len(srcFiles) for i in range(imageCount): if i < totalLen: srcFile = os.path.join(srcDir, srcFiles[i]) destFile = os.path.join(albumDir, str(i + 1) + '.jpg') print 'move', srcFile, 'to', destFile os.rename(srcFile, destFile)
def mergeHuaban(srcDir, destDir, nameLength): commonlib.ensureDirExists(srcDir) commonlib.createDirIfNecessary(destDir) counter = 1 for dirname, dirnames, filenames in os.walk(srcDir): for filename in filenames: srcFile = os.path.join(dirname, filename) destFile = os.path.join(destDir, str(counter).zfill(nameLength) + "_" + filename.split("_")[0] + ".jpg") print "rename", srcFile, "to", destFile os.rename(srcFile, destFile) counter = counter + 1
def mergeFolder(srcDir, destDir, nameLength): commonlib.ensureDirExists(srcDir) counter = int(getLargestFileName(destDir)) + 1 srcDirs = sorted(os.listdir(srcDir)) for dir in srcDirs: tDir = getFullDirName(destDir, counter, nameLength) sDir = os.path.join(srcDir, dir) commonlib.createDirIfNecessary(os.path.dirname(tDir)) print "Move", sDir, "to", tDir os.rename(sDir, tDir) counter = counter + 1
def mergeFolder(srcDir, destDir, nameLength): commonlib.ensureDirExists(srcDir) counter = int(getLargestFileName(destDir)) + 1 srcDirs = sorted(os.listdir(srcDir)) for dir in srcDirs: tDir = getFullDirName(destDir, counter, nameLength) sDir = os.path.join(srcDir, dir) commonlib.createDirIfNecessary(os.path.dirname(tDir)) print 'Move', sDir, 'to', tDir os.rename(sDir, tDir) counter = counter + 1
def mergeHuaban(srcDir, destDir, nameLength): commonlib.ensureDirExists(srcDir) commonlib.createDirIfNecessary(destDir) counter = 1 for dirname, dirnames, filenames in os.walk(srcDir): for filename in filenames: srcFile = os.path.join(dirname, filename) destFile = os.path.join( destDir, str(counter).zfill(nameLength) + '_' + filename.split('_')[0] + '.jpg') print 'rename', srcFile, 'to', destFile os.rename(srcFile, destFile) counter = counter + 1
def plainMerge(srcDir, destDir, nameLength): commonlib.ensureDirExists(srcDir) commonlib.createDirIfNecessary(destDir) destDirs = sorted(os.listdir(destDir)) counter = 0 if len(destDirs) != 0: counter = int(destDirs[-1]) srcDirs = [os.path.join(srcDir, dir) for dir in sorted(os.listdir(srcDir))] for dir in srcDirs: counter = counter + 1 toDir = os.path.join(destDir, str(counter).zfill(nameLength)) print "move", dir, "to", toDir os.rename(dir, toDir)
def plainMerge(srcDir, destDir, nameLength): commonlib.ensureDirExists(srcDir) commonlib.createDirIfNecessary(destDir) destDirs = sorted(os.listdir(destDir)) counter = 0 if len(destDirs) != 0: counter = int(destDirs[-1]) srcDirs = [os.path.join(srcDir, dir) for dir in sorted(os.listdir(srcDir))] for dir in srcDirs: counter = counter + 1 toDir = os.path.join(destDir, str(counter).zfill(nameLength)) print 'move', dir, 'to', toDir os.rename(dir, toDir)
def moveImageToDir_Huaban(srcDir, destDir, destNameLength, n): # 1. get the largest file number in destDir counter = getLargestFileNumberNew(destDir) print 'have ', counter, 'images' counter = counter + 1 # 2. walk srcDir for n times for dirname, dirnames, filenames in os.walk(srcDir): if len(dirnames) == 0 and len(filenames) == 0: continue for file in [ os.path.join(dirname, file) for file in sorted(filenames) ]: print 'processing image ' + file destFile = os.path.join( destDir, commonlib.generateFileNameByIndex(counter, 9, 3)) destThumbnail = destFile + 's.jpg' destFile = destFile + '.jpg' # create temp dir if necessary commonlib.createDirIfNecessary(os.path.dirname(destFile)) # generate thumbnail print 'thumbnail', destThumbnail try: imageThumbnail(file, destThumbnail) except IOError as e: print 'failed process', file print e os.remove(file) continue # move file to print 'moveto', destFile os.rename(file, destFile) counter = counter + 1 n = n - 1 if n <= 0: return
def numberImage(srcDir, destDir): commonlib.createDirIfNecessary(destDir) destFiles = os.listdir(destDir) for file in destFiles: if file != "icon.jpg" and os.path.isfile(os.path.join(destDir, file)): os.remove(os.path.join(destDir, file)) count = 1 for dirname, dirnames, filenames in os.walk(srcDir): filenames = sorted([f for f in filenames if f.lower().endswith(".jpg")]) for file in filenames: srcFile = os.path.join(dirname, file) if file == "icon.jpg": targetFile = os.path.join(destDir, file) else: targetFile = os.path.join(destDir, str(count) + ".jpg") if srcFile != targetFile: print "rename", srcFile, "to", targetFile os.rename(srcFile, targetFile) else: print "skip", srcFile count = count + 1
def moveImageToDir_Huaban(srcDir, destDir, destNameLength, n): # 1. get the largest file number in destDir counter = getLargestFileNumberNew(destDir) print "have ", counter, "images" counter = counter + 1 # 2. walk srcDir for n times for dirname, dirnames, filenames in os.walk(srcDir): if len(dirnames) == 0 and len(filenames) == 0: continue for file in [os.path.join(dirname, file) for file in sorted(filenames)]: print "processing image " + file destFile = os.path.join(destDir, commonlib.generateFileNameByIndex(counter, 9, 3)) destThumbnail = destFile + "s.jpg" destFile = destFile + ".jpg" # create temp dir if necessary commonlib.createDirIfNecessary(os.path.dirname(destFile)) # generate thumbnail print "thumbnail", destThumbnail try: imageThumbnail(file, destThumbnail) except IOError as e: print "failed process", file print e os.remove(file) continue # move file to print "moveto", destFile os.rename(file, destFile) counter = counter + 1 n = n - 1 if n <= 0: return
def numberImage(srcDir, destDir): commonlib.createDirIfNecessary(destDir) destFiles = os.listdir(destDir) for file in destFiles: if file != 'icon.jpg' and os.path.isfile(os.path.join(destDir, file)): os.remove(os.path.join(destDir, file)) count = 1 for dirname, dirnames, filenames in os.walk(srcDir): filenames = sorted( [f for f in filenames if f.lower().endswith('.jpg')]) for file in filenames: srcFile = os.path.join(dirname, file) if file == 'icon.jpg': targetFile = os.path.join(destDir, file) else: targetFile = os.path.join(destDir, str(count) + '.jpg') if srcFile != targetFile: print 'rename', srcFile, 'to', targetFile os.rename(srcFile, targetFile) else: print 'skip', srcFile count = count + 1
# coding=utf8 import os, os.path, shutil, subprocess, stat, pickle, sys, time, commonlib from sets import Set from PIL import Image from string import Template ImageTargetDir = '/tmp/imgtest' ImageSrcDir = '/home/yang/Desktop/tmp' counter = 0 for dirname, dirnames, filenames in os.walk(ImageSrcDir): for file in [os.path.join(dirname, file) for file in filenames]: src = file target = os.path.join(ImageTargetDir, generateFileNameByIndex(counter, 9, 3)) targetDir = os.path.dirname(target) print 'copying ', src, 'to ', target commonlib.createDirIfNecessary(targetDir) shutil.copy(src, target + 's.jpg') os.rename(src, target + '.jpg') counter = counter + 1
# coding=utf8 import os, os.path, shutil, subprocess, stat, pickle, sys, time, commonlib from sets import Set from PIL import Image from string import Template ImageTargetDir = '/tmp/imgtest' ImageSrcDir = '/home/yang/Desktop/tmp' counter = 0 for dirname, dirnames, filenames in os.walk(ImageSrcDir): for file in [os.path.join(dirname, file) for file in filenames]: src = file target = os.path.join(ImageTargetDir, generateFileNameByIndex(counter, 9, 3)) targetDir = os.path.dirname(target) print 'copying ', src, 'to ' , target commonlib.createDirIfNecessary(targetDir) shutil.copy(src, target + 's.jpg') os.rename(src, target + '.jpg') counter = counter + 1