From c0aa60db7fe0aeef5d776dd48abf0d5a5a4dda5b Mon Sep 17 00:00:00 2001 From: Nicky Groszewski Date: Wed, 8 Feb 2017 19:07:19 -0500 Subject: [PATCH 1/3] working on windows --- crawl_subject_files.py | 6 ++--- mirror_script/mirror_directory.py | 40 +++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/crawl_subject_files.py b/crawl_subject_files.py index 6fad069..5e38677 100644 --- a/crawl_subject_files.py +++ b/crawl_subject_files.py @@ -376,7 +376,6 @@ def audio_wav_window(self): def crawl_files(self, file_or_dirname): self.start_button.config(state="disable") self.tups=[] - print(self.chosen_subjects) if self.recurse_or_scan.get(): if not file_or_dirname.endswith('.csv'): tkMessageBox.showinfo("Error", "You must provide a csv file to scan or uncheck the top box.") @@ -473,8 +472,8 @@ def copy_files(self, lst): else: for tup in lst: filepath = tup[0] - localdir = os.path.dirname(filepath) - savepath = self.output_dir+localdir + drive, localdir = os.path.splitdrive(filepath) + savepath = os.path.join(self.output_dir, os.path.normpath(os.path.dirname(localdir)).lstrip('\\')) try: with open(savepath) as f: pass except IOError as e: @@ -526,6 +525,7 @@ def update_tups(self, path, sub): self.tups.append((str(path), str(sub))) if self.audio_wav_type.get()=='unscrubbed': if re.search(r'\.wav$', sub) and "scrubbed" not in sub: + print(path, sub) self.tups.append((str(path), str(sub))) if "custom_regex" in self.checked_boxes: if re.search(self.custom_regex_text.get(), sub): diff --git a/mirror_script/mirror_directory.py b/mirror_script/mirror_directory.py index 6e6e3b3..579b0f3 100644 --- a/mirror_script/mirror_directory.py +++ b/mirror_script/mirror_directory.py @@ -7,7 +7,7 @@ import Tkinter as tk # for python2 import tkFileDialog as tkfiledialog import tkMessageBox - from Tkinter import ttk + import ttk except ImportError: import tkinter as tk # for python3 import tkinter.filedialog as tkfiledialog @@ -126,20 +126,52 @@ def mirror_files_to_csv(self, lst): writer.writerow(item) tkMessageBox.showinfo("Completed", "Directory successfully mirrored!") +# def mirror_files_recursive(self, lst): +# for tup in lst: +# filepath = tup[0] +# base_name = os.path.basename(filepath) +# drive, localdir = os.path.splitdrive(filepath) +# savepath = os.path.join(self.output_dir,os.path.dirname(localdir)) +# try: +# with open(savepath): pass +# except IOError: +# if not os.path.exists(savepath): +# os.makedirs(savepath) +# pathBefore = os.getcwd() +# os.chdir(savepath) +# try: +# print("touch", base_name) +# print(savepath) +# subprocess.call(['touch', base_name], shell=True) +# except WindowsError: +# savepath = os.path. +# command = "fsutil file createnew %s 0" % base_name +# subprocess.call([command]) +# os.chdir(pathBefore) +# tkMessageBox.showinfo("Completed", "Directory successfully mirrored!") + + def mirror_files_recursive(self, lst): for tup in lst: filepath = tup[0] base_name = os.path.basename(filepath) - localdir = os.path.dirname(filepath) - savepath = os.path.join(self.output_dir,localdir[1:]) + drive, localdir = os.path.splitdrive(filepath) + savepath = os.path.join(self.output_dir,os.path.normpath(os.path.dirname(localdir)).lstrip('\\')) + print(self.output_dir) + print(os.path.dirname(localdir)) + print("SAVEPATH: " ,savepath) try: with open(savepath): pass except IOError: if not os.path.exists(savepath): os.makedirs(savepath) + print(savepath) pathBefore = os.getcwd() os.chdir(savepath) - subprocess.call(['touch', base_name]) + try: + subprocess.call(['touch', base_name]) + except WindowsError: + open(base_name,'a').close() os.chdir(pathBefore) tkMessageBox.showinfo("Completed", "Directory successfully mirrored!") From 99958fc7befb5f418de3ddbe4827dfd22c9e8a3a Mon Sep 17 00:00:00 2001 From: Nicky Groszewski Date: Wed, 8 Feb 2017 19:08:49 -0500 Subject: [PATCH 2/3] remove print statements --- crawl_subject_files.py | 1 - mirror_script/mirror_directory.py | 29 ----------------------------- 2 files changed, 30 deletions(-) diff --git a/crawl_subject_files.py b/crawl_subject_files.py index 5e38677..e74a2c2 100644 --- a/crawl_subject_files.py +++ b/crawl_subject_files.py @@ -525,7 +525,6 @@ def update_tups(self, path, sub): self.tups.append((str(path), str(sub))) if self.audio_wav_type.get()=='unscrubbed': if re.search(r'\.wav$', sub) and "scrubbed" not in sub: - print(path, sub) self.tups.append((str(path), str(sub))) if "custom_regex" in self.checked_boxes: if re.search(self.custom_regex_text.get(), sub): diff --git a/mirror_script/mirror_directory.py b/mirror_script/mirror_directory.py index 579b0f3..bf9316b 100644 --- a/mirror_script/mirror_directory.py +++ b/mirror_script/mirror_directory.py @@ -126,46 +126,17 @@ def mirror_files_to_csv(self, lst): writer.writerow(item) tkMessageBox.showinfo("Completed", "Directory successfully mirrored!") -# def mirror_files_recursive(self, lst): -# for tup in lst: -# filepath = tup[0] -# base_name = os.path.basename(filepath) -# drive, localdir = os.path.splitdrive(filepath) -# savepath = os.path.join(self.output_dir,os.path.dirname(localdir)) -# try: -# with open(savepath): pass -# except IOError: -# if not os.path.exists(savepath): -# os.makedirs(savepath) -# pathBefore = os.getcwd() -# os.chdir(savepath) -# try: -# print("touch", base_name) -# print(savepath) -# subprocess.call(['touch', base_name], shell=True) -# except WindowsError: -# savepath = os.path. -# command = "fsutil file createnew %s 0" % base_name -# subprocess.call([command]) -# os.chdir(pathBefore) -# tkMessageBox.showinfo("Completed", "Directory successfully mirrored!") - - def mirror_files_recursive(self, lst): for tup in lst: filepath = tup[0] base_name = os.path.basename(filepath) drive, localdir = os.path.splitdrive(filepath) savepath = os.path.join(self.output_dir,os.path.normpath(os.path.dirname(localdir)).lstrip('\\')) - print(self.output_dir) - print(os.path.dirname(localdir)) - print("SAVEPATH: " ,savepath) try: with open(savepath): pass except IOError: if not os.path.exists(savepath): os.makedirs(savepath) - print(savepath) pathBefore = os.getcwd() os.chdir(savepath) try: From d27fd11cf2a15569ad2eb0f92d613e7a2c2e1810 Mon Sep 17 00:00:00 2001 From: nrg12 Date: Wed, 8 Feb 2017 14:33:00 -0500 Subject: [PATCH 3/3] fixed cross platform compatibility issue --- crawl_subject_files.py | 2 +- mirror_script/mirror_directory.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crawl_subject_files.py b/crawl_subject_files.py index e74a2c2..4e04873 100644 --- a/crawl_subject_files.py +++ b/crawl_subject_files.py @@ -473,7 +473,7 @@ def copy_files(self, lst): for tup in lst: filepath = tup[0] drive, localdir = os.path.splitdrive(filepath) - savepath = os.path.join(self.output_dir, os.path.normpath(os.path.dirname(localdir)).lstrip('\\')) + savepath = os.path.join(self.output_dir,os.path.normpath(os.path.dirname(localdir)).lstrip(r"\\").lstrip("/")) try: with open(savepath) as f: pass except IOError as e: diff --git a/mirror_script/mirror_directory.py b/mirror_script/mirror_directory.py index bf9316b..0121cae 100644 --- a/mirror_script/mirror_directory.py +++ b/mirror_script/mirror_directory.py @@ -117,7 +117,7 @@ def mirror_files(self, lst): def mirror_files_to_csv(self, lst): self.getSavePath() x = self.save_filename - if not re.match("(.csv)$", self.save_filename): + if not x.endswith('.csv'): x+=".csv" with open(self.output_dir+'/'+x, 'a') as f: writer = csv.writer(f) @@ -131,7 +131,7 @@ def mirror_files_recursive(self, lst): filepath = tup[0] base_name = os.path.basename(filepath) drive, localdir = os.path.splitdrive(filepath) - savepath = os.path.join(self.output_dir,os.path.normpath(os.path.dirname(localdir)).lstrip('\\')) + savepath = os.path.join(self.output_dir,os.path.normpath(os.path.dirname(localdir)).lstrip(r"\\").lstrip("/")) try: with open(savepath): pass except IOError: