Skip to content

Commit

Permalink
readies sync
Browse files Browse the repository at this point in the history
  • Loading branch information
rafie committed Jan 26, 2020
1 parent b9a13fe commit eace393
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 9 deletions.
2 changes: 1 addition & 1 deletion opt/readies/paella/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __setattr__(self,name,value):

#----------------------------------------------------------------------------------------------

Global.bb = bb
Global.BB = bb
Global.eprint = eprint
Global.fatal = fatal
Global.cwd = cwd
Expand Down
5 changes: 4 additions & 1 deletion opt/readies/paella/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

#----------------------------------------------------------------------------------------------

if 'PYDEBUG' in os.environ:
pydebug = os.environ.get('PYDEBUG', '')
if pydebug == '1' or pydebug == 'pudb':
try:
from pudb import set_trace as bb
except ImportError:
from pdb import set_trace as bb
elif pydebug == 'pdb':
from pdb import set_trace as bb
else:
def bb(): pass

Expand Down
13 changes: 11 additions & 2 deletions opt/readies/paella/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
from contextlib import contextmanager
import os
import os.path
import urllib.request
import tempfile
try:
from urllib2 import urlopen
except:
from urllib.request import urlopen

#----------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -38,7 +41,10 @@ def wget(url, dest="", tempdir=False):
dest = tempfilepath()
elif tempdir:
dest = os.path.join('/tmp', dest)
urllib.request.urlretrieve(url, dest)
ufile = urlopen(url)
data = ufile.read()
with open(dest, "wb") as file:
file.write(data)
return os.path.abspath(dest)

#----------------------------------------------------------------------------------------------
Expand All @@ -59,3 +65,6 @@ def mkdir_p(dir):
os.makedirs(dir, exist_ok=True)

#----------------------------------------------------------------------------------------------

def relpath(dir, rel):
return os.path.abspath(os.path.join(dir, rel))
16 changes: 14 additions & 2 deletions opt/readies/paella/platform.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

from __future__ import absolute_import
import platform
import re

#----------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -84,6 +85,12 @@ def __init__(self, strict=False):
self.os = 'solaris'
self.os_ver = ''
self.dist = ''
elif self.os == 'freebsd':
self.dist = ''
ver = sh('freebsd-version')
m = re.search(r'([^-]*)-(.*)', ver)
self.os_ver = self.full_os_ver = m.group(1)
self.osnick = self.os + self.os_ver
else:
if strict:
assert(False), "Cannot determine OS"
Expand All @@ -101,7 +108,7 @@ def __init__(self, strict=False):
self.arch = 'arm32v7'

def is_debian_compat(self):
return self.dist == 'debian' or self.dist == 'ubuntu'
return self.dist == 'debian' or self.dist == 'ubuntu' or self.dist == 'linuxmint'

def is_redhat_compat(self):
return self.dist == 'redhat' or self.dist == 'centos' or self.dist == 'amzn'
Expand Down Expand Up @@ -154,6 +161,8 @@ def invoke(self):
self.suse()
elif dist == 'arch':
self.arch()
elif dist == 'linuxmint':
self.linuxmint()
elif dist == 'amzn':
self.amzn()
else:
Expand Down Expand Up @@ -190,7 +199,7 @@ def centos(self):
def fedora(self):
pass

def redhat_compat(self): # centos, rhel
def redhat_compat(self): # centos, rhel, amzn, etc
pass

def redhat(self):
Expand All @@ -214,5 +223,8 @@ def bsd_compat(self):
def freebsd(self):
pass

def linuxmint(self):
pass

def amzn(self):
pass
15 changes: 15 additions & 0 deletions opt/readies/paella/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ def brew_install(self, packs, group=False, _try=False):
for pack in packs.split():
self.run("brew list {} &>/dev/null || brew install {}".format(pack, pack), output_on_error=True, _try=_try)

def pkg_install(self, packs, group=False, _try=False):
self.run("pkg install -q -y " + packs, output_on_error=True, _try=_try)

def install(self, packs, group=False, _try=False):
if self.os == 'linux':
if self.dist == 'fedora': # also include centos 8
Expand All @@ -129,6 +132,8 @@ def install(self, packs, group=False, _try=False):
Assert(False), "Cannot determine installer"
elif self.os == 'macosx':
self.brew_install(packs, group=group, _try=_try)
elif self.os == 'freebsd':
self.pkg_install(packs, group=group, _try=_try)
else:
Assert(False), "Cannot determine installer"

Expand Down Expand Up @@ -219,3 +224,13 @@ def install_git_lfs_on_linux(self, _try=False):
# elif self.platform.is_debian_compat():
# self.run(cmd.format('deb'), _try=_try)
# self.install("git-lfs", _try=_try)

def install_gnu_utils(self, _try=False):
self.install("make findutils gnu-sed")
for x in ['make', 'find', 'sed']:
p = "/usr/local/bin/{}".format(x)
if not os.path.exists(p):
self.run("ln -sf /usr/local/bin/g{} {}".format(x, p))
else:
eprint("Warning: {} exists - not replaced".format(p))

7 changes: 4 additions & 3 deletions opt/readies/paella/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@

import sys
from subprocess import Popen, PIPE
import inspect
import os.path

if (sys.version_info > (3, 0)):
from .utils3 import *
else:
from .utils2 import *

def sh(cmd):
return " ".join(Popen(cmd.split(), stdout=PIPE).communicate()[0].split("\n"))
def current_filepath():
return os.path.abspath(inspect.getfile(inspect.currentframe().f_back))
4 changes: 4 additions & 0 deletions opt/readies/paella/utils2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@

import sys
from subprocess import Popen, PIPE

def eprint(*args, **kwargs):
print >> sys.stderr, ' '.join(map(lambda x: "%s" % x, args))

def sh(cmd):
return " ".join(Popen(cmd.split(), stdout=PIPE).communicate()[0].split("\n"))
5 changes: 5 additions & 0 deletions opt/readies/paella/utils3.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@

import sys
from subprocess import Popen, PIPE

def eprint(*args, **kwargs):
print(*args, file = sys.stderr, **kwargs)

def sh(cmd):
return " ".join(Popen(cmd.split(), stdout=PIPE).communicate()[0].decode('utf-8').split("\n"))

0 comments on commit eace393

Please sign in to comment.