In [40]:
from importlib import reload
from collections import OrderedDict
import os
In [41]:
from IPython.display import display, HTML, IFrame
In [42]:
import expect
reload(expect)
Out[42]:
In [43]:
commands = (
('docker version', 'sudo docker --version'),
('dokku version', 'sudo dokku version'),
('buildpack', 'sudo dokku config:get docs BUILDPACK_URL'),
)
commands = tuple((name, expect.command_template.format(command))
for name, command in commands)
commands = OrderedDict(commands)
In [44]:
def tweet():
jose_tweet = """'<blockquote class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">1. How did I get to the point where I memorized keywords and syntax for 10+ langs?<br>2. Why couldn't some of these be combined?</p>— Jose Diaz-Gonzalez (@savant) <a href="https://twitter.com/savant/status/813945152284852224">December 28, 2016</a></blockquote>
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>'"""
return HTML(jose_tweet)
In [45]:
def wat():
return IFrame(src='//giphy.com/embed/l0NwQGfPV1EcKE3Xa', width=480, height=456)
In [46]:
# !$command syntax fails in a comprehension
outputs = []
for name, command in commands.items():
output = !$command
*_, output = output # want last item
outputs.append((name, output))
In [47]:
outputs = OrderedDict(outputs)
In [48]:
def print_outputs():
for name, value in outputs.items():
print('{: >25} {: >6}'.format(name, value))
In [49]:
def lines_filter(line, state, a='location', b='}'):
start = a in line
end = b in line
if start:
return start
if all((state, end)):
return True
return False
In [50]:
nginx_config = os.path.expanduser('~/projects/dokku-static-nginx/app/nginx.conf.erb')
with open(nginx_config) as fh:
lines = tuple(fh.read().splitlines())
In [51]:
def search_lines(lines, **kwargs):
state = False
i_state = False
indices = []
for n, line in enumerate(lines):
i_state = lines_filter(line, state, **kwargs)
if i_state:
state = lines_filter(line, state, **kwargs)
if all((state, i_state)):
indices.append(n)
if len(indices) == 2:
break
try:
s, e = indices
except ValueError:
s, = indices
e = s
return lines[s:e + 1]
In [52]:
nginx_directive = '\n'.join(search_lines(lines, a='location', b='}'))
In [53]:
nginx_config = os.path.expanduser('~/projects/buildpack-nginx/bin/compile')
with open(nginx_config) as fh:
lines = tuple(fh.read().splitlines())
In [54]:
nginx_version = '\n'.join(search_lines(lines, a='# Nginx 1.11.8', b='ZLIB_TARBALL'))
try:
module_directive = '\n'.join(search_lines(lines, a='--without-http_auth_', b='--without-http_auth_'))
except ValueError:
module_directive = 'empty string'