File: gen_plugin_index.py

package info (click to toggle)
editra 0.7.20%2Bdfsg.1-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 13,736 kB
  • ctags: 11,517
  • sloc: python: 74,206; sql: 258; ansic: 242; sh: 190; php: 45; tcl: 38; lisp: 38; perl: 23; java: 22; pascal: 21; cpp: 20; haskell: 20; xml: 18; cs: 18; erlang: 17; ruby: 16; asm: 15; makefile: 13; csh: 9; ml: 9; ada: 9
file content (93 lines) | stat: -rw-r--r-- 2,733 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python
###############################################################################
# Name: gen_plugin_index.py                                                   #
# Purpose: Generate the index file for the plugin manager                     #
# Author: Cody Precord <cprecord@editra.org>                                  #
# Copyright: (c) 2008 Cody Precord <staff@editra.org>                         #
# License: wxWindows License                                                  #
###############################################################################

"""

"""

__author__ = "Cody Precord <cprecord@editra.org>"
__svnid__ = "$Id: gen_plugin_index.py 56655 2008-11-02 23:36:56Z CJP $"
__revision__ = "$Revision: 56655 $"

#-----------------------------------------------------------------------------#
# Imports
import os
import sys

#-----------------------------------------------------------------------------#

INDEX = "plugin.idx"

#-----------------------------------------------------------------------------#

def findDirectories(path):
    """Find all directories under the given path
    @return: list of strings

    """
    if not os.path.isdir(path):
        raise ValueError("path must be a directory")

    dirs = list()
    for dname in os.listdir(path):
        if dname not in "build dist":
            dirs.append(os.path.join(path, dname))

    return dirs

def getInfoTxt(path):
    """Get the information text about the plugin"""
    rtxt = ''
    try:
        fhandle = open(path, 'r')
        rtxt = fhandle.read()
        rtxt = rtxt.strip()
    except IOError:
        print("Bad file path: " + path)
    finally:
        fhandle.close()

    return rtxt

def generateIndex(paths):
    """Generate the index for the plugins found under the given
    directory.
    @param paths: list of paths to look for plugin directories under

    """
    # Make sure we are working with absolute paths
    apaths = [ os.path.abspath(path) for path in paths ]

    # Collect all the plugin project directories
    spaths = list()
    for path in paths:
        if os.path.exists(path):
            dirs = findDirectories(path)
            spaths.extend(dirs)

    # Find all the info.txt files
    ifiles = list()
    for path in spaths:
        info = os.path.join(path, 'info.txt')
        if os.path.exists(info):
            ifiles.append(info)

    # Construct the index
    info = [getInfoTxt(fname) for fname in ifiles]
    index = open(INDEX, 'w')
    out = "\n###\n".join(info)
    index.write(out)
    index.close()
    
#-----------------------------------------------------------------------------#

if __name__ == '__main__':
    paths = sys.argv[1:]
    generateIndex(paths)