GitPM as a Python library
GitPM can be used as a python library, as well as a command-line tool.
After installing GitPM, you can import it in your python project:
import gitpm
You likely want to use the Project
class, which you can import like this:
from gitpm import Project
Project Initialisation and Creation
from gitpm import Project
# load an existing project like this:
project = Project(path) # path is where your project lays
# or like this:
project = Project.fromSelector(id) # assumes a unique id
project = Project.fromSelector(name) # assumes a unique name
# create a new project
project = Project.create(
".", # where?
name="my-project", # preferably without whitespace
id=None, # default: highest known id + 1
bare=False, # if you want a bare repo
)
Modifying Project Metadata
# get / set IDs
project.getId() # undefined: '----'
project.setId("0000")
# get / set Name
project.getName()
project.setName("new-name")
# get / set Status
project.getStatus() # can also be 'undefined'
project.setStatus("new")
project.setStatus("maintained")
project.setStatus("discontinued")
project.setStatus("completed")
# get / set Tags
project.getTags()
project.setTags("some, comma, separated, tags")
# get / set Description
project.getDescription()
project.setDescription(
"My new project is amazing and you should leave a star :)"
)
Executing git commands
GitPM manages project metadata, git version-controls projects. Here's how you can run git commands for a specific project:
project.execute(argv) # an array like sys.argv
project.execute(
["git", "remote", "add", "origin", "https://github.com/..."]
)
Some common functions are already implemented by GitPM:
project.getLastCommit() # returns a hash
project.getCurrentBranch() # returns a string like 'master'
More Features coming soon... some are already implemented without documentation :)