random split
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import os,sys
|
||||
import math,shutil,re
|
||||
from random import shuffle
|
||||
|
||||
VERSION="0.1"
|
||||
|
||||
@@ -12,7 +13,8 @@ def setup_options():
|
||||
parser=ArgumentParser(description="Splits files to subfolders equally.")
|
||||
|
||||
parser.add_argument("--order",'-o',type=str,action='store', dest='order',default="sequence",
|
||||
help="Splitting method: sequence, sparse, regexp")
|
||||
help="Splitting method.",
|
||||
choices=['sequence','sparse','regexp','random'])
|
||||
parser.add_argument("-m",action='store_true', dest='move',default=False,
|
||||
help="Move entries instead of hardlink.")
|
||||
parser.add_argument("-f",action='store_true', dest='files',default=False,
|
||||
@@ -133,9 +135,6 @@ def report(outFolders):
|
||||
options=setup_options()
|
||||
outFolders=[]
|
||||
method = options.order.lower().strip()
|
||||
if method not in ('sparse','sequence','regexp'):
|
||||
print("Writing order: \""+method+"\" not recognized.")
|
||||
sys.exit(1)
|
||||
# list files, and remove hidden (.files)
|
||||
inFiles=sorted(filter(lambda x: not x.startswith('.'), os.listdir(options.path)))
|
||||
if options.files:
|
||||
@@ -151,7 +150,9 @@ else:
|
||||
for x in outFolders:
|
||||
if not os.path.isdir(x):
|
||||
os.mkdir(x)
|
||||
|
||||
if method=='random':
|
||||
shuffle(inFiles)
|
||||
fileorder(inFiles,options.path,outFolders,options.n,options.move)
|
||||
if method=='regexp':
|
||||
regexorder(inFiles,options.path,outFolders,matcher,uniqlabel,options.move)
|
||||
if method=='sparse':
|
||||
@@ -159,4 +160,5 @@ if method=='sparse':
|
||||
if method=='sequence':
|
||||
fileorder(inFiles,options.path,outFolders,options.n,options.move)
|
||||
|
||||
|
||||
report(outFolders)
|
||||
|
||||
Reference in New Issue
Block a user