summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2014-05-16 15:47:24 -0300
committerTomás Touceda <chiiph@leap.se>2014-05-16 15:47:24 -0300
commit5cb40a959af827e4eadde1c047664c4f4c0ae01d (patch)
treeb11f91ee018a23e0afd7be8c1bc74e0c34a1e64b /scripts
parentce22976cc0e203e53799e771aa5e3717d498cc5c (diff)
parent4375c180b3de4eb84603bf15755ae1f7635804fe (diff)
Merge branch 'release-0.5.1'0.5.1
Diffstat (limited to 'scripts')
-rw-r--r--scripts/compile_design_docs.py111
-rw-r--r--scripts/ddocs/update_design_docs.py (renamed from scripts/update_design_docs.py)0
-rwxr-xr-xscripts/profiling/backends_cpu_usage/log_cpu_usage.py (renamed from scripts/backends_cpu_usage/log_cpu_usage.py)0
-rw-r--r--scripts/profiling/backends_cpu_usage/movingaverage.py (renamed from scripts/backends_cpu_usage/movingaverage.py)0
-rwxr-xr-xscripts/profiling/backends_cpu_usage/plot.py (renamed from scripts/backends_cpu_usage/plot.py)0
-rwxr-xr-xscripts/profiling/backends_cpu_usage/test_u1db_sync.py (renamed from scripts/backends_cpu_usage/test_u1db_sync.py)0
-rwxr-xr-xscripts/profiling/doc_put_memory_usage/find_max_upload_size.py (renamed from scripts/doc_put_memory_usage/find_max_upload_size.py)0
-rwxr-xr-xscripts/profiling/doc_put_memory_usage/get-mem.py (renamed from scripts/doc_put_memory_usage/get-mem.py)0
-rwxr-xr-xscripts/profiling/doc_put_memory_usage/plot-mem.py (renamed from scripts/doc_put_memory_usage/plot-mem.py)0
9 files changed, 111 insertions, 0 deletions
diff --git a/scripts/compile_design_docs.py b/scripts/compile_design_docs.py
new file mode 100644
index 00000000..7ffebb10
--- /dev/null
+++ b/scripts/compile_design_docs.py
@@ -0,0 +1,111 @@
+#!/usr/bin/python
+
+
+# This script builds files for the design documents represented in the
+# ../common/src/soledad/common/ddocs directory structure (relative to the
+# current location of the script) into a target directory.
+
+
+import argparse
+from os import listdir
+from os.path import realpath, dirname, isdir, join, isfile, basename
+import json
+
+DDOCS_REL_PATH = ('..', 'common', 'src', 'leap', 'soledad', 'common', 'ddocs')
+
+
+def build_ddocs():
+ """
+ Build design documents.
+
+ For ease of development, couch backend design documents are stored as
+ `.js` files in subdirectories of
+ `../common/src/leap/soledad/common/ddocs`. This function scans that
+ directory for javascript files, and builds the design documents structure.
+
+ This funciton uses the following conventions to generate design documents:
+
+ - Design documents are represented by directories in the form
+ `<prefix>/<ddoc>`, there prefix is the `src/leap/soledad/common/ddocs`
+ directory.
+ - Design document directories might contain `views`, `lists` and
+ `updates` subdirectories.
+ - Views subdirectories must contain a `map.js` file and may contain a
+ `reduce.js` file.
+ - List and updates subdirectories may contain any number of javascript
+ files (i.e. ending in `.js`) whose names will be mapped to the
+ corresponding list or update function name.
+ """
+ ddocs = {}
+
+ # design docs are represented by subdirectories of `DDOCS_REL_PATH`
+ cur_pwd = dirname(realpath(__file__))
+ ddocs_path = join(cur_pwd, *DDOCS_REL_PATH)
+ for ddoc in [f for f in listdir(ddocs_path)
+ if isdir(join(ddocs_path, f))]:
+
+ ddocs[ddoc] = {'_id': '_design/%s' % ddoc}
+
+ for t in ['views', 'lists', 'updates']:
+ tdir = join(ddocs_path, ddoc, t)
+ if isdir(tdir):
+
+ ddocs[ddoc][t] = {}
+
+ if t == 'views': # handle views (with map/reduce functions)
+ for view in [f for f in listdir(tdir)
+ if isdir(join(tdir, f))]:
+ # look for map.js and reduce.js
+ mapfile = join(tdir, view, 'map.js')
+ reducefile = join(tdir, view, 'reduce.js')
+ mapfun = None
+ reducefun = None
+ try:
+ with open(mapfile) as f:
+ mapfun = f.read()
+ except IOError:
+ pass
+ try:
+ with open(reducefile) as f:
+ reducefun = f.read()
+ except IOError:
+ pass
+ ddocs[ddoc]['views'][view] = {}
+
+ if mapfun is not None:
+ ddocs[ddoc]['views'][view]['map'] = mapfun
+ if reducefun is not None:
+ ddocs[ddoc]['views'][view]['reduce'] = reducefun
+
+ else: # handle lists, updates, etc
+ for fun in [f for f in listdir(tdir)
+ if isfile(join(tdir, f))]:
+ funfile = join(tdir, fun)
+ funname = basename(funfile).replace('.js', '')
+ try:
+ with open(funfile) as f:
+ ddocs[ddoc][t][funname] = f.read()
+ except IOError:
+ pass
+ return ddocs
+
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ 'target', type=str,
+ help='the target dir where to store design documents')
+ args = parser.parse_args()
+
+ # check if given target is a directory
+ if not isdir(args.target):
+ print 'Error: %s is not a directory.' % args.target
+ exit(1)
+
+ # write desifgn docs files
+ ddocs = build_ddocs()
+ for ddoc in ddocs:
+ ddoc_filename = "%s.json" % ddoc
+ with open(join(args.target, ddoc_filename), 'w') as f:
+ f.write("%s" % json.dumps(ddocs[ddoc], indent=3))
+ print "Wrote _design/%s content in %s" % (ddoc, join(args.target, ddoc_filename,))
diff --git a/scripts/update_design_docs.py b/scripts/ddocs/update_design_docs.py
index e7b5a29c..e7b5a29c 100644
--- a/scripts/update_design_docs.py
+++ b/scripts/ddocs/update_design_docs.py
diff --git a/scripts/backends_cpu_usage/log_cpu_usage.py b/scripts/profiling/backends_cpu_usage/log_cpu_usage.py
index 2674e1ff..2674e1ff 100755
--- a/scripts/backends_cpu_usage/log_cpu_usage.py
+++ b/scripts/profiling/backends_cpu_usage/log_cpu_usage.py
diff --git a/scripts/backends_cpu_usage/movingaverage.py b/scripts/profiling/backends_cpu_usage/movingaverage.py
index bac1b3e1..bac1b3e1 100644
--- a/scripts/backends_cpu_usage/movingaverage.py
+++ b/scripts/profiling/backends_cpu_usage/movingaverage.py
diff --git a/scripts/backends_cpu_usage/plot.py b/scripts/profiling/backends_cpu_usage/plot.py
index 4e5083ad..4e5083ad 100755
--- a/scripts/backends_cpu_usage/plot.py
+++ b/scripts/profiling/backends_cpu_usage/plot.py
diff --git a/scripts/backends_cpu_usage/test_u1db_sync.py b/scripts/profiling/backends_cpu_usage/test_u1db_sync.py
index 26ef8f9f..26ef8f9f 100755
--- a/scripts/backends_cpu_usage/test_u1db_sync.py
+++ b/scripts/profiling/backends_cpu_usage/test_u1db_sync.py
diff --git a/scripts/doc_put_memory_usage/find_max_upload_size.py b/scripts/profiling/doc_put_memory_usage/find_max_upload_size.py
index 02c68015..02c68015 100755
--- a/scripts/doc_put_memory_usage/find_max_upload_size.py
+++ b/scripts/profiling/doc_put_memory_usage/find_max_upload_size.py
diff --git a/scripts/doc_put_memory_usage/get-mem.py b/scripts/profiling/doc_put_memory_usage/get-mem.py
index d64875fc..d64875fc 100755
--- a/scripts/doc_put_memory_usage/get-mem.py
+++ b/scripts/profiling/doc_put_memory_usage/get-mem.py
diff --git a/scripts/doc_put_memory_usage/plot-mem.py b/scripts/profiling/doc_put_memory_usage/plot-mem.py
index e24679a2..e24679a2 100755
--- a/scripts/doc_put_memory_usage/plot-mem.py
+++ b/scripts/profiling/doc_put_memory_usage/plot-mem.py