Exemplo n.º 1
0
async def load():
    from seamless.metalevel.bind_status_graph import bind_status_graph_async
    import json

    global ctx, ctx2, save
    graph = json.load(open("graph/" + PROJNAME + ".seamless"))
    ctx = Context()
    ctx.add_zip("graph/" + PROJNAME + ".zip")
    ctx.set_graph(graph, mounts=True, shares=True)
    await ctx.translation(force=True)

    status_graph = json.load(open("graph/" + PROJNAME +
                                  "-monitoring.seamless"))

    ctx2 = await bind_status_graph_async(
        ctx,
        status_graph,
        mounts=True,
        shares=True,
        zips=["graph/" + PROJNAME + "-monitoring.zip"],
    )

    def save():
        import os, itertools, shutil

        def backup(filename):
            if not os.path.exists(filename):
                return filename
            for n in itertools.count():
                n2 = n if n else ""
                new_filename = "{}.bak{}".format(filename, n2)
                if not os.path.exists(new_filename):
                    break
            shutil.move(filename, new_filename)
            return filename

        ctx.save_graph(backup("graph/" + PROJNAME + ".seamless"))
        ctx2.save_graph(backup("graph/" + PROJNAME + "-monitoring.seamless"))
        ctx.save_zip(backup("graph/" + PROJNAME + ".zip"))
        ctx2.save_zip(backup("graph/" + PROJNAME + "-monitoring.zip"))

    print("""Project loaded.

    Main context is "ctx"
    Status context is "ctx2"
    Run save() to save the context
    """)
Exemplo n.º 2
0
def bind_status_graph(ctx, status_graph, *, zips=None, mounts=False, shares=True):
    """"Creates context that will monitor the status of ctx

The context is loaded from status_graph, which must be a graph in JSON format.
It uses the same manager as ctx.
The status graph's underlying buffers must be available already
(from add_zip or via Seamless database)
The status graph must have a cell called "graph",
 and normally, also a cell shared as "index.html"
The status graph will receive the share namespace "status"

mounts and shares have the same meaning as in from_graph

Additional zips can be provided.
They will be passed to ctx.add_zip before the graph is loaded
"""
    from seamless.highlevel import Context
    ctx2 = Context()
    if zips is not None:
        for zipf in zips:
            ctx2.add_zip(zipf)
    ctx2.share_namespace="status"
    ctx2.set_graph(
        status_graph,
        mounts=mounts,
        shares=shares
    )
    assert "graph" in ctx2.get_children()
    observe_graph_bound = partial(
        observe_graph, ctx, ctx2
    )
    ctx2.translate()
    params = {"runtime": True}
    ctx.observe(("get_graph",), observe_graph_bound, OBSERVE_GRAPH_DELAY, params=params)
    def observe2(graph):
        try:
            graph_rt = ctx2.graph_rt
        except AttributeError:
            graph_rt = None
        if not isinstance(graph_rt, Cell):
            return
        ctx2.graph.set(deepcopy(graph))
    ctx.observe(("get_graph",), observe2, OBSERVE_GRAPH_DELAY)
    return ctx2
Exemplo n.º 3
0
if shareserver_address is not None:
    if shareserver_address == "HOSTNAME":
        shareserver_address = subprocess.getoutput("hostname -I | awk '{print $1}'")
    seamless.shareserver.DEFAULT_ADDRESS = shareserver_address
    print("Setting shareserver address to: {}".format(shareserver_address))

import seamless.stdlib

from seamless.highlevel import load_graph, Context
graph = json.load(args.graph)
if args.zipfile is None and not args.add_zip:
    ctx = load_graph(graph, mounts=args.mounts, shares=args.shares)
else:
    ctx = Context()
    if args.zipfile is not None:
        ctx.add_zip(args.zipfile)
    for zipf in args.add_zip:
        ctx.add_zip(zipf)
    ctx.set_graph(graph, mounts=args.mounts, shares=args.shares)
if args.database:
    params = {}
    db_host = env.get("SEAMLESS_DATABASE_HOST")
    if db_host is not None:
        params["host"] = db_host
    db_port = env.get("SEAMLESS_DATABASE_PORT")
    if db_port is not None:
        params["port"] = db_port
    seamless.database_sink.connect(**params)
    seamless.database_cache.connect(**params)
ctx.translate()
Exemplo n.º 4
0
import seamless
from seamless.core.cache.buffer_cache import buffer_cache
import os

env = os.environ
params = {}
db_host = env.get("SEAMLESS_DATABASE_HOST")
if db_host is not None:
    params["host"] = db_host
db_port = env.get("SEAMLESS_DATABASE_PORT")
if db_port is not None:
    params["port"] = db_port

seamless.database_sink.connect(**params)

# TODO: proper command line options (also for mounts)
import sys
from seamless.highlevel import Context
zipfile = sys.argv[1]
ctx = Context()
checksums = ctx.add_zip(zipfile, incref=True)
for checksum in checksums:
    buffer_cache.decref(bytes.fromhex(checksum))
Exemplo n.º 5
0
import json
import seamless
from seamless.highlevel import load_graph, Context

graph = json.load(open("twopi-result.seamless"))
zipfile = "twopi-result.zip"
""" # Does not work well...
ctx = load_graph(graph)
ctx.add_zip(zipfile)
ctx.translate(force=True)
print(ctx.pi.value)
"""

ctx = Context()
ctx.add_zip(zipfile)  # for now, should be before set_graph to avoid glitches
ctx.set_graph(graph)
ctx.translate()
print(ctx.pi.value.unsilk
      )  # For now, None; could be defined immediately in future
print(ctx.twopi.value.unsilk)  # set to None, because of independence
ctx.compute()  # re-runs the computation;
# in the future, the graph will be loaded more smartly
# so that this is either not needed, or runs instantly (cache hit)
print(ctx.twopi.value.unsilk)
print()
Exemplo n.º 6
0
import seamless
seamless_dir = os.path.dirname(seamless.__file__)

empty = Context()
empty.save_graph("graph/{0}.seamless".format(project_name))
del empty

f = "webgen.seamless"
source = os.path.join(seamless_dir, "graphs", f)
dest = os.path.join("graph", "{0}-webctx.seamless".format(project_name))
shutil.copy(source, dest)
graph = json.load(open(dest))

ctx = Context()
ctx.add_zip(os.path.join(seamless_dir, "graphs", "webgen.zip"))
ctx.set_graph(graph)
ctx.save_vault("vault")

gitignore = """# Seamless vault files and backups

# 1. Independent, big buffers. Uncomment the following line to remove them from version control
### vault/independent/big/*

# 2. Dependent, big buffers. Comment out the following line to put them under version control
vault/dependent/big/*

# 3. Dependent, small buffers. Comment out the following line to put them under version control
vault/dependent/small/*

# 4. Backups of the Seamless graph. Comment out the following line to put them under version control
Exemplo n.º 7
0
from seamless.core.cache.transformation_cache import transformation_cache
if os.path.exists(result_cache):
    with open(result_cache) as f:
        for line in f:
            tf_checksum, result_checksum = line.split()
            tf_checksum = bytes.fromhex(tf_checksum)
            result_checksum = bytes.fromhex(result_checksum)
            transformation_cache.transformation_results[tf_checksum] = \
              result_checksum, False

# /TODO

ctx = Context()

if os.path.exists(buffer_cache):
    ctx.add_zip(buffer_cache)

ctx.pandoc = """
ln -s inputfile input.md
pandoc --standalone --to man input.md -o /dev/stdout
"""
for f in docfiles:
    setattr(ctx, f, Context())
    sctx = getattr(ctx, f)
    md = "{}/{}.md".format(docdir, f)
    sctx.md = Cell("text").set(open(md).read())
    tf = sctx.tf = Transformer()
    tf.language = "bash"
    tf.scriptname = f
    tf.inputfile = sctx.md
    tf.code = ctx.pandoc
Exemplo n.º 8
0
from seamless.highlevel import Context, Transformer, Cell
from seamless import stdlib
import json

import os

os.chdir(os.path.dirname(os.path.abspath(__file__)))
os.system("rm -rf web")
os.system("mkdir web")
os.system("cp -r components web/components")

graph = json.load(open("../status-visualization.seamless"))

ctx = Context()
ctx.add_zip("../status-visualization.zip")
ctx.set_graph(graph)
ctx.gen_vis_status.code.mount("web/gen_vis_status.py")

ctx.include(stdlib.merge)
ctx.seamless2webform = Cell("code")
ctx.seamless2webform = open("seamless2webform.py").read()
ctx.seamless2webform.mount("web/seamless2webform.py")
ctx.generate_webform = Transformer()
ctx.generate_webform.graph = ctx.graph
ctx.generate_webform.pins.graph.celltype = "plain"
ctx.generate_webform.code = ctx.seamless2webform
ctx.autogen_webform = ctx.generate_webform
ctx.autogen_webform.celltype = "plain"
ctx.autogen_webform.mount("web/webform-AUTOGEN.json", "w")
ctx.autogen_webform0 = Cell("text")
ctx.autogen_webform0 = ctx.autogen_webform