Download Firefox: WindowsMac OS X
logo       
Google Custom Search
    AddThis Social Bookmark Button

Some handy plug-ins that mad my life easier.: msg#00012

Subject: Some handy plug-ins that mad my life easier.
AutoGenerateObjectDirs.py
Creates output directories while loading a project similar to gnatmake -p.

project_changing.py <cid:part1.04070004.02000208@bredband.net>
   Makes it possible to add customization per project or directory tree.

/Please feel free to use it
/Per

"""This macro will create missing object-directories for a
 project tree when loading it into GPS.
 To install just copy the file to one of the plug-in directories in GPS.
 ${HOME}/.gps/plug-ins
 ${GPS_ROOT}/share/gps/plug-ins

"""

import GPS
import os
from os.path import *
import string
def on_project_changed(self):
    CreatedDirs=False
    if GPS.Preference ("Auto-Create-Dirs").get():
        prjs=GPS.Project.root().dependencies(True)
        prjs.append(GPS.Project.root())
        created=[]
        for i in prjs :        
           dirs=[i.get_attribute_as_string("Exec_Dir"),
                i.get_attribute_as_string("Library_Dir"),
                i.get_attribute_as_string("Object_Dir"),
                i.get_attribute_as_string("Library_Src_Dir")]
           for j in dirs:
               if i and i not in [".",""," "]:
                   dir=join(dirname(i.file().name()),j).strip()
                   if dir[-1:] not in ["\\","/"]:
                       if not exists(dir):
                           os.makedirs(dir)
                           created.append(dir)
                           CreatedDirs=True
        if CreatedDirs:
           GPS.Console("").clear()
           GPS.Console("").write("Created missing dirs\n")
           GPS.Console("").write(string.join(created,"\n"))
           GPS.Console("").write("\n")
           GPS.Project.recompute()

def on_gps_started(hook):
    try:
        GPS.Preference ("Auto-Create-Dirs").get()
    except:
        GPS.Preference ("Auto-Create-Dirs").set(True)
    GPS.Hook("project_view_changed").add(on_project_changed)
    on_project_changed(hook)

GPS.parse_xml("""   
   <preference name="Auto-Create-Dirs"
                page="General"
                label="Auto Create Missing Dirs"
                tip="Automaticly creates missing Directories."
                default="True"
                type="boolean" />""")
                
GPS.Hook("gps_started").add(on_gps_started)

"""
This module provides a framework for project specific customisation of GPS
it will set the variable:
 * "GPS.Project.project_changing_to" to the name of the project to be loaded.

then try to load configuration files in order.
 * "gps_cfg.py" in all enclosing direcorories closest last.
 * "project_name.py" next to the root project.
 * "project_name.xml" next to the root project. 
"""
import GPS
import os
from os.path import *
import string
import sys


    
def project_changing(this,project):
    def importCode(code,name,add_to_sys_modules=False):
        import new
        module=new.module(name)
        if add_to_sys_modules:
            import sys
            sys.modules[name]=module
        exec code in module.__dict__
        return module

    xmlfile=splitext(project.name())[0] + ".xml"
    pyfile=splitext(project.name())[0]  + ".py"
    files=[]
    dir=dirname(project.name())
    
    while True:
        f=join(dir,"gps_cfg.py")
        if exists(f):files.append(f)
        if dirname(dir)==dir:break
        dir=dirname(dir)
    files.reverse()
    if exists(pyfile):files.append(pyfile)
    
    GPS.Project.project_changing_to = project.name()

    for i in files:
        f=file(i)
        sys.stdout.write('loading: "' + i + '" ')
        try:
            importCode(f,splitext(basename(i))[0])
            sys.stdout.write('OK.\n')
        except:
            sys.stdout.write('Fail.\n')               
        f.close()
    
    if exists(xmlfile):
        f=file(xmlfile)
        buffer=f.read()
        f.close()
        sys.stdout.write('loading: "' + xmlfile)
        try:
            GPS.parse_xml(buffer)
            sys.stdout.write('" OK.\n')
        except:
            sys.stdout.write('" Fail.\n')

GPS.Hook("project_changing").add(project_changing)
_______________________________________________
gps-devel mailing list
gps-devel@xxxxxxxxxxxxxxxxx
http://lists.adacore.com/mailman/listinfo/gps-devel
<Prev in Thread] Current Thread [Next in Thread>