def add_obj_from_full_path(self, child_full_path, parent_obj): file_url = get_ufs_url_for_local_path(child_full_path) is_container = os.path.isdir(child_full_path) tz = get_localzone() last_modified_with_timezone = tz.localize(datetime.datetime.fromtimestamp(os.path.getmtime(child_full_path))) existing_obj = UfsObj.objects.filter(full_path=child_full_path) if existing_obj.exists(): obj = existing_obj[0] is_updated = False if obj.is_container != is_container: obj.is_container = is_container is_updated = True modified_diff = obj.last_modified - last_modified_with_timezone if modified_diff.days > 1: is_updated = True if is_updated: obj.save() else: obj, is_created = UfsObj.objects.get_or_create( ufs_obj_type=UfsObj.TYPE_UFS_OBJ, ufs_url=file_url, parent=parent_obj, is_container=is_container, full_path=child_full_path, user=self.admin_user, source=UfsObj.SOURCE_INDEXER, last_modified=last_modified_with_timezone, ) return obj
def init_with_full_path(self, full_path): self.full_path = full_path self.ufs_url = obj_tools.get_ufs_url_for_local_path(self.full_path) tz = get_localzone() self.last_modified = tz.localize(datetime.datetime.fromtimestamp(os.path.getmtime(self.full_path)))