Пример #1
0
 def update_handler(self, fn, handler):
     q = update_property_query(self.app_id, fn, handler)
     res = msb.mqlwrite(q, use_permission_of=app_id);
     return res
Пример #2
0
 def update_handler(self, fn, handler):
     q = update_property_query(self.app_id, fn, handler)
     res = msb.mqlwrite(q, use_permission_of=app_id)
     return res
Пример #3
0
    def to_graph(self, app_id, msb=None, list_only=False, interactive=False):
        msb = msb or self.msb
        res_cur = InGraphAcreApp(app_id, msb)
        if msb != self.msb:
            res_asof = InGraphAcreApp(app_id, msb, res_cur.metadata['timestamp'])
        else:
            res_asof = InGraphAcreApp(app_id, msb, self.metadata['timestamp'])
        orig_files = res_asof.metadata['files']

        remote_files = res_cur.metadata['files']
        if not orig_files: orig_files = remote_files
        in_files = self.metadata['files']

        def continue_prompt():
            ok = False
            contin = False
            while not ok:
                res = raw_input("Continue anyway (y/n)? ")
                if len(res):
                    res = res.lower().strip()[0]
                    if res  == 'y':
                        contin = True
                        ok = True
                    elif res == 'n':
                        contin = False
                        ok = True
            return contin

        def merge_notice(f, local, removed):
            if local:
                print "File %s has been modified or removed on remote host since last sync" % f
                if interactive and continue_prompt():
                    if deleted:
                        if isinstance(changes.get(f, None), list):
                            changes[f].append(('-', a))
                        else:
                            changes[f] = [('-', a)]
                    else:
                        check_blobs(f)
                else:
                    sys.exit(1)
            else:
                print "File %s exists on remote host but not locally or in original copy" % f
                if interactive and continue_prompt():
                        if isinstance(changes.get(f, None), list):
                            changes[f].append(('-', a))
                        else:
                            changes[f] = [('-', a)]
                else:
                    sys.exit(1)


        def check_blobs(f, merge_ok=False):
            orig = orig_files.get(f,{})
            local = in_files.get(f,{})
            remote = remote_files.get(f,{})
            md_check = ['blob_id', 'content_type', 'handler']
            for a in md_check:
                o = orig.get(a, None)
                l = local.get(a, None)
                r = remote.get(a, None)
                if l == o and l != r:
                    if merge_ok:
                        # XXX might want to provide the option to revert to local
                        pass
                    else:
                        merge_notice(f, True, False)
                elif l == o:
                    pass
                elif l != o and o == r:
                    if isinstance(changes.get(f, None), list):
                        changes[f].append(('M', a))
                    else:
                        changes[f] = [('M', a)]
                elif l != o and o != r:
                    print l, o, r
                    if merge_ok:
                        if isinstance(changes.get(f, None), list):
                            changes[f].append(('M', a))
                        else:
                            changes[f] = [('M', a)]
                    else:
                        merge_notice(f, False, False)

        changes = {}
        for a in in_files:
            if a not in orig_files and a not in remote_files:
                if isinstance(changes.get(a, None), list):
                    changes[a].append(('+',))
                else:
                    changes[a] = [('+',)]
            elif a in orig_files and a not in remote_files:
                merge_notice(a, True, True)
            elif a in orig_files and a in remote_files:
                check_blobs(a)
            elif a not in orig_files and a in remote_files:
                merge_notice(a, False, False)

        for a in (set(remote_files.keys()) - set(in_files.keys())):
            if a in orig_files:
                merge_notice(a, False, False)
            else:
                check_blobs(a)

        for a in (set(orig_files.keys()) - set(remote_files.keys())):
            if a not in in_files:
                merge_notice(a, True, True)


        msb.login()
        for f, chgs in changes.iteritems():
            for c in chgs:
                if c[0] == '+':
                    print "add", f
                    if not list_only:
                        fi = in_files.get(f)
                        res = msb.upload(fi['contents'], fi['content_type'], permission_of=app_id)
                        q = add_file_query(app_id, f, fi['handler'], res['id'])
                        res = msb.mqlwrite(q, use_permission_of=app_id)
                elif c[0] == 'M' and c[1] == 'blob_id':
                    print "content change in", f
                    if not list_only:
                        fi = in_files.get(f)
                        res = msb.upload(fi['contents'], fi['content_type'],
                                         app_id+'/'+f, app_id)
                elif c[0] == 'M':
                    print "change in property", c[1], "for file", f
                    if not list_only:
                        fi = in_files.get(f)
                        q = update_property_query(app_id, f, fi['handler'])
                        res = msb.mqlwrite(q, use_permission_of=app_id);
Пример #4
0
    def to_graph(self, app_id, msb=None, list_only=False, interactive=False):
        msb = msb or self.msb
        res_cur = InGraphAcreApp(app_id, msb)
        if msb != self.msb:
            res_asof = InGraphAcreApp(app_id, msb,
                                      res_cur.metadata['timestamp'])
        else:
            res_asof = InGraphAcreApp(app_id, msb, self.metadata['timestamp'])
        orig_files = res_asof.metadata['files']

        remote_files = res_cur.metadata['files']
        if not orig_files: orig_files = remote_files
        in_files = self.metadata['files']

        def continue_prompt():
            ok = False
            contin = False
            while not ok:
                res = raw_input("Continue anyway (y/n)? ")
                if len(res):
                    res = res.lower().strip()[0]
                    if res == 'y':
                        contin = True
                        ok = True
                    elif res == 'n':
                        contin = False
                        ok = True
            return contin

        def merge_notice(f, local, removed):
            if local:
                print "File %s has been modified or removed on remote host since last sync" % f
                if interactive and continue_prompt():
                    if deleted:
                        if isinstance(changes.get(f, None), list):
                            changes[f].append(('-', a))
                        else:
                            changes[f] = [('-', a)]
                    else:
                        check_blobs(f)
                else:
                    sys.exit(1)
            else:
                print "File %s exists on remote host but not locally or in original copy" % f
                if interactive and continue_prompt():
                    if isinstance(changes.get(f, None), list):
                        changes[f].append(('-', a))
                    else:
                        changes[f] = [('-', a)]
                else:
                    sys.exit(1)

        def check_blobs(f, merge_ok=False):
            orig = orig_files.get(f, {})
            local = in_files.get(f, {})
            remote = remote_files.get(f, {})
            md_check = ['blob_id', 'content_type', 'handler']
            for a in md_check:
                o = orig.get(a, None)
                l = local.get(a, None)
                r = remote.get(a, None)
                if l == o and l != r:
                    if merge_ok:
                        # XXX might want to provide the option to revert to local
                        pass
                    else:
                        merge_notice(f, True, False)
                elif l == o:
                    pass
                elif l != o and o == r:
                    if isinstance(changes.get(f, None), list):
                        changes[f].append(('M', a))
                    else:
                        changes[f] = [('M', a)]
                elif l != o and o != r:
                    print l, o, r
                    if merge_ok:
                        if isinstance(changes.get(f, None), list):
                            changes[f].append(('M', a))
                        else:
                            changes[f] = [('M', a)]
                    else:
                        merge_notice(f, False, False)

        changes = {}
        for a in in_files:
            if a not in orig_files and a not in remote_files:
                if isinstance(changes.get(a, None), list):
                    changes[a].append(('+', ))
                else:
                    changes[a] = [('+', )]
            elif a in orig_files and a not in remote_files:
                merge_notice(a, True, True)
            elif a in orig_files and a in remote_files:
                check_blobs(a)
            elif a not in orig_files and a in remote_files:
                merge_notice(a, False, False)

        for a in (set(remote_files.keys()) - set(in_files.keys())):
            if a in orig_files:
                merge_notice(a, False, False)
            else:
                check_blobs(a)

        for a in (set(orig_files.keys()) - set(remote_files.keys())):
            if a not in in_files:
                merge_notice(a, True, True)

        msb.login()
        for f, chgs in changes.iteritems():
            for c in chgs:
                if c[0] == '+':
                    print "add", f
                    if not list_only:
                        fi = in_files.get(f)
                        res = msb.upload(fi['contents'],
                                         fi['content_type'],
                                         permission_of=app_id)
                        q = add_file_query(app_id, f, fi['handler'], res['id'])
                        res = msb.mqlwrite(q, use_permission_of=app_id)
                elif c[0] == 'M' and c[1] == 'blob_id':
                    print "content change in", f
                    if not list_only:
                        fi = in_files.get(f)
                        res = msb.upload(fi['contents'], fi['content_type'],
                                         app_id + '/' + f, app_id)
                elif c[0] == 'M':
                    print "change in property", c[1], "for file", f
                    if not list_only:
                        fi = in_files.get(f)
                        q = update_property_query(app_id, f, fi['handler'])
                        res = msb.mqlwrite(q, use_permission_of=app_id)