Skip to content

Commit

Permalink
Update PyPT
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Apr 1, 2017
1 parent 2004376 commit 39ebeba
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 21 deletions.
66 changes: 66 additions & 0 deletions .pypt/AURvm/aurvm_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python
# AURvm client script
# Usage: ./aurvm_client.py $PROJECT $PROJECTLC $version use_git[true|false]
# Part of the Python Project Template.
# Copyright © 2013-2017, Chris Warrick.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions, and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the author of this software nor the names of
# contributors to this software may be used to endorse or promote
# products derived from this software without specific prior written
# consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import base64
import io
import json
import subprocess
import sys

try:
_, project, projectlc, version, use_git = sys.argv
except IndexError:
print("Usage: ./aurvm_client.py $PROJECT $PROJECTLC $version use_git[true|false]")

use_git = True if use_git == 'true' else False
if use_git:
gitver = subprocess.check_output(r"git describe --long | sed -E 's/([^-]*-g)/r\1/;s/-/./g;s/^v//g'", shell=True)
gitver = gitver.decode('utf-8').strip()
else:
gitver = None

with io.open('PKGBUILD', 'r', encoding='utf-8') as fh:
pkgbuild = fh.read()

data = json.dumps({
'project': project,
'projectlc': projectlc,
'version': version,
'use_git': use_git,
'gitver': gitver,
'pkgbuild': pkgbuild
}, ensure_ascii=True, sort_keys=True).encode('utf-8')

print(base64.b64encode(data).decode('utf-8'))
2 changes: 2 additions & 0 deletions .pypt/AURvm/aurvm_heartbeat.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
echo "AURvm OK"
77 changes: 77 additions & 0 deletions .pypt/AURvm/aurvm_host.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env python3
# AURvm host script
# Usage: base64-encoded JSON on stdin
# Part of the Python Project Template.
# Copyright © 2013-2017, Chris Warrick.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions, and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the author of this software nor the names of
# contributors to this software may be used to endorse or promote
# products derived from this software without specific prior written
# consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import base64
import io
import json
import os
import subprocess
import sys

BASEDIR = os.path.expanduser('~/git/aur-pkgbuilds')


def commitaur(msg):
with open('.SRCINFO', 'wb') as fh:
fh.write(subprocess.check_output(['makepkg', '--printsrcinfo']))
subprocess.check_call(['git', 'add', '.'])
subprocess.check_call(['git', 'commit', '-asm', msg])
subprocess.check_call(['git', 'push', '-u', 'origin', 'master'])


data = base64.b64decode(sys.stdin.read().encode('utf-8'))
data = json.loads(data.decode('utf-8'))
msg = data['project'] + ' v' + data['version']
sys.stderr.write("[host] Updating AUR packages...\n")
sys.stderr.flush()

os.chdir(BASEDIR)
os.chdir(data['projectlc'])
with io.open('PKGBUILD', 'w', encoding='utf-8') as fh:
fh.write(data['pkgbuild'])
commitaur(msg)
os.chdir(BASEDIR)

if data['use_git']:
os.chdir(data['projectlc'] + '-git')
subprocess.check_call(["sed", "s/pkgver=.*/pkgver=" + data['gitver'] + "/", "PKGBUILD", "-i"])
commitaur(msg)
os.chdir(BASEDIR)

subprocess.check_call(['./UPDATE-REQUIREMENTS.py'])
subprocess.check_call(['git', 'commit', '-asm', msg])
subprocess.check_call(['git', 'push'])
sys.stderr.write("[host] Done!\n")
sys.stderr.flush()
50 changes: 32 additions & 18 deletions .pypt/hooks/post-release.hook
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
#!/bin/zsh
. .pypt/config
echo -n "Update AUR packages? [Y/n] "
read yn
if [[ "$yn" != "y" && "$yn" != "Y" && "$yn" != "" ]]; then
# To change default, move the ` || "$rln" == ""` condition wherever you desire
# and change the capital letter in the prompt
echo -n "Update AUR packages? [Remotely/locally/no] "
read rln
if [[ "$rln" == "N" || "$rln" == "n" ]]; then
exit 0
fi
if [[ "$rln" == "L" || "$rln" == "l" ]]; then
echo "Updating AUR packages..."
gitver=$(git describe --long | sed -E 's/([^-]*-g)/r\1/;s/-/./g;s/^v//g')

echo "Updating AUR packages..."
gitver=$(git describe --long | sed -E 's/([^-]*-g)/r\1/;s/-/./g;s/^v//g')
cp PKGBUILD ~/git/aur-pkgbuilds/$PROJECTLC/PKGBUILD
cd ~/git/aur-pkgbuilds
. ~/git/aur-pkgbuilds/aur.zsh

cp PKGBUILD ~/git/aur-pkgbuilds/$PROJECTLC/PKGBUILD
cd ~/git/aur-pkgbuilds
. ~/git/aur-pkgbuilds/aur.zsh
cd "$PROJECTLC"
commitaur "$PROJECT v$version"

cd "$PROJECTLC"
commitaur "$PROJECT v$version"
cd "$PROJECTLC"-git
sed "s/pkgver=.*/pkgver=$gitver/" PKGBUILD -i
commitaur "$PROJECT v$version"

cd "$PROJECTLC"-git
sed "s/pkgver=.*/pkgver=$gitver/" PKGBUILD -i
commitaur "$PROJECT v$version"
./UPDATE-REQUIREMENTS.py
git commit -asm "$PROJECT v$version"
git push

./UPDATE-REQUIREMENTS.py
git commit -asm "$PROJECT v$version"
git push

echo "Done!"
echo "Done!"
fi
if [[ "$rln" == "R" || "$rln" == "r" || "$rln" == "" ]]; then
avout=""
echo "[local] Attempting to remote into Arch Linux VM (ssh arch)..."
while [[ "$avout" != "AURvm OK" ]]; do
echo "[local] Sending heartbeat..."
avout=$(ssh arch git/aur-pkgbuilds/aurvm_heartbeat.sh)
done
echo "[local] Sending data..."
.pypt/AURvm/aurvm_client.py | ssh arch git/aur-pkgbuilds/aurvm_host.py
echo "[local] Done!"
fi
6 changes: 3 additions & 3 deletions release
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ status 'Generating locales...'

status 'Importing...'
python -c "import $PROJECTLC"
if [[ $? == 1 ]]; then
if [[ $? != 0 ]]; then
error "Import failed. Fix your code or don't come back."
exit 1
fi

if [[ -e tests ]]; then
status 'Running tests...'
py.test tests/
if [[ $? == 1 ]]; then
pytest tests/
if [[ $? != 0 ]]; then
error "Tests failed. Fix your code or don't come back."
exit 1
fi
Expand Down

0 comments on commit 39ebeba

Please sign in to comment.