-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.py
64 lines (56 loc) · 2.26 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
import sys
from dotmesh.client import DotmeshClient
# example of how to quieten the logs:
#import logging
#logging.getLogger('jsonrpcclient.client.request').setLevel(logging.ERROR)
#logging.getLogger('jsonrpcclient.client.response').setLevel(logging.ERROR)
# let's set up the cluster access:
api_key = os.environ['DOTMESH_APIKEY']
cluster_url = "http://localhost:32607/rpc"
dmclient = DotmeshClient(cluster_url=cluster_url, username="admin", api_key=api_key)
# now let's create a dot called 'test' and work in a branch called 'master':
dotname = "test"
branchname = "master"
print("== Create dot:")
dot = dmclient.createDot(dotname=dotname)
# alternatively, if a dot already exists,
# you can do the following:
# dot = dmclient.getDot(dotname=dotname)
print("\nID={0}, name={1}".format(dot.id, dot.name))
# get a branch to work on:
print("\n== Get master branch:")
branch = dot.getBranch(branchname)
print("\n{0}".format(branch.name))
# now let's do a commit:
print("\n== Do some commit and show log:")
branch.commit("just a test commit")
branch.commit("and another commit, who would have thought")
branch.commit("here is a commit with some extra metadata", {"fruit": "apples", "color":"red"})
log = branch.log()
print("\n")
for entry in log:
msg = entry["Metadata"]["message"]
ctime = entry["Metadata"]["timestamp"]
print("{0}: {1}".format(ctime, msg))
# time for a new branch:
print("\n== Create new branch, commit and show log:")
mybranch = branch.createBranch("mybranch", "master")
mybranch.commit("the first commit in my branch")
mylog = mybranch.log()
print("\n")
print("{0}: {1}".format(mylog[0]["Metadata"]["timestamp"], mylog[0]["Metadata"]["message"]))
# now let's create a dot called 'other' in the namespace "thing"
# and work in a branch called 'master':
namespace = "thing"
otherdotname = "other"
branchname = "master"
print("== Create dot:")
dot = dmclient.createDot(dotname=otherdotname, ns=namespace)
print("\nnamespace= {0}, ID={1}, name={2}".format(dot.ns, dot.id, dot.name))
# and finally, let's clean up by deleting the dot (and all the commits)
# if instructed so by user, via the optional CLI argument:
if len(sys.argv) > 1 and sys.argv[1]=="cleanup":
print("\n== Clean-up:")
dmclient.deleteDot(dotname=dotname)
dmclient.deleteDot(dotname=otherdotname)