mirror of https://github.com/PurpleI2P/pyseeder
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
"""Git transport plugin""" |
|
import subprocess |
|
import os, os.path |
|
from shutil import copyfile |
|
from pyseeder.utils import TransportException |
|
|
|
TRANSPORT_NAME = "git" |
|
|
|
# Push to github repo witout prompting password. |
|
# Set up SSH keys or change origin URL like that: |
|
# git remote set-url origin https://$USERNAME:$PASSWORD@github.com/$USERNAME/$REPO.git |
|
|
|
def run(filename, config): |
|
if "folder" not in config: |
|
raise TransportException("git: No folder specified in config") |
|
else: |
|
REPO_FOLDER = config["folder"] |
|
|
|
REPO_FILE = os.path.split(filename)[1] |
|
|
|
if not os.access(REPO_FOLDER, os.W_OK): |
|
raise TransportException("git: {} access forbidden" \ |
|
.format(REPO_FOLDER)) |
|
|
|
if not os.path.isfile(filename): |
|
raise TransportException("git: input file not found") |
|
|
|
copyfile(filename, os.path.join(REPO_FOLDER, REPO_FILE)) |
|
|
|
commands = [ |
|
"git add {}".format(REPO_FILE), |
|
"git commit -m 'update'", |
|
"git push origin master" |
|
] |
|
|
|
cwd = os.getcwd() |
|
os.chdir(REPO_FOLDER) |
|
for c in commands: subprocess.call(c, shell=True) |
|
os.chdir(cwd)
|
|
|