Skip to content

Instantly share code, notes, and snippets.

@eli-schwartz
Last active September 3, 2017 21:25
Show Gist options
  • Save eli-schwartz/6810fade8bee39655be014ea33bd4fe2 to your computer and use it in GitHub Desktop.
Save eli-schwartz/6810fade8bee39655be014ea33bd4fe2 to your computer and use it in GitHub Desktop.
OSC plugin to sync Arch Linux packages into the OpenSUSE Build Service
#!/usr/bin/python2
def do_aursync(self, subcmd, opts):
"""${cmd_name}: Update an Arch package
Assumes canonical sources are in ~/git/pkgbuilds/some-package
or else in /var/aur/some-package
${cmd_usage}
${cmd_option_list}
"""
import os, re, shutil, subprocess, json #, srcinfo.parse
import lxml.etree as ET
source_re = re.compile(r'((?P<filename>.*)::)?(?P<protocol>[a-z+]+)://(?P<host>[^/]*)(?P<path>/.*)')
pkg = os.path.basename(os.path.abspath(os.path.curdir))
candidates = [os.path.join(os.path.expanduser('~/git/pkgbuilds'), pkg), os.path.join('/var/aur', pkg)]
for d in candidates:
if os.path.isdir(d):
pkg_dir = d
break
pkg_files = subprocess.check_output(['git', 'ls-files', '.'], cwd=pkg_dir, universal_newlines=True).splitlines()
for f in os.listdir('.'):
if os.path.isfile(f):
os.unlink(f)
for f in pkg_files:
shutil.copyfile(os.path.join(pkg_dir, f), f)
#with open('.SRCINFO') as f:
# (pkginfo, errors) = srcinfo.parse.parse_srcinfo(f.read())
pkginfo = subprocess.check_output('cat .SRCINFO | parse_srcinfo --json', shell=True)
pkginfo = json.loads(pkginfo.decode('UTF-8'))
services = ET.Element('services')
for source in pkginfo['source']:
rsource = source.split('::')[-1]
url = rsource.split('+')[-1]
children = []
extra_children = {}
if rsource.startswith('git://') or rsource.startswith('git+'):
service_type = 'tar_scm'
children += ['filename']
extra_children.update({'scm': 'git', 'url': url, 'package-meta': 'yes'})
elif '://' in source or rsource.startswith('lp:'):
service_type = 'download_url'
children += ['host', 'protocol', 'path', 'filename']
else:
continue
m = source_re.match(source)
service = ET.SubElement(services, 'service', name=service_type)
for child in [child for child in children if m.group(child) is not None]:
new_child = ET.SubElement(service, 'param', name=child)
new_child.text = m.group(child)
for child in extra_children.keys():
new_child = ET.SubElement(service, 'param', name=child)
new_child.text = extra_children.get(child)
ET.ElementTree(services).write('_service', pretty_print=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment