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