def generate_html(i, o, defines): log.v("> cryptobox.html") mkdir(os.path.dirname(o)) open(o, "w").write(embed_html(i, defines, defines['path.jquery_ui_css_images'])) log.v(">> Copy clippy.swf") shutil.copyfile(defines['path.clippy'], os.path.dirname(o) + "/clippy.swf")
def mkdir(paths): """ Stupid mkdir wrapper to bypass exceptions """ if type(paths) != list: paths = [ paths ] for p in paths: try: os.mkdir(p) except Exception as e: log.v("Couldn't create directory %s (%s)" % (p, e))
def __handle_node(search_paths, tp, v): for path in search_paths: f = path + '/' + tp try: data = pp(f, v) except: log.v("Tried " + f) continue log.v("Read " + f) try: jdata = json.loads(data) except Exception as e: raise Exception("Invalid JSON data in '" + f + "':\n" + str(e)) jdata['type'] = tp.split('/')[0] if jdata['type'] == 'login': jdata['vars'] = v if len(v['tag']) == 0: jdata['tag'] = '__default__' else: jdata['tag'] = v['tag'] return jdata if tp.split('/')[0] == 'login': log.w("Not found entry type '%s'" % tp) jdata = {} jdata['vars'] = v jdata['tag'] = '__default__' jdata['type'] = 'login' jdata['name'] = '/'.join(tp.split('/')[1:]) jdata['address'] = 'http://' + jdata['name'] jdata['form'] = {} return jdata else: raise Exception("Not found entry type '%s'" % tp)
def generate_bookmarklet(i, o, defines): log.v("> bookmarklet/%s" % os.path.dirname(i)) mkdir(os.path.dirname(o)) open(o, "w").write(pp(i , defines)) log.v(">> Save to " + o)
def generate_mhtml(i, o, defines): log.v("> m.cryptobox.html") mkdir(os.path.dirname(o)) open(o, "w").write(embed_html(i, defines, defines['path.jquery_mobile_css_images']))
def generate_cryptobox_json(js, o): log.v("> cryptobox.json") open(o, "w").write(json.dumps(js))
def _create_schema(self): """ Create empty Tables in the Postgres database to which this object is connected to.. """ log.dao("_create_schema() called on Postgres DAO.") cursor = self._connection.cursor() # TODO if not exists maybe?? #cursor.execute(""" DROP SCHEMA IF EXISTS uvs_schema CASCADE; """) self._clear_tables() cursor.execute(""" CREATE SCHEMA IF NOT EXISTS uvs_schema; """) cursor.execute(""" SET search_path TO uvs_schema; """) fp_size = get_uvs_fingerprint_size() log.v("fp size is: " + str(fp_size) + " bytes") # wee need two symbols for each byte in hex encoding so fp_size_hex_enc = fp_size * 2 # postgres text data types: # varchar(n) ---> variable len with limit # char(n) ---> fixed len blank padded # text ---> variable unlimited len # IMPORTANT: never use str concat (+) or python format specifiers (old style or new) to # put values into queries, neglecting this will open u up to SQL injection attack. Instead # pass a tuple or named key value pairs to psycopg2 and it will do the right thing. # tuple example: execute( "%s", (132,) ) # named k,v pairs example: execute( "%(tickets_left)s", {tickets_left: 132} ) cursor.execute("""CREATE TABLE IF NOT EXISTS snapshots ( snapid char(%(fp_size)s) NOT NULL, snapinfo_json BYTEA, PRIMARY KEY (snapid) ); """, {'fp_size': fp_size_hex_enc} ) # Trees table, i dont believe postgres table names are case sensitive. # tid is the uvs fp the tree contents # tree is json that describes whats in this tree. cursor.execute("""CREATE TABLE IF NOT EXISTS trees ( tid char(%(fp_size)s) NOT NULL, tree_json BYTEA, PRIMARY KEY (tid) ); """, {'fp_size': fp_size_hex_enc} ) # BYTEA type has 1 GB max size limit in postgres # fid is the uvs fp of the file content # finfo is json of information about this fid. Most important part is a list of segments that make up this file # dereference the segments table to find the contents of this file. cursor.execute("""CREATE TABLE IF NOT EXISTS files ( fid char(%(fp_size)s) NOT NULL, finfo_json BYTEA, PRIMARY KEY (fid) ); """, {'fp_size': fp_size_hex_enc} ) # BYTEA type has 1 GB max size limit in postgres # sgid is the uvsfp of this segment cursor.execute("""CREATE TABLE IF NOT EXISTS segments ( sgid char(%(fp_size)s) NOT NULL, segment BYTEA, PRIMARY KEY (sgid) ); """, {'fp_size': fp_size_hex_enc} ) # just a json record with some public info about this repo # (like public name, salt, optional owner email if needed, ....) cursor.execute("""CREATE TABLE IF NOT EXISTS public ( public_json BYTEA ); """ ) # this will commit the transaction right away. without this call, changes will be lost entirely. # Note after calling close on this connection, all cursors derived from it will fail to execute queries. # also all cursors derived from the same connection, see each other's changes immediately (are not isolated) # multiple connection objects may or may not see each others changes immediately (check ISOLATION LEVEL) self._connection.commit()