at_folder.py :  » Development » Leo » Leo-4.7.1-final » leo » plugins » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Development » Leo 
Leo » Leo 4.7.1 final » leo » plugins » at_folder.py
#@+leo-ver=4-thin
#@+node:edream.110203113231.873:@thin at_folder.py
#@<< docstring >>
#@+node:edream.110203113231.874:<< docstring >>
'''Synchronize @folder nodes with folders.

If a node is named '@folder path_to_folder', the content (filenames) of the
folder and the children of that node will be sync. Whenever a new file is put
there, a new node will appear on top of the children list (with mark). So that
I can put my description (ie. annotation) as the content of that node. In this
way, I can find any files much easier from leo. import 

Moreover, I add another feature to allow you to group files(in leo) into
children of another group. This will help when there are many files in that
folder. You can logically group it in leo (or even clone it to many groups),
while keep every files in a flat/single directory on your computer.
'''
#@nonl
#@-node:edream.110203113231.874:<< docstring >>
#@nl

#@@language python
#@@tabwidth -4

import leo.core.leoGlobals as g
import leo.core.leoPlugins as leoPlugins
import os  # added JD 2004-09-10

__version__ = "1.4"

#@+others
#@+node:edream.110203113231.875:sync_node_to_folder
def sync_node_to_folder(c,parent,d):

    oldlist = {}
    newlist = []
    #get children info
    v = parent
    after_v = parent.nodeAfterTree()
    while v != after_v:
        if not v.hasChildren():
            oldlist[v.h] = v.b
        v = v.threadNext()
    #compare folder content to children
    for name in os.listdir(d):
        if name in oldlist:
            del oldlist[name]
        else:
            newlist.append(name)
    #insert newlist
    newlist.sort()
    newlist.reverse()
    for name in newlist:
        v = parent.insertAsNthChild(0)
        c.setHeadString(v,name)
        v.setMarked()
    #warn for orphan oldlist
    if len(oldlist)>0:
        g.es('missing: '+','.join(oldlist.keys()))
#@-node:edream.110203113231.875:sync_node_to_folder
#@-others

def onSelect (tag,keywords):
    c = keywords.get('c') or keywords.get('new_c')
    if not c: return
    v = keywords.get("new_v")
    h = v.h
    if g.match_word(h,0,"@folder"):
        sync_node_to_folder(c,v,h[8:])

if 1: # Ok for unit testing.
    leoPlugins.registerHandler("select1", onSelect)
    g.plugin_signon(__name__)
#@nonl
#@-node:edream.110203113231.873:@thin at_folder.py
#@-leo
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.