Changeset 1442

Show
Ignore:
Timestamp:
07/01/08 21:49:50 (5 months ago)
Author:
rob
Message:

Refs #18: Added RebuildCtags? action to recreate the tags file

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/peppy/plugins/project.py

    r1438 r1442  
    2020from peppy.actions import * 
    2121from peppy.lib.userparams import * 
     22from peppy.lib.processmanager import * 
    2223 
    2324 
     
    3132        ) 
    3233     
    33     def loadTags(self): 
     34    def getTagFileURL(self): 
    3435        if self.tags_file_location == 0: 
    3536            base = self.project_top_dir 
     
    3738            base = self.project_settings_dir 
    3839        url = base.resolve2(ProjectPlugin.classprefs.ctags_tag_file_name) 
     40        return url 
     41 
     42    def regenerateTags(self): 
     43        # need to operate on the local filesystem 
     44        dprint(self.project_top_dir) 
     45        if self.project_top_dir.scheme != "file": 
     46            raise TypeError("Can only process ctags on local filesystem") 
     47        cwd = str(self.project_top_dir.path) 
     48        ctags_file = str(self.getTagFileURL().path) 
     49        wildcards = self.ctags_exclude.split() 
     50        excludes = " ".join(["--exclude=%s" % w for w in wildcards]) 
     51        args = "-o %s %s %s %s" % (ctags_file, ProjectPlugin.classprefs.ctags_args, self.ctags_extra_args, excludes) 
     52        cmd = "%s %s" % (ProjectPlugin.classprefs.ctags_command, args) 
     53        dprint(cmd) 
     54         
     55        output = JobOutputSaver(self.regenerateFinished) 
     56        ProcessManager().run(cmd, cwd, output) 
     57     
     58    def regenerateFinished(self, output): 
     59        dprint(output) 
     60        if output.exit_code == 0: 
     61            self.loadTags() 
     62        else: 
     63            Publisher().sendMessage('peppy.log.error', output.getErrorText()) 
     64     
     65    def loadTags(self): 
     66        url = self.getTagFileURL() 
    3967        self.parseCtags(url) 
    4068     
     
    144172 
    145173 
     174class RebuildCtags(SelectAction): 
     175    """Rebuild tag file""" 
     176    name = "Rebuild Tag File" 
     177    default_menu = ("Project", -500) 
     178 
     179    def action(self, index=-1, multiplier=1): 
     180        if self.mode.project_info: 
     181            info = self.mode.project_info 
     182            info.regenerateTags() 
     183 
     184 
    146185class SaveGlobalTemplate(OnDemandActionNameMixin, SelectAction): 
    147186    """Save as the default (application-wide) template for this major mode. 
     
    185224 
    186225    def isEnabled(self): 
    187         return bool(ProjectPlugin.getProjectInfo(self.mode)) 
    188  
    189     def action(self, index=-1, multiplier=1): 
    190         project = ProjectPlugin.getProjectInfo(self.mode) 
    191         project.build() 
     226        return bool(self.mode.project_info and self.mode.project_info.build_command) 
     227 
     228    def action(self, index=-1, multiplier=1): 
     229        self.mode.project_info.build() 
    192230 
    193231 
     
    199237 
    200238    def isEnabled(self): 
    201         return bool(ProjectPlugin.getProjectInfo(self.mode)) 
    202  
    203     def action(self, index=-1, multiplier=1): 
    204         project = ProjectPlugin.getProjectInfo(self.mode) 
    205         project.run() 
     239        return bool(self.mode.project_info and self.mode.project_info.run_command) 
     240 
     241    def action(self, index=-1, multiplier=1): 
     242        self.mode.project_info.run() 
    206243 
    207244 
     
    400437            actions.append(SaveGlobalTemplate) 
    401438        if mode.buffer.url in self.known_project_dirs: 
    402             actions.extend([SaveProjectTemplate, BuildProject, RunProject]) 
     439            actions.extend([SaveProjectTemplate, BuildProject, RunProject, RebuildCtags]) 
    403440        actions.append(ShowProjectSettings) 
    404441        return actions 
     
    409446 
    410447if __name__== "__main__": 
     448    app = wx.PySimpleApp() 
    411449    ctags = ProjectInfo(vfs.normalize("/home/rob/src/peppy-git/.peppy-project")) 
    412450    print ctags.getTag('GetValue') 
     451    ctags.regenerateTags()