Exemple #1
0
    def _validate_source(self, p_item: PItem):
        # 1) Does the source still exists
        if not os.path.exists(p_item.current_location):
            self.logger.info("MOVED:\t{}\t{}".format(p_item.current_location, p_item.get_p_root()))
            self.moved.write("{}\t{}\t{}\t{}\n".format(p_item.current_location, p_item.get_p_root(),
                                                       time.strftime("%Y-%m-%d", time.gmtime()), "Script"))
            self.moved.flush()
            # No Move on to the next level_5.
            return Mover.NEW_LOOP

        # 2) Is the source valid
        self.logger.info("VALIDATING:\t{}".format(p_item.current_location))
        if not self._full_validate(p_item.current_location):
            # 2a) No. Is it because of Thumbs
            self.logger.info("NOT VALID:\t{}".format(p_item.current_location))
            self.logger.info("REMOVE THUMBS:\t{}".format(p_item.current_location))
            self._remove_thumbs_in_bag(p_item.current_location)
            self.logger.info("VALIDATING:\t{}".format(p_item.current_location))
            if not self._full_validate(p_item.current_location):
                # 2b) No. Punt
                self.logger.info("NOT VALID:\t{}".format(p_item.current_location))
                self.logger.info("NOT MOVED:\t{}".format(p_item.current_location))
                self.review.write("{}\t{}\t{}\t{}\n".format('NOT MOVED', p_item.current_location,
                                                            self.sanc_bagger.which_error()[0],
                                                            self.sanc_bagger.which_error()[1]))
                self.review.flush()
                # Done as much as we can with this one move on. Source is left in place
                return Mover.NEW_LOOP
        return Mover.KEEP_GOING
Exemple #2
0
    def _verify_destination(self, p_item: PItem):
        # This function assumes the source still exists and is valid.
        # Returns True if path is in place and complete
        # Returns False is path is in anyway not complete

        # 1) does destination exist
        if not os.path.exists(p_item.get_p_root()):
            return False

        # 2) Path exists
        #    Do both source and destination have the same number of files

        if not self._do_paths_have_same_num_files(p_item.current_location, p_item.get_p_root()):
            # File mismatch
            return False

        # 3) Number of files are the same
        #    is the Destination valid
        if not self._full_validate(p_item.get_p_root()):
            # Destination is not valid.
            return False
        return True
Exemple #3
0
 def _move_path(self, p_item: PItem) -> bool:
     self.logger.info("Source is valid and destination is clear.")
     self.logger.info("MOVING:\t{}:\t{}".format(p_item.current_location, p_item.get_p_root()))
     try:
         cp = CopyProgress("\\\\?\\" + p_item.current_location, p_item.get_p_root(), CopyProgress.FILES)
         cp.start_copy()
         self.logger.info("VALIDATING: {}".format(p_item.get_p_root()))
         if self._full_validate(p_item.get_p_root()):
             self.logger.info("VALID: {}".format(p_item.get_p_root()))
             self.logger.info("REMOVING: {}".format(p_item.current_location))
             self._sanc_rmtree(p_item.current_location)
             self.logger.info("REMOVED: {}".format(p_item.current_location))
             self.moved.write("{}\t{}\t{}\t{}\n".format(p_item.current_location, p_item.get_p_root(),
                                                time.strftime("%Y-%m-%d", time.gmtime()), "Script"))
             self.moved.flush()
             return True
         else:
             self.logger.info("NOT VALID: {}".format(p_item.get_p_root()))
             self.review.write("{}\t{}\t{}\t{}\n".format(p_item.current_location, p_item.get_p_root(),
                                                         self.sanc_bagger.which_error()[0],
                                                         self.sanc_bagger.which_error()[1]))
             self.review.flush()
             return False
     except FileNotFoundError as e:
         self.logger.error("NOT FOUND: {}".format(p_item.current_location))
         self.review.write("{}\t{}\n".format(p_item.current_location, "NOT FOUND"))
         self.review.flush()
         return False
     except BagValidationError as e:
         self.logger.error("{}: {}".format(e, p_item.current_location))
         self.review.write("{}\t{}\n".format(p_item.current_location, e))
         self.review.flush()
         return False
     except Exception as e:
         self.logger.error("{}: {}".format(e, p_item.current_location))
         self.review.write("{}\t{}\n".format(p_item.current_location, e))
         self.review.flush()
         return False
def old_method_from_file():
    val = False
    pu = PathUnique()
    source_fn = old_file_chooser()
    pre = False
    if len(args) > 1:
        pre = True
    comp_move = open("L:\\Intranet\\ar\Digital_Services\\Inventory\\002_TO_BE_MOVED\\{}".format(source_fn), "r")
    moved_file_name = source_fn.split(".")[0]
    moved = "L:\\Intranet\\ar\\Digital_Services\\Inventory\\004_COMPLETED\\{}_MOVED.tsv".format(moved_file_name)
    not_moved = "L:\\Intranet\\ar\\Digital_Services\\Inventory\\003_NEEDS_REVIEW\\{}_REVIEW.tsv".format(moved_file_name)
    lines = []
    item_list = []

    for f in comp_move.readlines():
        l = f.strip().split("\t")
        if not pre:
            pi = PItem(l, False)
            pr = pi.get_p_root()
            if val:
                if pu.is_unique(pr):
                    item_list.append(pi)
                else:
                    print("NOT UNIQUE: {}\t{}".format(pi.current_location, pr))
                    sys.exit(-1)
            else:
                item_list.append(pi)
        else:
            p = PItem(l, True)
            p.p_location = l[1]
            p.current_location = l[0]
            item_list.append(p)
    if val:
        pu.save()
    mv = Mover(item_list, comp_move.name)
    mv.moved_log = moved
    mv.not_moved_log = not_moved
    mv.start_move()
    try:
        projectId = ProjectID(project_file=f, project_added=datetime.now())
        projectId.save()
        print("Starting project: {}".format(f))
    except IntegrityError as e:
        print("Getting project: {}".format(f))
        projectId = ProjectID.get(ProjectID.project_file == f)
        if projectId.project_completed:
            print("This project has been successfully completed")
            exit(1)

    with open(f) as fh:
        for line in fh.readlines():
            s = line.strip().split("\t")
            pi = PItem(s, False)
            print("Adding to database: {}".format(pi.current_location))
            s2p = StoPDB(pid=projectId)
            try:
                s2p.p_root = pi.p_location
                s2p.s_root = pi.current_location
                s2p.save()
            except IntegrityError as e:
                print("{}\t{}".format(e, pi.p_location))
                exit(-1)
            if os.path.exists(pi.p_location):
                s2p.completed_move = True
                s2p.save()
            parts = StoPparts(root=s2p)
            parts.lvl1 = pi.record_status
            parts.lvl2 = pi.collection_type
Exemple #6
0
 def _verify_dest(self, p_item: PItem):
     if not os.path.exists(p_item.get_p_root()):
         self.logger.info("CLEAR:\t{}".format(p_item.get_p_root()))
         return Mover.NEW_LOOP
Exemple #7
0
    pu = PathUnique()
    source_fn = file_chooser()
    pre = False
    if len(args) > 1:
        pre = True
    comp_move = open("L:\\Intranet\\ar\Digital_Services\\Inventory\\002_TO_BE_MOVED\\{}".format(source_fn), "r")
    moved_file_name = source_fn.split(".")[0]
    moved = "L:\\Intranet\\ar\\Digital_Services\\Inventory\\004_COMPLETED\\{}_MOVED.tsv".format(moved_file_name)
    not_moved = "L:\\Intranet\\ar\\Digital_Services\\Inventory\\003_NEEDS_REVIEW\\{}_REVIEW.tsv".format(moved_file_name)
    lines = []
    item_list = []

    for f in comp_move.readlines():
        l = f.strip().split("\t")
        if not pre:
            pi = PItem(l, False)
            pr = pi.get_p_root()
            if val:
                if pu.is_unique(pr):
                    item_list.append(pi)
                else:
                    print("NOT UNIQUE: {}\t{}".format(pi.current_location, pr))
                    sys.exit(-1)
            else:
                item_list.append(pi)
        else:
            p = PItem(l, True)
            p.p_location = l[1]
            p.current_location = l[0]
            item_list.append(p)
    if val: