Exemplo n.º 1
0
def add_user_to_sentry_logs():
    """Add the current user's OSF ID to all sentry error events"""
    user = get_current_user()

    # Set user id across all threads globally
    data = settings.raven_client.extra.setdefault('data', {})
    context = {'osf_user_id': user.id}
    data.update(context)
Exemplo n.º 2
0
    def __init__(self):
        super().__init__()
        self.user = get_current_user()
        self.__stop = threading.Event()
        self._sync_now_event = threading.Event()

        if not os.path.isdir(self.user.folder):
            raise FolderNotInFileSystem
Exemplo n.º 3
0
def add_user_to_sentry_logs():
    """Add the current user's OSF ID to all sentry error events"""
    user = get_current_user()

    # Set user id across all threads globally
    data = settings.raven_client.extra.setdefault('data', {})
    context = {'osf_user_id': user.id}
    data.update(context)
Exemplo n.º 4
0
 def __init__(self, *, limit=5):
     self.user = get_current_user()
     self.headers = {
         'User-Agent': 'OSF Sync',
         'Authorization': 'Bearer {}'.format(self.user.oauth_token),
     }
     self.throttler = threading.Semaphore(limit)  # TODO: Is throttling active?
     self.request_session = requests.Session()
     self.request_session.headers.update(self.headers)
Exemplo n.º 5
0
 def __init__(self, *, limit=5):
     self.user = get_current_user()
     self.headers = {
         'User-Agent': 'OSF Sync',
         'Authorization': 'Bearer {}'.format(self.user.oauth_token),
     }
     self.throttler = threading.Semaphore(
         limit)  # TODO: Is throttling active?
     self.request_session = requests.Session()
     self.request_session.headers.update(self.headers)
Exemplo n.º 6
0
    def _run(self):
        parent = self.remote.parent.id if self.remote.parent else None

        self.db.name = self.remote.name
        self.db.kind = self.remote.kind
        self.db.provider = self.remote.provider
        self.db.user = get_current_user()
        self.db.parent_id = parent
        self.db.node_id = self.node.id

        with Session() as session:
            session.add(self.db)
            session.commit()
Exemplo n.º 7
0
    def _run(self):
        parent = self.remote.parent.id if self.remote.parent else None

        with Session() as session:
            session.add(
                models.File(id=self.remote.id,
                            name=self.remote.name,
                            kind=self.remote.kind,
                            provider=self.remote.provider,
                            user=get_current_user(),
                            parent_id=parent,
                            node_id=self.node.id))
            session.commit()
Exemplo n.º 8
0
    def _run(self):
        parent = self.remote.parent.id if self.remote.parent else None

        self.db.name = self.remote.name
        self.db.kind = self.remote.kind
        self.db.provider = self.remote.provider
        self.db.user = get_current_user()
        self.db.parent_id = parent
        self.db.node_id = self.node.id

        with Session() as session:
            session.add(self.db)
            session.commit()
Exemplo n.º 9
0
    def _run(self):
        parent = self.remote.parent.id if self.remote.parent else None

        with Session() as session:
            session.add(models.File(
                id=self.remote.id,
                name=self.remote.name,
                kind=self.remote.kind,
                provider=self.remote.provider,
                user=get_current_user(),
                parent_id=parent,
                node_id=self.node.id
            ))
            session.commit()
Exemplo n.º 10
0
    def _run(self):
        parent = self.remote.parent.id if self.remote.parent else None

        self.db.name = self.remote.name
        self.db.kind = self.remote.kind
        self.db.provider = self.remote.provider
        self.db.user = get_current_user()
        self.db.parent_id = parent
        self.db.node_id = self.node.id
        self.db.size = self.remote.size
        self.db.md5 = self.remote.extra['hashes']['md5']
        self.db.sha256 = self.remote.extra['hashes']['sha256']

        with Session() as session:
            session.add(self.db)
            session.commit()
Exemplo n.º 11
0
    def _run(self):
        parent = self.remote.parent.id if self.remote.parent else None

        self.db.name = self.remote.name
        self.db.kind = self.remote.kind
        self.db.provider = self.remote.provider
        self.db.user = get_current_user()
        self.db.parent_id = parent
        self.db.node_id = self.node.id
        self.db.size = self.remote.size
        self.db.md5 = self.remote.extra['hashes']['md5']
        self.db.sha256 = self.remote.extra['hashes']['sha256']

        with Session() as session:
            session.add(self.db)
            session.commit()
Exemplo n.º 12
0
    def _run(self):
        parent = self.remote.parent.id if self.remote.parent else None

        with Session() as session:
            session.add(models.File(
                id=self.remote.id,
                name=self.remote.name,
                kind=self.remote.kind,
                provider=self.remote.provider,
                user=get_current_user(),
                parent_id=parent,
                node_id=self.node.id,
                size=self.remote.size,
                md5=self.remote.extra['hashes']['md5'],
                sha256=self.remote.extra['hashes']['sha256'],
            ))
            session.commit()
Exemplo n.º 13
0
def extract_node(path):
    """Given a file path extract the node id and return the loaded Database object
    Visual, how this method works:
        '/root/OSF/Node - 1244/Components/Node - 1482/OSF Storage/OSF Storage/OSF Storage/file.txt'
        '/OSF/Node - 1244/Components/Node - 1482/OSF Storage/OSF Storage/OSF Storage/file.txt'
        ['/OSF/Node - 1244/Components/Node - 1482/', '', '', '/file.txt']
        '/OSF/Node - 1244/Components/Node - 1482/'
        ['Node - 1244', 'Components', 'Node - 1482']
        'Node - 1482'
        1482
    """
    node_id = path.replace(get_current_user().folder, '').split(settings.OSF_STORAGE_FOLDER)[0].strip(os.path.sep).split(os.path.sep)[-1].split(' - ')[-1]
    try:
        with Session() as session:
            return session.query(models.Node).filter(models.Node.id == node_id).one()
    except NoResultFound:
        raise NodeNotFound(path)
Exemplo n.º 14
0
    def __init__(self):
        super().__init__()

        self.ignore = threading.Event()

        try:
            user = get_current_user()
        except NoResultFound:
            # TODO: This only happens when a user logs out and the db has
            # been cleared. The app tries to run again without a user being
            # being set. This error doesn't disrupt user experience, but we
            # might consider tracking down the specific source and preventing
            # it from happening.
            raise
        self.folder = user.folder

        self.observer = Observer()
        self.observer.schedule(self, self.folder, recursive=True)
Exemplo n.º 15
0
    def _run(self):
        parent = self.remote.parent.id if self.remote.parent else None

        with Session() as session:
            session.add(
                models.File(
                    id=self.remote.id,
                    name=self.remote.name,
                    kind=self.remote.kind,
                    provider=self.remote.provider,
                    user=get_current_user(),
                    parent_id=parent,
                    node_id=self.node.id,
                    size=self.remote.size,
                    md5=self.remote.extra['hashes']['md5'],
                    sha256=self.remote.extra['hashes']['sha256'],
                ))
            session.commit()
Exemplo n.º 16
0
def extract_node(path):
    """Given a file path extract the node id and return the loaded Database object
    Visual, how this method works:
        '/root/OSF/Node - 1244/Components/Node - 1482/OSF Storage/OSF Storage/OSF Storage/file.txt'
        '/OSF/Node - 1244/Components/Node - 1482/OSF Storage/OSF Storage/OSF Storage/file.txt'
        ['/OSF/Node - 1244/Components/Node - 1482/', '', '', '/file.txt']
        '/OSF/Node - 1244/Components/Node - 1482/'
        ['Node - 1244', 'Components', 'Node - 1482']
        'Node - 1482'
        1482
    """
    node_id = path.replace(get_current_user().folder, '').split(
        settings.OSF_STORAGE_FOLDER)[0].strip(os.path.sep).split(
            os.path.sep)[-1].split(' - ')[-1]
    try:
        with Session() as session:
            return session.query(
                models.Node).filter(models.Node.id == node_id).one()
    except NoResultFound:
        raise NodeNotFound(path)
Exemplo n.º 17
0
 def __init__(self):
     self._unreachable = []
     self.user_folder = get_current_user().folder + os.path.sep
Exemplo n.º 18
0
 def __init__(self):
     self._unreachable = []
     self.user_folder = get_current_user().folder + os.path.sep