コード例 #1
0
ファイル: handlers.py プロジェクト: SamuelXu/glusterfs
def generic_handler(ts, key, data):
    """
    Generic handler to broadcast message to all peers, custom handlers
    can be created by func name handler_<event_name>
    Ex: handle_event_volume_create(ts, key, data)
    """
    utils.publish(ts, key, data)
コード例 #2
0
ファイル: handlers.py プロジェクト: Junsu/glusterfs
def handle_event_volume_set(ts, key, data):
    """
    Recieved data will have all the options as one string, split into
    list of options. "key1,value1,key2,value2" into
    [[key1, value1], [key2, value2]]
    """
    opts = data.get("options", "").strip(",").split(",")
    data["options"] = []
    for i, opt in enumerate(opts):
        if i % 2 == 0:
            # Add new array with key
            data["options"].append([opt])
        else:
            # Add to the last added array
            data["options"][-1].append(opt)

    utils.publish(ts, key, data)
コード例 #3
0
ファイル: coffee.py プロジェクト: ryazwinski/coffee
def brew(coffee_type, db):
    if bottle.request.headers.environ.get("REMOTE_ADDR") != "127.0.0.1":
        return json_return(403, "Can only start a brew from the monitor host - sorry.")

    data = db.execute("select id, name from coffees")
    coffees = {row["id"]: row["name"] for row in data}

    if coffee_type not in coffees.keys():
        return json_return(403, "Invalid coffee type.")

    row = db.execute("select dts, coffee from raw_log order by dts desc").fetchone()
    now = datetime.datetime.now()

    if row:
        dt = datetime.datetime.strptime(row["dts"], "%Y-%m-%d %H:%M:%S")
        delta = now - dt

        if delta.seconds < BREW_TIME:
            if coffee_type != row["coffee"]:
                db.execute('update raw_log set coffee=%d where dts="%s"' % (coffee_type, row["dts"]))
                return json_return(200, "brew type changed. Estimated completion: %s" % estimate_complete(dt))
            else:
                return json_return(200, "brew already in progress. Estimated completion: %s" % estimate_complete(dt))

    db.execute("insert into raw_log (coffee) values (%d)" % coffee_type)
    eta = estimate_complete(now)
    ret_str = "Brew started: %s. Estimated completion: %s" % (coffees[coffee_type], eta)

    tweet(ret_str)
    publish(
        json.dumps(
            {
                "human": ret_str,
                "type": "start",
                "coffee": coffees[coffee_type],
                "start": now.strftime("%Y%m%d%H%M%S"),
                "estimate": eta.strftime("%Y%m%d%H%M%S"),
            }
        )
    )

    os.system("(%s/followup.sh %d %s)&" % (os.path.dirname(__file__), BREW_TIME, coffees[coffee_type]))

    return json_return(200, ret_str)
コード例 #4
0
def test_example_459():
    result = publish("""[link](/uri "title")""")
    assert_node(result,
                [nodes.document, nodes.paragraph, nodes.reference, "link"])
    assert_node(result[0][0], refuri="/uri", reftitle='title')
コード例 #5
0
def test_example_474():
    result = publish("[link](foo%20b&auml;)")
    assert_node(result,
                [nodes.document, nodes.paragraph, nodes.reference, "link"])
    assert_node(result[0][0], refuri="foo%20b%C3%A4")
コード例 #6
0
def test_example_172():
    result = publish("[foo]: /url")
    assert_node(result, [nodes.document, nodes.target])
コード例 #7
0
def test_example_175():
    text = ('[foo]: /url\n'
            '"title" ok\n')
    result = publish(text)
    assert_node(result, [nodes.document, (nodes.target,
                                          [nodes.paragraph, '"title" ok'])])
コード例 #8
0
def test_example_114_2():
    text = ("~~~ aa ``` ~~~\n"
            "foo\n"
            "~~~\n")
    result = publish(text)
    assert_node(result, [nodes.document, nodes.literal_block, "foo\n"])
コード例 #9
0
def test_example_14():
    result = publish("+++")
    assert_node(result, [nodes.document, nodes.paragraph, "+++"])
コード例 #10
0
def test_example_66():
    text = ("\n"
            "====\n")
    result = publish(text)
    assert_node(result, [nodes.document, nodes.paragraph, "===="])
コード例 #11
0
def test_example_107():
    text = ("``` ```\n"
            "aaa\n")
    result = publish(text)
    assert_node(result, [nodes.document, nodes.paragraph, (nodes.literal,
                                                           "\naaa")])
コード例 #12
0
def test_example_62():
    text = ("> foo\n"
            "bar\n"
            "===\n")
    result = publish(text)
    assert_node(result, [nodes.document, nodes.block_quote, nodes.paragraph, "foo\nbar\n==="])
コード例 #13
0
def test_example_63():
    text = ("- Foo\n"
            "---\n")
    result = publish(text)
    assert_node(result, [nodes.document, ([nodes.bullet_list, nodes.list_item, "Foo"],
                                          nodes.transition)])
コード例 #14
0
def test_example_61():
    text = ("> Foo\n"
            "---\n")
    result = publish(text)
    assert_node(result, [nodes.document, ([nodes.block_quote, nodes.paragraph, "Foo"],
                                          nodes.transition)])
コード例 #15
0
def test_example_59():
    text = ("Foo\\\n"
            "----\n")
    result = publish(text)
    assert_node(result, [nodes.document, nodes.section, nodes.title, "Foo\\"])
コード例 #16
0
def test_example_56():
    text = ("Foo\n"
            "    ---\n")
    result = publish(text)
    assert_node(result, [nodes.document, nodes.paragraph, "Foo\n---"])
コード例 #17
0
def test_example_45():
    result = publish("# foo#")
    assert_node(result, [nodes.document, nodes.section, nodes.title, "foo#"])
コード例 #18
0
def test_example_67():
    text = ("---\n"
            "---\n")
    result = publish(text)
    assert_node(result, [nodes.document, (nodes.transition,
                                          nodes.transition)])
コード例 #19
0
def test_example_95():
    result = publish("```")
    assert_node(result, [nodes.document, nodes.literal_block])
コード例 #20
0
def test_example_6():
    result = publish(">\t\tfoo\n")
    assert_node(result, [nodes.document, nodes.block_quote, nodes.literal_block, "  foo\n"])
コード例 #21
0
def test_example_114():
    text = ("``` aa ```\n"
            "foo\n")
    result = publish(text)
    assert_node(result, [nodes.document, nodes.paragraph, ([nodes.literal, "aa"],
                                                           "\nfoo")])
コード例 #22
0
def test_example_76():
    text = ("    a simple\n"
            "      indented code block\n")
    result = publish(text)
    assert_node(result, [nodes.document, nodes.literal_block, "a simple\n  indented code block\n"])
コード例 #23
0
def test_example_115():
    text = ("```\n"
            "``` aaa\n"
            "```\n")
    result = publish(text)
    assert_node(result, [nodes.document, nodes.literal_block, "``` aaa\n"])
コード例 #24
0
def test_example_81():
    text = ("    chunk1\n"
            "      \n"
            "      chunk2\n")
    result = publish(text)
    assert_node(result, [nodes.document, nodes.literal_block, "chunk1\n  \n  chunk2\n"])
コード例 #25
0
def test_example_16():
    text = ("--\n"
            "**\n"
            "__\n")
    result = publish(text)
    assert_node(result, [nodes.document, nodes.paragraph, "--\n**\n__"])
コード例 #26
0
def test_example_82():
    text = ("Foo\n"
            "    bar\n")
    result = publish(text)
    assert_node(result, [nodes.document, nodes.paragraph, "Foo\nbar"])
コード例 #27
0
def test_example_174():
    result = publish('[foo]: /url "title" ok')
    assert_node(result, [nodes.document, nodes.paragraph, '[foo]: /url "title" ok'])
コード例 #28
0
def test_example_83():
    text = ("    foo\n"
            "bar\n")
    result = publish(text)
    assert_node(result, [nodes.document, ([nodes.literal_block, "foo\n"],
                                          [nodes.paragraph, "bar"])])
コード例 #29
0
def test_example_2():
    result = publish("  \tfoo\tbaz\t\tbim")
    assert_node(result, [nodes.document, nodes.literal_block, "foo\tbaz\t\tbim"])
コード例 #30
0
ファイル: followup.py プロジェクト: ryazwinski/coffee
#!/usr/bin/env python

from utils import tweet, publish
from datetime import datetime
from time import sleep
import json
import sys

try:
    cmd = sys.argv.pop(0)
    delay = int(sys.argv.pop(0))
    coffee = sys.argv.pop(0)
except:
    print "usage: %s delay coffee" % cmd
    sys.exit(1)

sleep(delay)

msg = "A pot of %s is ready for you. [%s]" % (coffee, datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
tweet(msg)
publish(
    json.dumps(({"type": "complete", "coffee": coffee, "end": datetime.now().strftime("%Y%m%d%H%M%S"), "human": msg}))
)
コード例 #31
0
def test_example_473():
    result = publish("[link](foo\\bar)")
    assert_node(result,
                [nodes.document, nodes.paragraph, nodes.reference, "link"])
    assert_node(result[0][0], refuri="foo%5Cbar")
コード例 #32
0
def test_example_90():
    text = ("``\n"
            "foo\n"
            "``\n")
    result = publish(text)
    assert_node(result, [nodes.document, nodes.paragraph, nodes.literal, "foo"])
コード例 #33
0
def test_example_7():
    result = publish("-\t\tfoo\n")
    assert_node(result, [nodes.document, nodes.bullet_list, nodes.list_item, nodes.literal_block, "  foo\n"])
コード例 #34
0
def test_example_42():
    text = ("# foo ##################################\n"
            "##### foo ##\n")
    result = publish(text)
    assert_node(result, [nodes.document, ([nodes.section, ([nodes.title, "foo"],
                                                           [nodes.section, nodes.title, "foo"])])])