Skip to content

Instantly share code, notes, and snippets.

@gmacon
Created March 8, 2018 16:18
Show Gist options
  • Save gmacon/ab201fbe6a3b2a40664042dae62df6ab to your computer and use it in GitHub Desktop.
Save gmacon/ab201fbe6a3b2a40664042dae62df6ab to your computer and use it in GitHub Desktop.
script to run spm as a non-root user (for spm build)
#!/usr/bin/env python2
import os
import os.path
import shutil
import subprocess
import sys
import tempfile
import yaml
def call_spm(args, repo_dir):
spm_tmp = tempfile.mkdtemp()
try:
os.mkdir(os.path.join(spm_tmp, 'etc'))
os.mkdir(os.path.join(spm_tmp, 'cache'))
os.mkdir(os.path.join(spm_tmp, 'log'))
with open(os.path.join(spm_tmp, 'etc', 'spm'), 'w') as spm_config:
yaml.safe_dump({
'spm_logfile': os.path.join(spm_tmp, 'log', 'spm'),
'spm_cache_dir': os.path.join(spm_tmp, 'cache'),
'spm_db': os.path.join(spm_tmp, 'cache', 'packages.db'),
'spm_build_dir': repo_dir,
'formula_path': repo_dir,
'pillar_path': repo_dir,
'reactor_path': repo_dir,
}, spm_config)
subprocess.check_call(['spm', '-c', os.path.join(spm_tmp, 'etc')] +
args)
finally:
shutil.rmtree(spm_tmp)
if __name__ == '__main__':
call_spm(sys.argv[1:], 'repo')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment