Skip to main content

Some temporal operations over git repositories using, mainly, ssh private keys.

Project description

tempgit

Some temporal operations over git repositories using, mainly, ssh private keys and a git monitor to detect changes in a repository.

Temporal git repository

This is used to get a temporal git repository, for example, to clone it, modify and push the changes without maintaining a local copy of the repository. The syntax is:

from tempgit import TemporalGitRepository

# Using "with" command. The repository will be removed automatically after the "with" command finishes 
with TemporalGitRepository(repository, branch=branch, ssh_key=ssh_key, single_branch=False, depth=1, remove=True) as repo:
    repo.add(...)
    repo.commit(...)
    repo.push()

Where repository is the Git repository URL, the branch the branch name, ssh_key the private key to connect with the repository, single_branch True to download only the selected branch, depth create a shallow clone of that depth, and remove if the local copy of the repository will be removed.

For example:

from tempgit import TemporalGitRepository

# Using "with" command. The repository will be removed automatically after the "with" command finishes 
with TemporalGitRepository(repository, branch=branch, ssh_key=ssh_key) as repo:
    repo.add(file1, file2, file3, ...)  # Add the modifications
    repo.commit('Message')  # Commit the changes
    repo.push()  # Push the commit

# With close(). The repository will be removed when you close the object.
repo = TemporalGitRepository(repository, branch=branch, ssh_key=ssh_key):
repo.add(file1, file2, file3, ...)
repo.commit('Message')
repo.push()
repo.close()

Git monitor

Monitor a Git repository to check if there is any change in the remote repository with respect the local one.

from mysutils.git import GitMonitor

# Function to execute when the is a change
def func(*files: str) -> None:
  # Print the changed files
  print(files)

# Create a monitor instance to execute one only time  
monitor = GitMonitor(func, 'local_dir', 'remote_url', 'branch_name')
# Execute the monitor
monitor.monitor()
# Execute the monitor as a thread
monitor.start()

# If you want to check the git repository several times you need add an interval to
monitor = GitMonitor(func, 'local_dir', 'remote_url', 'branch_name', interval=30)  # 30 seconds
# If you want to execute func() the first time although the repository has not changed, use force
monitor = GitMonitor(func, 'local_dir', 'remote_url', 'branch_name', force=True, interval=30)

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

tempgit-0.1.1.tar.gz (18.6 kB view details)

Uploaded Source

File details

Details for the file tempgit-0.1.1.tar.gz.

File metadata

  • Download URL: tempgit-0.1.1.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for tempgit-0.1.1.tar.gz
Algorithm Hash digest
SHA256 eccaad81c95193dbcae81d7347c26c0843e2e2eea5b3a472cfd95e3a0113d941
MD5 b021239a4a6b685bbccece10d855cf67
BLAKE2b-256 d607914ba8e5f74b3865b564414853d3138ffb2a57939e0b60767cafda7f9cd6

See more details on using hashes here.

Supported by

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