Ejemplo n.º 1
0
 def execute():
     files = list(
         filter(lambda x: not os.path.isdir(x),
                glob(path, recursive=True)))
     if files:
         print("New Files Found")
         for index, file in enumerate(files):
             Utils.print_progress_bar(index + 1, len(files),
                                      "Organizing Files")
             fsplit = file.split(FILE_DEL)
             old_name = fsplit[-1]
             if self.org_type == "DIMENSION":
                 vid = cv2.VideoCapture(file)
                 height = vid.get(cv2.CAP_PROP_FRAME_HEIGHT)
                 width = vid.get(cv2.CAP_PROP_FRAME_WIDTH)
                 if height > width:
                     Utils.create_dir(self.dest_dir + "/vertical/")
                     Utils.create_dir(self.dest_dir +
                                      "/vertical/conform/")
                     move(
                         file, self.dest_dir + "/vertical/conform/" +
                         old_name)
                 else:
                     Utils.create_dir(self.dest_dir + "/")
                     move(file, self.dest_dir + "/" + old_name)
Ejemplo n.º 2
0
 def get_files(self):
     urls = self.get_urls()
     with open("files.csv", "w+") as f:
         for i, url in enumerate(urls):
             Utils.print_progress_bar(i,
                                      len(urls),
                                      prefix="Retrieving File Names")
             f.writelines(url[0] + "\n")
Ejemplo n.º 3
0
    def _run_with_csv(self):
        now = str(round(time.time() * 1000))
        self.OUTPUT_FILE += "-" + now
        csvfile = open(self.csv_path, "r")
        csvfile.read(1)
        name_map = {}
        for line in csvfile.readlines():
            line = line.split(",")
            original_name = line[self.oc]
            new_name = line[self.dc]
            name_map[original_name] = new_name

        with open('test.json', "w+") as file:
            file.writelines(json.dumps(name_map))
        try:
            ArchiveUtility.rm_dir(self.OUTPUT_FILE)
            if not self.force:
                Utils.create_dir(self.OUTPUT_FILE)
            path = os.getcwd() + self.directory + FILE_DEL + "**"
            files_to_change = list(
                filter(lambda x: not os.path.isdir(x),
                       glob(path, recursive=True)))
            if not files_to_change:
                ArchiveUtility.rm_dir(self.OUTPUT_FILE)
                self.clean(csvfile,
                           "No files to archive found in: " + self.directory)
            for index, f_name in enumerate(files_to_change):
                fsplit = f_name.split(FILE_DEL)
                old_name = fsplit[-1]
                split_name = os.path.splitext(old_name)
                old_name = split_name[0]
                extension = split_name[1]
                if old_name in name_map:
                    old_dirs_set = fsplit[self.get_depth_to_base(fsplit[1:]
                                                                 ):-1]
                    old_dirs = FILE_DEL.join(old_dirs_set)
                    new_name = name_map[old_name]
                    new_location = self.OUTPUT_FILE + FILE_DEL + old_dirs + FILE_DEL + new_name
                    if self.force:
                        new_path = old_dirs + FILE_DEL + new_name + extension
                        move(f_name, new_path)
                    else:
                        if old_dirs not in self.created_dirs:
                            self.create_directories(old_dirs_set)
                        copyfile(f_name, new_location)
                    Utils.print_progress_bar(index + 1, len(files_to_change))
            if self.force:
                self.clean(csvfile, "Finished. Your files are archived")
            else:
                self.clean(
                    csvfile, "Finished. Your archived files can be found in " +
                    self.OUTPUT_FILE + "-" + now + "|| 00111100 00110011")
        except Exception as e:
            Utils.rm_dir(self.OUTPUT_FILE)
            self.clean(csvfile, "Error: " + str(e))
Ejemplo n.º 4
0
    def _run_default(self):
        now = str(round(time.time() * 1000))
        self.OUTPUT_FILE += "-" + now
        csv_filename = self.OUTPUT_FILE + "-" + now + ".csv"
        csvfile = open(csv_filename, "w+")
        try:
            Utils.rm_dir(self.OUTPUT_FILE)
            Utils.create_dir(self.OUTPUT_FILE)
            path = os.getcwd() + self.directory + FILE_DEL + "**"
            files_to_change = list(
                filter(lambda x: not os.path.isdir(x),
                       glob(path, recursive=True)))
            csv_writer = csv.writer(csvfile,
                                    delimiter=',',
                                    quotechar='|',
                                    quoting=csv.QUOTE_MINIMAL)
            csv_writer.writerow([
                "Original Name", "Archive Name", "Original Directory",
                "Archive Directory"
            ])
            if not files_to_change:
                os.remove(csv_filename)
                ArchiveUtility.rm_dir(self.OUTPUT_FILE)
                self.clean(csvfile,
                           "No files to archive found in: " + self.directory)
            for index, f_name in enumerate(files_to_change):
                fsplit = f_name.split(FILE_DEL)
                old_name = fsplit[-1]
                old_dirs_set = fsplit[self.get_depth_to_base(fsplit[1:]):-1]
                old_dirs = FILE_DEL.join(old_dirs_set)
                new_name = self.rename_file(old_name)

                new_location = self.OUTPUT_FILE \
                               + FILE_DEL + (self.dp if self.dp else "") \
                               + old_dirs + FILE_DEL + new_name

                if old_dirs not in self.created_dirs:
                    self.create_directories(old_dirs_set)

                copyfile(f_name, new_location)
                old_path = FILE_DEL.join(fsplit[4:-1])
                csv_writer.writerow(
                    [old_name, new_name, old_path, new_location])
                self.asset_number += 1
                Utils.print_progress_bar(index + 1, len(files_to_change))
            self.clean(
                csvfile, "Finished. Your archived files can be found in " +
                self.OUTPUT_FILE + "-" + now + "/ and your csv in " +
                csv_filename + " || 00111100 00110011")
        except Exception as e:
            os.remove(csv_filename)
            Utils.rm_dir(self.OUTPUT_FILE)
            self.clean(csvfile, "Error: " + str(e))
Ejemplo n.º 5
0
    def download(self, url, total):
        """ execute the get request and write the file """
        self.sema.acquire()
        headers = {
            "Authorization": "Bearer " + self.api_key,
            "Dropbox-API-Arg": json.dumps({"path": url[0]})
        }
        resp = requests.post("https://content.dropboxapi.com/2/files/download",
                             headers=headers)

        self.write_to_file(url[1], resp.content)
        self.total_downloaded += 1
        Utils.print_progress_bar(self.total_downloaded,
                                 total,
                                 prefix="Downloading Files")
        self.sema.release()