Exemplo n.º 1
0
 def check_ignored(Klass, filepath, opts):
     #if os.path.islink(filepath) or not os.path.isfile(filepath):
     if os.path.islink(filepath) or ( not os.path.isfile(filepath) and not os.path.isdir(filepath)) :
         log.warn("Ignored non-regular path %r", filepath)
         return True
     elif Klass.ignored(filepath) or File.ignored(filepath):
         log.info("Ignored file %r", filepath)
         return True
Exemplo n.º 2
0
 def decode_path( Klass, path, opts ):
     return path
     # XXX: decode from opts.fs_enc
     assert isinstance(path, basestring)
     try:
         path = unicode(path, 'utf-8')
         #path = path.decode('utf-8')
     except UnicodeDecodeError, e:
         log.warn("Ignored non-unicode path %s", path)
Exemplo n.º 3
0
 def rsr_list_groups(self, sa=None):
     "List all group nodes"
     gns = sa.query(GroupNode).all()
     fields = 'node_id', 'name', 'subnodes'
     if gns:
         print('#', ', '.join(fields))
         for n in gns:
             for f in fields:
                 print(getattr(n, f), end=' ')
             print()
     else:
         log.warn("No entries")
Exemplo n.º 4
0
 def rsr_nodes(self, sa, *args):
     "Print existing nodes. "
     nodes = []
     for arg in args:
         typehint, nodeid = self.deref(arg, sa)
         # do something with typehint?
         node = Node.find(( Node.name == nodeid, ))
         if not node:
             log.warn("No entry for %s:%s", typehint, nodeid)
             continue
         print(node.ntype, node.name)
         nodes.append(node)
     yield dict(nodes=nodes)
Exemplo n.º 5
0
    def fetch(clss, *paths):
        """
        Find metadir by searching for markerleaf indicated by Class'
        DOTID property, using '.' DOTNAME '/' as one of the name prefixes.

        See confparse.find_config_path. This will be searching for the .id
        extensions.

        Returning Class instance for first path, if any.
        """
        configpaths = list(clss.find(*paths))
        if configpaths:
            if len(configpaths) > 1:
                log.warn('Using first config file %s for %s', clss.DOTID, configpaths)
            return clss(configpaths[0])
Exemplo n.º 6
0
def cmd_home_doc(settings, opts):
    sa = get_session(settings.dbref)
    home_doc_cf = get_custom_field('Home Doc', sa)
    proj_id_cf = get_custom_field('ID Slug', sa)
    assert home_doc_cf.field_format == 'link', home_doc_cf.field_format
    # yaml
    assert home_doc_cf.format_store.startswith('---')
    format = home_doc_cf.format_store.split('\n')[1:]
    assert format[0].startswith('url_pattern: '),\
            format
    url_pattern = format[0][len('url_pattern: '):]

    if opts.args.ISSUE:
        iid = int(opts.args.ISSUE)
        issue, home_doc_cf_v = sa.query(rdm.Issue, rdm.CustomValue).join(
                rdm.CustomValue,
                rdm.CustomValue.customized_id == rdm.Issue.id
            ).filter(
                rdm.CustomValue.custom_field_id == home_doc_cf.id,
                rdm.Issue.id == iid
            ).one()

        project, proj_id_cf_v = sa.query(rdm.Project, rdm.CustomValue).join(
                rdm.CustomValue,
                rdm.CustomValue.customized_id == rdm.Project.id
            ).filter(
                rdm.CustomValue.custom_field_id == proj_id_cf.id,
                rdm.Project.id == issue.project_id
            ).one()

        if not home_doc_cf_v.value:
            log.warn("No Home Doc")
            return 1

        if proj_id_cf_v.value:
            id_slug = proj_id_cf_v.value
        else:
            id_slug = ''

        url = url_pattern.replace('%project_identifier%', id_slug)
        url = url.replace('%project_id%', str(issue.project_id))
        url = url.replace('%value%', home_doc_cf_v.value)
        url = url.replace('%id%', str(issue.id))

        print(url, issue.subject)
    else:
        print(url_pattern)
Exemplo n.º 7
0
 def rsr_tree(self, sa=None, *nodes):
     "Print a tree of nodes as nested lists"
     if not nodes:
         roots = sa.query(GroupNode)\
                 .filter( GroupNode.root == True, ).all()
         if not roots:
             log.err("No roots")
     else:
         roots = []
         for node in nodes:
             group = GroupNode.find(( Node.name == node, ))
             if not group:
                 log.warn(group)
                 continue
             roots.append(group)
     for group in roots:
         self.execute( 'rsr_node_recurse', dict( group=group  ) )
Exemplo n.º 8
0
    def rsr_set_root_bool(self, sa=None, opts=None):
        """
        set bool = true
        where
            count(jt.node_id) == 0
            jt.group_id

        core.groupnode_node_table\
            update().values(
                )
        """
        gns = sa.query(GroupNode).all()
        if gns:
            for n in gns:
                if not n.supernode:
                    n.root = True
                    log.info("Root %s", n)
                    sa.add(n)
            if opts.rsr_auto_commit:
                sa.commit()
        else:
            log.warn("No entries")
Exemplo n.º 9
0
 def recurse(js, lvl=0):
     #if 'id' in js and js['id']:
     #    if js['id'] == 1912:
     #        import sys
     #        sys.exit()
     #    print
     #    print ( '\t'*lvl ) + str(json['id'])
     #if 'title' in json and json['title']:
     #    print ( '\t'*lvl ) + json['title']
     if 'uri' in js and js['uri']:
         assert 'children' not in js, "what to do %s" % js
         yield js#['uri']
         #print ( '\t'*lvl ) + json['uri']
     elif 'children' in js:
         yield js
         for x in js['children']:
             for y in recurse(x, lvl+1):
                 yield y
     elif 'parent' in js or 'root' in js or 'title' in js:
         yield js
     else:
         log.warn("Ignored node %s", js)
Exemplo n.º 10
0
 def walk(self, path, max_depth=-1):
     # XXX: maybe rewrite to Dir.walk
     """
     Walk all files that may have a metafile, and notice any metafile(-like)
     neighbors?
     """
     for root, nodes, leafs in os.walk(path):
         for node in list(nodes):
             dirpath = os.path.join(root, node)
             if not os.path.exists(dirpath):
                 log.err("Error: reported non existant node %s", dirpath)
                 nodes.remove(node)
                 continue
             depth = dirpath.replace(path,'').strip('/').count('/')
             if fs.Dir.ignored(dirpath):
                 log.warn("Ignored directory %r", dirpath)
                 nodes.remove(node)
             elif max_depth != -1:
                 if depth >= max_depth:
                     nodes.remove(node)
         for leaf in leafs:
             cleaf = os.path.join(root, leaf)
             if not os.path.exists(dirpath):
                 log.err("Error: non existant leaf %s", cleaf)
                 continue
             if not os.path.isfile(cleaf) or os.path.islink(cleaf):
                 #log.warn("Ignored non-regular file %r", cleaf)
                 continue
             if fs.File.ignored(cleaf):
                 #log.warn("Ignored file %r", cleaf)
                 continue
             if Metafile.is_metafile(cleaf, strict=False):
                 if not Metafile(cleaf).path:
                     log.err("Metafile without resource file")
             else:
                 yield cleaf