Beispiel #1
0
def dump(filename):
    """Dump specified pages and its dependencies."""

    web.load()
    site = db.get_site(config.site)

    visited = {}

    def visit_all(pages):
        for p in pages:
            if isinstance(p, tdb.Thing):
                visit(p)
            elif isinstance(p, list):
                visit_all(p)

    def visit(p):
        if p.id in visited:
            return 
        visited[p.id] = p
        visit(p.type)
        visit_all(p.d.values())

    pages = [db.get_version(site, p.strip()) for p in open(filename).readlines()]
    visit_all(pages)

    for p in visited.values():
        data = dict(p.d)
        data['__type__'] = p.type
        data['__name__'] = p.name
        data['__parent__'] = p.parent
        print tdb.logger.format('thing', p.id, data),
Beispiel #2
0
def thingify(type, value):
    # if type is given as string then get the type from db
    if type is None:
        type = '/type/string'

    if isinstance(type, str):
        from infogami.core import db

        type = db.get_version(type)

    PRIMITIVE_TYPES = (
        "/type/key",
        "/type/string",
        "/type/text",
        "/type/int",
        "/type/float",
        "/type/boolean",
        "/type/uri",
    )

    if type.key not in PRIMITIVE_TYPES and isinstance(value, str) and not value.strip():
        value = web.ctx.site.new('', {'type': type})

    if type.key not in PRIMITIVE_TYPES and (
        value is None or isinstance(value, client.Nothing)
    ):
        value = web.ctx.site.new('', {'type': type})

    # primitive values
    if not isinstance(value, client.Thing):
        value = web.storage(value=value, is_primitive=True, type=type, key=value)
    else:
        value.type = type  # value.type might be string, make it Thing object

    return value
Beispiel #3
0
    def POST(self, path):
        p = db.get_version(path)
        if not p:
            raise web.seeother(path)

        i = web.input('permission.key', 'child_permission.key')
        q = {
            'key': path,
            'permission': {
                'connect': 'update',
                'key': i['permission.key'] or None,
            },
            'child_permission': {
                'connect': 'update',
                'key': i['child_permission.key'] or None,
            },
        }

        try:
            web.ctx.site.write(q)
        except Exception as e:
            import traceback

            traceback.print_exc(e)
            add_flash_message('error', str(e))
            return render.permission(p)

        raise web.seeother(web.changequery({}, m='permission'))
Beispiel #4
0
        def diff(key, revision):
            b = db.get_version(key, revision)

            rev_a = revision -1
            if rev_a == 0:
                a = web.ctx.site.new(key, {})
                a.revision = 0
            else:
                a = db.get_version(key, revision=rev_a)

            diff = render.diff(a, b)

            #@@ dirty hack to extract diff table from diff
            import re
            rx = re.compile(r"^.*(<table.*<\/table>).*$", re.S)
            return rx.sub(r'\1', str(diff))
Beispiel #5
0
def pull(root, paths_files):
    """Move specified pages from wiki to disk."""
    def write(path, data):
        dir = os.path.dirname(filepath)
        if not os.path.exists(dir):
            os.makedirs(dir)
        f = open(filepath, 'w')
        f.write(repr(data))
        f.close()

    pages = {}
    paths = [line.strip() for line in open(paths_files).readlines()]
    paths2 = []

    for path in paths:
        if path.endswith('/*'):
            path = path[:-2] # strip trailing /*
            paths2 += [p.name for p in db._list_pages(context.site, path)]
        else:
            paths2.append(path)

    for path in paths2:
        print >> web.debug, "pulling page", path
        page = db.get_version(context.site, path)
        name = page.name or '__root__'
        data = thing2dict(page)
        filepath = os.path.join(root, name + ".page") 
        write(filepath, data)
Beispiel #6
0
def pull(root, paths_files):
    """Move specified pages from wiki to disk."""
    def write(path, data):
        dir = os.path.dirname(filepath)
        if not os.path.exists(dir):
            os.makedirs(dir)
        f = open(filepath, 'w')
        f.write(repr(data))
        f.close()

    pages = {}
    paths = [line.strip() for line in open(paths_files).readlines()]
    paths2 = []

    for path in paths:
        if path.endswith('/*'):
            path = path[:-2]  # strip trailing /*
            paths2 += [p.name for p in db._list_pages(context.site, path)]
        else:
            paths2.append(path)

    for path in paths2:
        print("pulling page", path, file=web.debug)
        page = db.get_version(context.site, path)
        name = page.name or '__root__'
        data = thing2dict(page)
        filepath = os.path.join(root, name + ".page")
        write(filepath, data)
Beispiel #7
0
def thingify(type, value):
    # if type is given as string then get the type from db
    if type is None:
        type = '/type/string'
        
    if isinstance(type, basestring):
        from infogami.core import db
        type = db.get_version(type)
        
    PRIMITIVE_TYPES = "/type/key", "/type/string", "/type/text", "/type/int", "/type/float", "/type/boolean", "/type/uri"    
    from infogami.infobase import client
        
    if type.key not in PRIMITIVE_TYPES and isinstance(value, basestring) and not value.strip():
        value = web.ctx.site.new('', {'type': type})

    if type.key not in PRIMITIVE_TYPES and (value is None or isinstance(value, client.Nothing)):
        value = web.ctx.site.new('', {'type': type})
    
    # primitive values
    if not isinstance(value, client.Thing):
        value = web.storage(value=value, is_primitive=True, type=type, key=value)
    else:
        value.type = type # value.type might be string, make it Thing object
    
    return value
Beispiel #8
0
def thinginput(value, property=None, **kw):
    if property is None:
        if 'expected_type' in kw:
            if isinstance(kw['expected_type'], basestring):
                from infogami.core import db        
                kw['expected_type'] = db.get_version(kw['expected_type'])
        else:
            raise ValueError, "missing expected_type"
        property = web.storage(kw)
    return unicode(render.input(thingify(property.expected_type, value), property))
Beispiel #9
0
def thinginput(value, property=None, **kw):
    if property is None:
        if 'expected_type' in kw:
            if isinstance(kw['expected_type'], six.string_types):
                from infogami.core import db
                kw['expected_type'] = db.get_version(kw['expected_type'])
        else:
            raise ValueError("missing expected_type")
        property = web.storage(kw)
    return six.text_type(render.input(thingify(property.expected_type, value), property))
Beispiel #10
0
 def getthing(name, create=False):
     if isinstance(name, tdb.Thing):
         return name
     try:
         return db.get_version(context.site, name)
     except:
         if create and create_dependents:
             thing = db.new_version(context.site, name, getthing("type/thing"), {})
             thing.save()
             return thing
         else:
             raise
Beispiel #11
0
    def GET(self, path):
        i = web.input(v=None)

        if i.v is not None and safeint(i.v, None) is None:
            raise web.seeother(web.changequery(v=None))

        p = db.get_version(path, i.v)
        if p is None:
            return notfound(path)
        elif p.type.key == '/type/delete':
            web.ctx.status = '404 Not Found'
            return render.viewpage(p)
        elif (p.type.key == "/type/redirect" and p.location
              and not p.location.startswith('http://')
              and not p.location.startswith('://')):
            web.redirect(p.location)
        else:
            return render.viewpage(p)
Beispiel #12
0
    def GET(self, path):
        i = web.input(v=None, t=None)

        if not web.ctx.site.can_write(path):
            return render.permission_denied(web.ctx.fullpath, "Permission denied to edit " + path + ".")

        if i.v is not None and safeint(i.v, None) is None:
            raise web.seeother(web.changequery(v=None))

        p = db.get_version(path, i.v) or db.new_version(path, types.guess_type(path))

        if i.t:
            type = db.get_type(i.t)
            if type is None:
                add_flash_message('error', 'Unknown type: ' + i.t)
            else:
                p.type = type

        return render.editpage(p)
Beispiel #13
0
 def GET(self, path):
     p = db.get_version(path)
     if not p:
         raise web.seeother(path)
     return render.permission(p)
Beispiel #14
0
 def GET(self, path):
     p = db.get_version(path) or web.ctx.site.new(path, {'key': path, 'revision': 0})
     p.revision = "%s - staging" % p.revision
     p2 = get_site().get(path) or web.ctx.site.new(path, {'key': path, 'revision': 0})
     p2.revision = "%s - production" % p2.revision
     return render.syncdiff(p, p2)
Beispiel #15
0
 def GET(self):
     assert db.get_version('/').title == "Open Library"
     #assert 'b/Political_Fictions' in search.solr.search('political fictions didion').result_list
     print "HEALTHY"