Example #1
0
 def on_get(self, req, resp, dataset, snapshot=None):
     """Get the tree of files for a snapshot."""
     if snapshot:
         files = get_files(self.store, dataset,
                           branch=snapshot)
         response = get_snapshot(self.store, dataset, snapshot)
         response['files'] = files
         resp.media = response
         resp.status = falcon.HTTP_OK
     else:
         tags = get_snapshots(self.store,
                              dataset)
         resp.media = {'snapshots': tags}
         resp.status = falcon.HTTP_OK
Example #2
0
    def on_get(self, req, resp, dataset, filename=None, snapshot='HEAD'):
        ds_path = self.store.get_dataset_path(dataset)
        if filename:
            try:
                ds = self.store.get_dataset(dataset)
                if ds.repo.is_under_annex([filename])[0]:
                    path = git_show(ds_path, snapshot + ':' + filename)
                    # remove leading relative folder paths
                    fd = path[path.find('.git/annex'):]

                    # if fd fails, that means the file is not present in the annex and we need to get it from s3
                    # so we send the client a 404 to indicate the file was not found locally.
                    fd = open(os.path.join(ds_path, fd), 'rb')
                    resp.stream = fd
                    resp.stream_len = os.fstat(fd.fileno()).st_size
                    resp.status = falcon.HTTP_OK
                else:
                    resp.body = git_show(ds_path, snapshot + ':' + filename)
                    resp.status = falcon.HTTP_OK
            except CalledProcessError:
                # File is not present in tree
                resp.media = {'error': 'file not found in git tree'}
                resp.status = falcon.HTTP_NOT_FOUND
            except IOError:
                # File is not kept locally
                resp.media = {'error': 'file not found'}
                resp.status = falcon.HTTP_NOT_FOUND
            except:
                # Some unknown error
                resp.media = {
                    'error': 'an unknown error occurred accessing this file'
                }
                resp.status = falcon.HTTP_INTERNAL_SERVER_ERROR
                self.logger.exception(
                    'An unknown error processing file "{}"'.format(filename))
        else:
            # Request for index of files
            # Return a list of file objects
            # {name, path, size}
            try:
                if "untracked" in req.params:
                    files = get_untracked_files(self.store, dataset)
                    resp.media = {'files': files}
                else:
                    files = get_files(self.store, dataset, snapshot)
                    resp.media = {'files': files}
            except:
                resp.status = falcon.HTTP_INTERNAL_SERVER_ERROR
Example #3
0
 def on_get(self, req, resp, dataset, filename=None, snapshot='HEAD'):
     ds_path = self.store.get_dataset_path(dataset)
     if filename:
         try:
             file_content = git_show(ds_path, snapshot, filename)
             # If the file begins with an annex path, return that path
             if file_content[0:4096].find('.git/annex') != -1:
                 # Resolve absolute path for annex target
                 target_path = os.path.join(ds_path,
                                            os.path.dirname(filename),
                                            file_content)
                 # Verify the annex path is within the dataset dir
                 if ds_path == os.path.commonpath((ds_path, target_path)):
                     fd = open(target_path, 'rb')
                     resp.stream = fd
                     resp.stream_len = os.fstat(fd.fileno()).st_size
                     resp.status = falcon.HTTP_OK
                 else:
                     resp.media = {'error': 'file not found in git tree'}
                     resp.status = falcon.HTTP_NOT_FOUND
             else:
                 resp.body = file_content
                 resp.status = falcon.HTTP_OK
         except KeyError:
             # File is not present in tree
             resp.media = {'error': 'file not found in git tree'}
             resp.status = falcon.HTTP_NOT_FOUND
         except IOError:
             # File is not kept locally
             resp.media = {'error': 'file not found'}
             resp.status = falcon.HTTP_NOT_FOUND
         except:
             # Some unknown error
             resp.media = {
                 'error': 'an unknown error occurred accessing this file'
             }
             resp.status = falcon.HTTP_INTERNAL_SERVER_ERROR
             self.logger.exception(
                 'An unknown error processing file "{}"'.format(filename))
     else:
         # Request for index of files
         # Return a list of file objects
         # {name, path, size}
         try:
             files = get_files(self.store, dataset, snapshot)
             resp.media = {'files': files}
         except:
             resp.status = falcon.HTTP_INTERNAL_SERVER_ERROR