splitgraph.commandline package
Module contents¶
Splitgraph command line client
Hooks into the API to allow management of Splitgraph repositories and images using sgr
.
- class
splitgraph.commandline.
ClickHandler
(level=0)¶ Bases:
logging.Handler
emit
(record)¶Do whatever it takes to actually log the specified logging record.
This version is intended to be implemented by subclasses and so raises a NotImplementedError.
- class
splitgraph.commandline.
WithExceptionHandler
(name=None, commands=None, **attrs)¶ Bases:
click.core.Group
get_command
(ctx, cmd_name)¶Given a context and a command name, this returns a
Command
object if it exists or returns None.
invoke
(ctx)¶Given a context, this invokes the attached callback (if it exists) in the right way.
splitgraph.commandline.
get_exception_name
(o)¶
Submodules¶
splitgraph.commandline.cloud module¶
Command line routines related to registering/setting up connections to the Splitgraph registry.
splitgraph.commandline.common module¶
Various common functions used by the command line interface.
- class
splitgraph.commandline.common.
Color
¶ Bases:
object
An enumeration of console colors
BLUE
= '\x1b[94m'¶
BOLD
= '\x1b[1m'¶
CYAN
= '\x1b[96m'¶
DARKCYAN
= '\x1b[36m'¶
END
= '\x1b[0m'¶
GREEN
= '\x1b[92m'¶
PURPLE
= '\x1b[95m'¶
RED
= '\x1b[91m'¶
UNDERLINE
= '\x1b[4m'¶
YELLOW
= '\x1b[93m'¶
- class
splitgraph.commandline.common.
ImageType
(default: Optional[str] = 'latest', repository_exists: bool = False, get_image: bool = False)¶ Bases:
click.types.ParamType
Parser that extracts the full image specification (repository and hash/tag).
convert
(value: str, param: Optional[click.core.Parameter], ctx: Optional[click.core.Context]) → Tuple[Repository, Optional[Union[Image, str]]]¶Image specification must have the format [NAMESPACE/]REPOSITORY[:HASH_OR_TAG].
The parser returns a tuple of (repository object, tag or hash).
name
= 'Image'¶the descriptive name of this type
- class
splitgraph.commandline.common.
JsonType
¶ Bases:
click.types.ParamType
Parser for Json – a wrapper around json.loads because without specifying the name Click shows the type for the option/arg as LOADS.
Also supports passing JSON files (pass in @filename.json).
convert
(value: str, param: Optional[click.core.Parameter], ctx: Optional[click.core.Context])¶Converts the value. This is not invoked for values that areNone (the missing value).
name
= 'Json'¶the descriptive name of this type
- class
splitgraph.commandline.common.
RepositoryType
(exists: bool = False)¶ Bases:
click.types.ParamType
convert
(value: str, param: Optional[click.core.Parameter], ctx: Optional[click.core.Context]) → Repository¶Converts the value. This is not invoked for values that areNone (the missing value).
name
= 'Repository'¶the descriptive name of this type
- class
splitgraph.commandline.common.
ResettableStream
(stream)¶ Bases:
io.RawIOBase
Stream that supports reading from the underlying stream and resetting the position once.
We can’t use fseek() in this case, since we might be reading from a pipe. So, we operate this stream in two modes. In the first mode, we mirror all reads into a separate buffer (consuming the input stream). After the user calls reset(), we first output data from the mirrored copy, then continue consuming the input stream (simulating seek(0).
readable
()¶Return whether object was opened for reading.
If False, read() will raise OSError.
readinto
(b)¶
reset
()¶
splitgraph.commandline.common.
emit_sql_results
(results, use_json=False, show_all=False)¶
splitgraph.commandline.common.
load_json_param
(value: str, param: Optional[click.core.Parameter], ctx: Optional[click.core.Context])¶
splitgraph.commandline.common.
remote_switch_option
(*names, **kwargs)¶Adds an option to switch global SG_ENGINE for this invocation of sgr.
This is useful for e.g. tagging or viewing image information on a remote registry. This is not used in operations like commit/checkout (even though nothing is preventing SG_ENGINE switch from working on that if the remote engine supports this), the user should switch SG_ENGINE envvar themselves in that case.
- Parameters
names – Names
kwargs – Passed to click.option
splitgraph.commandline.common.
sql_results_to_str
(results: List[Tuple[Any]], use_json: bool = False) → str¶
splitgraph.commandline.engine module¶
splitgraph.commandline.engine.
copy_to_container
(container: Container, source_path: str, target_path: str) → None¶Copy a file into a Docker container
- Parameters
container – Container object
source_path – Source file path
target_path – Target file path (in the container)
- Returns
splitgraph.commandline.engine.
get_docker_client
()¶Wrapper around client.from_env() that also pings the daemon to make sure it can connect and if not, raises an error.
splitgraph.commandline.engine.
inject_config_into_engines
(engine_prefix, config_path)¶Copy the current config into all engines that are managed by sgr engine. This is so that the engine has the right credentials and settings for when we do layered querying (a Postgres client queries the engine directly and it has to download objects etc).
- Parameters
engine_prefix – Prefix for Docker containers that are considered to be engines
config_path – Path to the config file.
splitgraph.commandline.engine.
list_engines
(prefix, include_all=False, unavailable_ok=True)¶
splitgraph.commandline.engine.
patch_and_save_config
(config, patch)¶
splitgraph.commandline.example module¶
Command line routines generating example data / Splitfiles
splitgraph.commandline.example.
alter_table
(repository: Repository, table_name: str, rows_added: int, rows_deleted: int, rows_updated: int) → None¶Alters the example table, adding/updating/deleting a certain number of rows.
- Parameters
repository – Checked-out Repository object.
table_name – Name of the table
rows_added – Number of rows to add
rows_deleted – Number of rows to remove
rows_updated – Number of rows to update
splitgraph.commandline.example.
generate_table
(repository: Repository, table_name: str, size: int) → None¶Creates a table with an integer primary key and a string value.
- Parameters
repository – Checked-out Repository to create the table in.
table_name – Name of the table to generate
size – Number of rows in the table.
splitgraph.commandline.image_creation module¶
sgr commands related to creating and checking out images
splitgraph.commandline.image_info module¶
sgr commands related to getting information out of / about images
splitgraph.commandline.ingestion module¶
Command line tools for ingesting/exporting Splitgraph images into other formats.
splitgraph.commandline.misc module¶
Miscellaneous image management sgr commands.
splitgraph.commandline.mount module¶
sgr commands related to mounting databases via Postgres FDW
splitgraph.commandline.push_pull module¶
sgr commands related to sharing and downloading images.
splitgraph.commandline.splitfile module¶
sgr commands related to building and rebuilding Splitfiles.