Skip to content

Commit

Permalink
renamed rest of vars
Browse files Browse the repository at this point in the history
  • Loading branch information
vihdutta committed Mar 12, 2021
1 parent 2a8bebf commit 649297d
Show file tree
Hide file tree
Showing 8 changed files with 6,030 additions and 123 deletions.
10 changes: 5 additions & 5 deletions asfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ def filesidrenamer(dstname, srcfiles, dstfiles):
num = createid(srcfiles, dstfiles)
if '(' in file:
try:
dstrename = file.split('(')[0] + num + file.split('(')[1]
fileider = file.split('(')[0] + num + file.split('(')[1]
except IndexError:
dstrename = file + num
fileider = file + num
else:
try:
dstrename = file.split('.')[0] + num + '.' + file.split('.')[1]
fileider = file.split('.')[0] + num + '.' + file.split('.')[1]
except IndexError:
dstrename = file + num
os.rename(os.path.join(dstname, file), os.path.join(dstname, dstrename))
fileider = file + num
os.rename(os.path.join(dstname, file), os.path.join(dstname, fileider))


def dstsort(dstname):
Expand Down
28 changes: 15 additions & 13 deletions autosort.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import shutil
from PyQt5.QtWidgets import QFileDialog
from asfuncs import createid, dstsort, filesnumrenamer, filesidrenamer
import time

ignoredirs = ('$RECYCLE.BIN', 'System Volume Information')
metadata = False
Expand All @@ -10,43 +11,44 @@
srcfiles = []
dstfiles = []
idfilelist = []
allsrcfiles = []
allsrcfileslen = 0

# base of the copyfromallusbs() function
def copyfromdirs(metadata, replace, sortmethod, dstname):
allsrcfiles.clear()
allsrcfileslen = 0

for srcdir in srcdirs:
for root, dirs, files in os.walk(srcdir):
dirs[:] = [d for d in dirs if d not in ignoredirs]
for file in files:
allsrcfiles.append(file) #allsrcfiles only used for the number of files, make += 1?
tempfilelistlen = len(allsrcfiles)
allsrcfileslen += 1 #allsrcfiles only used for the number of files, make += 1?
tempallsrcfileslen = allsrcfileslen

for root, dirs, files in os.walk(dstname):
for file in files:
dstfiles.append(file)

for srcdir in srcdirs:
for root, dirs, files in os.walk(srcdir):
yield f'In directory {root}'
dirs[:] = [d for d in dirs if d not in ignoredirs]
for file in files:
srcfiles.append(file)
for file in files:
if not replace:
try:
dstrename = file.split('.')[0] + createid(srcfiles, dstfiles) + '.' + file.split('.')[1]
fileider = file.split('.')[0] + createid(srcfiles, dstfiles) + '.' + file.split('.')[1]
except IndexError:
dstrename = file + createid(srcfiles, dstfiles)
fileider = file + createid(srcfiles, dstfiles)
else:
dstrename = file
fileider = file
if metadata:
shutil.copy2(os.path.join(root, file), os.path.join(dstname, dstrename))
shutil.copy2(os.path.join(root, file), os.path.join(dstname, fileider))
else:
shutil.copy(os.path.join(root, file), os.path.join(dstname, dstrename))
dstfiles.append(dstrename)
tempfilelistlen -= 1
yield f'Copied {file}. {tempfilelistlen} of {len(allsrcfiles)} files remaining.'
shutil.copy(os.path.join(root, file), os.path.join(dstname, fileider))
dstfiles.append(fileider)
tempallsrcfileslen -= 1
yield f'Copied "{file}" - {tempallsrcfileslen} of {allsrcfileslen} remain.'
if sortmethod == 2:
if not replace:
filesnumrenamer(dstname, srcfiles, dstfiles, idfilelist)
Expand All @@ -65,5 +67,5 @@ def copyfromdirs(metadata, replace, sortmethod, dstname):
'''testing items'''
# tic = time.perf_counter()
# toc = time.perf_counter()
# with open('filenamehere.txt', 'a') as f:
# with open('testing/filenamehere.txt', 'a') as f:
# f.write(f'File copied in {toc - tic:0.4f} seconds\n')
3 changes: 2 additions & 1 deletion autosortgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,9 @@ def setupUi(self, MainWindow):

def source_button_click(self):
sourcedir = QFileDialog.getExistingDirectory()
self.sourcedisplay.setText(sourcedir)
srcdirs.append(sourcedir)
srcdirsstring = ', '.join(srcdirs)
self.sourcedisplay.setText(srcdirsstring)


def destination_button_click(self):
Expand Down
12 changes: 8 additions & 4 deletions testing/copyfunctionbenchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ def copytimes():
metadata = []
nometadata = []

with open('version_0-9.txt', 'r') as f:
with open('testing/metadata.txt', 'r') as f:
with_metadata = f.readlines()
for data in with_metadata:
float_getter = re.compile(r'\d+\.\d+')
metadata.append(float_getter.findall(data))
fixed_list = [float(element[0]) for element in metadata]
print(f'Old alg: {sum(fixed_list) / len(fixed_list):0.4f} sec avg. (per file) for {len(with_metadata)} files.')
print(f'Metadata Files: {len(with_metadata)}.')
print(f'Metadata: {sum(fixed_list) / len(fixed_list):0.4f} sec avg. (per file).')
print(f'Metadata: {sum(fixed_list):0.4f} sec total\n')

with open('version_1-0.txt', 'r') as f:
with open('testing/nometadata.txt', 'r') as f:
without_metadata = f.readlines()
for data in without_metadata:
float_getter = re.compile(r'\d+\.\d+')
nometadata.append(float_getter.findall(data))
fixed_list = [float(element[0]) for element in nometadata]
print(f'New alg: {sum(fixed_list) / len(fixed_list):0.4f} sec avg. (per file) for {len(without_metadata)} files.')
print(f'No Metadata Files: {len(without_metadata)}.')
print(f'No Metadata: {sum(fixed_list) / len(fixed_list):0.4f} sec avg. (per file) for {len(without_metadata)} files.')
print(f'No Metadata: {sum(fixed_list):0.4f} sec total')

if __name__ == '__main__':
copytimes()
Loading

0 comments on commit 649297d

Please sign in to comment.