Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added client.py and updated grapple.conf #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
*.pyc
tests/*.json
grappledb
*~
ftp.redhat.com/
combined/
control/
logs/
specs/
requires/
build/
install/
.*.sw[po]
*.py[co]

skein.cfg.*

# ignore files with sensitive data
gh_settings.py
github_settings.py
103 changes: 103 additions & 0 deletions client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
from ConfigParser import SafeConfigParser
import io
import json
import os
import urllib2
import subprocess

CONFIG_ENV_VAR = "GRAPPLE_CONF_FILE"
DEFAULT_CONFIG_FILE = "/etc/grapple/grapple.conf"

CLIENT_SECTION = 'client'
QUERYURL_VAR = 'queryurl'
SUBMITTEDURL_VAR = 'submittedurl'
KOJICONFIG_VAR = 'kojiconfig'
KOJITAG_VAR = 'kojitag'
GITURL_VAR = 'giturl'
GITCOMMIT_VAR = 'gitcommit'
REPLACE_CHARS_VAR = 'replace_chars'

CONFIG_DEFAULTS = {GITURL_VAR: '',
KOJITAG_VAR: '',
GITCOMMIT_VAR: 'HEAD'
}

# Use this for just using defaults if file isn't found
EMPTY_CONFIG = """
[database]

[connections]

[queries]

[client]

"""

config_file = os.environ.get(CONFIG_ENV_VAR, DEFAULT_CONFIG_FILE)
config = SafeConfigParser(CONFIG_DEFAULTS)

config.readfp(io.BytesIO(EMPTY_CONFIG))
values = config.read(config_file)


if not values:
# Convert to logging?
print "Configuration file %s not found, using defaults" % config_file


query_url = config.get(CLIENT_SECTION, QUERYURL_VAR)
submitted_url = config.get(CLIENT_SECTION, SUBMITTEDURL_VAR)

def process_commits():

js = json.load(urllib2.urlopen(query_url))

kojiconfig = None
try:
kojiconfig = config.get(CLIENT_SECTION, KOJICONFIG_VAR)
except:
pass

if len(js):
print "requesting commits from: %s" % query_url
print "-----"

for j in js:
print "processing commit: %s from package: %s" % (j['commit_id'], j['package'])
args = ["/usr/bin/koji"]

if kojiconfig:
args.append("-c")
args.append(kojiconfig)

kojitag = config.get(CLIENT_SECTION, KOJITAG_VAR)
giturl = config.get(CLIENT_SECTION, GITURL_VAR)
commit = config.get(CLIENT_SECTION, GITCOMMIT_VAR)

name = j['package']
replace_chars = config.get(CLIENT_SECTION, REPLACE_CHARS_VAR)
for chars in replace_chars.split():
r, w = chars.split(':')
name = name.replace(r, w)

args.append('build')
args.append('--nowait')
args.append(kojitag)
args.append("%s/%s.git#%s" % (giturl, name, commit))

try:
# print "args: %s" % args
p = subprocess.check_call(args)
except CalledProcessError, e:
print "unable to build package: %s -- error: %s" % (j['package'], e)

try:
print "url: %s/%s" % (submitted_url, j['id'])
urllib2.urlopen("%s/%s" % (submitted_url, j['id']), 'x=y')
except Exception, e:
print "could not mark id %s as submitted -- error: %s" % (j['id'], e)


if __name__ == "__main__":
process_commits()
10 changes: 10 additions & 0 deletions tests/grapple.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ whitelist=127.0.0.1,192.168.0.1

[queries]
defaultlimit=100

[client]
url=http://roman.gooselinux.org:8080
queryurl=%(url)s/getcommits
submittedurl=%(url)s/submitted
kojiconfig=~/.koji/config-goose
kojitag=dist-gl6
giturl=git://github.com/gooselinux
gitcommit=HEAD
replace_chars=+:-