Cloning¶
The clone module¶
-
bookstore.clone.build_notebook_model(content, path)¶ Helper that builds a Contents API compatible model for notebooks.
Parameters: - content (str) – The content of the model.
- path (str) – The path to be targeted.
Returns: Jupyter Contents API compatible model for notebooks
Return type: dict
-
bookstore.clone.build_file_model(content, path)¶ Helper that builds a Contents API compatible model for files.
Parameters: - content (str) – The content of the model
- path (str) – The path to be targeted.
Returns: Jupyter Contents API compatible model for files
Return type: dict
-
bookstore.clone.validate_relpath(relpath, settings, log)¶ Validates that a relative path appropriately resolves given bookstore settings.
Parameters: - relpath (string) – Relative path to a notebook to be cloned.
- settings (BookstoreSettings) – Bookstore configuration.
- log (logging.Logger) – Log (usually from the NotebookApp) for logging endpoint changes.
Returns: Absolute path to file to be cloned.
Return type: Path
BookstoreCloneHandler¶
-
class
bookstore.clone.BookstoreCloneHandler(application: tornado.web.Application, request: tornado.httputil.HTTPServerRequest, **kwargs)¶ Prepares and provides clone options page, populating UI with clone option parameters.
Provides handling for
GETrequests when cloning a notebook from storage (S3). Launches a user interface with cloning options.-
initialize(self)¶ Helper to access bookstore settings.
-
get(self)¶ Checks for valid storage settings and render a UI for clone options.
-
construct_template_params(self, s3_bucket, s3_object_key, s3_version_id=None)¶ Helper to populate Jinja template for cloning option page.
-
get_template(self, name)¶ Loads a Jinja template and its related settings.
-
Methods¶
-
BookstoreCloneHandler.initialize() Helper to retrieve bookstore setting for the session.
-
BookstoreCloneHandler.get() GET /bookstore/clone?s3_bucket=<your_s3_bucket>&s3_key=<your_s3_key>
Renders an options page that will allow you to clone a notebook from a specific bucket via the Bookstore cloning API.
s3_bucket is the bucket you wish to clone from. s3_key is the object key that you wish to clone.
-
BookstoreCloneHandler.construct_template_params(s3_bucket, s3_object_key, s3_version_id=None) Helper that takes valid S3 parameters and populates UI template
Returns: Template parameters in a dictionary Return type: dict
-
BookstoreCloneHandler.get_template(name) Loads a Jinja template by name.
BookstoreCloneAPIHandler¶
-
class
bookstore.clone.BookstoreCloneAPIHandler(application: tornado.web.Application, request: tornado.httputil.HTTPServerRequest, **kwargs)¶ Handle notebook clone from storage.
Provides API handling for
POSTand clones a notebook from storage (S3).-
initialize(self)¶ Helper to access bookstore settings.
-
post(self)¶ Clone a notebook from the location specified by the payload.
-
build_content_model(self, obj, path)¶ Helper that takes a response from S3 and creates a ContentsAPI compatible model.
-
build_post_response_model(self, model, obj, s3_bucket, s3_object_key)¶ Helper that takes a Jupyter Contents API compliant model and adds cloning specific information.
-
Methods¶
-
BookstoreCloneAPIHandler.initialize() Helper to retrieve bookstore setting for the session.
-
BookstoreCloneAPIHandler.post() POST /api/bookstore/clone
Clone a notebook to the path specified in the payload.
The payload type for the request should be:
{ "s3_bucket": string, "s3_key": string, "target_path"?: string "s3_version_id"?: string }The response payload should match the standard Jupyter contents API POST response.
-
BookstoreCloneAPIHandler.build_content_model(content, target_path) Helper that takes a response from S3 and creates a ContentsAPI compatible model.
If the file at target_path already exists, this increments the file name.
Parameters: - content (str) – string encoded file content
- target_path (str) – The the path we wish to clone to, may be incremented if already present.
Returns: Return type: dict
-
BookstoreCloneAPIHandler.build_post_response_model(model, obj, s3_bucket, s3_object_key) Helper that takes a Jupyter Contents API compliant model and adds cloning specific information.
Parameters: - model (dict) – Jupyter Contents API model
- obj (dict) – Log (usually from the NotebookApp) for logging endpoint changes.
- s3_bucket (str) – The S3 bucket we are cloning from
- s3_object_key (str) – The S3 key we are cloning
Returns: Model with additional info about the S3 cloning
Return type: dict
BookstoreFSCloneHandler¶
Methods¶
-
BookstoreFSCloneHandler.initialize()¶ Helper to retrieve bookstore setting for the session.
-
BookstoreFSCloneHandler.get()¶ GET /bookstore/fs-clone?relpath=<your_relpath>
Renders an options page that will allow you to clone a notebook from a via the Bookstore file-system cloning API.
relpath is the relative path that you wish to clone from
-
BookstoreFSCloneHandler.construct_template_params(relpath, fs_clonepath)¶ Helper that takes a valid relpath and populates UI template
Returns: Template parameters in a dictionary Return type: dict
-
BookstoreFSCloneHandler.get_template(name)¶ Loads a Jinja template by name.
BookstoreFSCloneAPIHandler¶
-
class
bookstore.clone.BookstoreFSCloneAPIHandler(application: tornado.web.Application, request: tornado.httputil.HTTPServerRequest, **kwargs)¶ Handle notebook clone from an accessible file system (local or cloud).
Provides API handling for
POSTand clones a notebook from the specified file system (local or cloud).-
initialize(self)¶ Helper to access bookstore settings.
-
post(self)¶ Clone a notebook from the filesystem location specified by the payload.
-
build_content_model(self, content, path)¶ Helper for creating a Jupyter ContentsAPI compatible model.
-
Methods¶
-
BookstoreFSCloneAPIHandler.initialize() Helper to retrieve bookstore setting for the session.
-
BookstoreFSCloneAPIHandler.post() POST /api/bookstore/fs-clone
Clone a notebook to the path specified in the payload.
The payload type for the request should be:
{ "relpath": string, "target_path": string #optional }
The response payload should match the standard Jupyter contents API POST response.
-
BookstoreFSCloneAPIHandler.build_content_model(content, target_path) Helper that takes a content and creates a ContentsAPI compatible model.
If the file at target_path already exists, this increments the file name.
Parameters: - content (dict or string) – dict or string encoded file content
- target_path (str) – The the path we wish to clone to, may be incremented if already present.
Returns: Return type: dict