Skip to main content

A set of helpers classes for daily tasks: a reusable config file, a process helper, and a git interface.

Project description

ctbl_tools: miscelaneous daily tasks helpers

A package with miscelaneous classes meant to help at coding console helpers. Currently there are three classes:

  1. config: it implements a config file that saves itself. It is a specialization of configparser.
  2. process: it runs external processes, it saves the return code, and it helps (a little bit) to parse the standard output (or the standard error).
  3. git: a simple interface for git commands.

config: a self-preserving config file

It implements a config file that saves itself.

The idea is: we want to use a config file for an application, which is a simple text file that contains pairs of values, in a similar fashion to an INI file. If the file exists, it is used; if it doesn't, it is created. We use configparser for this.

An example:

from ctbl_tools.config import config

cfg = config(initpath = '~/somewhere/blabla.ini')
cfg.create_section('my_configuration')
cfg.set('my_configuration', 'x', 1)
cfg.set('my_configuration', 'y', '2')

When the program above ends, it will save all created configuration to the file ~/somewhere/blabla.ini.

process: a helper to run external programs

It runs an external program, and it stores the return code and both the standard output and standard error.

You first create an object of this type:

p = process()

Then run a command:

p.run("whoami")

Immediately after you gain access to the return code, stdout and stderr:

print(p.returncode)
for line in p.stdout:
  print(line)

You may check if return code was 0 (i.e., all good) by checking p.is_ok() to be true. You may also check whether there is any stdout or any stderr with p.is_there_stdout() and with p.is_there_stderr(), respectively.

Finally you may extract information out of stdout by using extract(). This method receives a regular expression and a boolean that is true by default (meaning that you want to inspect stdout; if false it will inspect stderr instead). The method will look for all matches in each line of stdout and store them in a list. The list stores as many elements as lines stdout has, and each element is a list of all matches within the corresponding line.

git: a simple git interface

It provides a simple programmatical interface to git.

First, you create a git object by providing a local path to a repo:

from ctbl_tools.git import git

x = git("~/Dev/my_repo")

The previous will fail if provided path is not a git repo.

Then you may either get the remote urls with x.get_remote(), or a get the status of the working tree by invoking x.get_status().

You may also do a commit with a list of files with x.commit(list-of-files), or do a push (x.git_push('my-commit-message')) or a pull (x.git_pull()).

This package also includes two auxiliary functions:

  • git_clone(url:str, path:str): It clones url into path.
  • is_git_url(url:str): It checks whether url is a valid git url.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ctbl_tools-0.1.3.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ctbl_tools-0.1.3-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file ctbl_tools-0.1.3.tar.gz.

File metadata

  • Download URL: ctbl_tools-0.1.3.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for ctbl_tools-0.1.3.tar.gz
Algorithm Hash digest
SHA256 5013bcdc4d0c2e69d3f902291e004deb07ca266eb049c37c70e38bba30a8bbff
MD5 fccc79965995a779494f688a40249f07
BLAKE2b-256 e8471b02f16dac0b7f8a7a84d5c12c24a4a1f88f8df2d33f3258699018a52beb

See more details on using hashes here.

File details

Details for the file ctbl_tools-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: ctbl_tools-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for ctbl_tools-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b1ad8b0a6ec3fc2410857952be1fba451ef3d32d9d2e1e03a5bcc4b07ac43759
MD5 a6b4c3f3e5288be35d84c4d968ec1e23
BLAKE2b-256 fe9282b6f3df57eaa23e4589713fbca0ad178648633d5bfbd02539d25a4ba725

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page