Package pyctags :: Module tag_base
[hide private]
[frames] | no frames]

Source Code for Module pyctags.tag_base

  1  ## Copyright (C) 2008 Ben Smith <benjamin.coder.smith@gmail.com> 
  2   
  3  ##    This file is part of pyctags. 
  4   
  5  ##    pyctags is free software: you can redistribute it and/or modify 
  6  ##    it under the terms of the GNU Lesser General Public License as published 
  7  ##    by the Free Software Foundation, either version 3 of the License, or 
  8  ##    (at your option) any later version. 
  9   
 10  ##    pyctags is distributed in the hope that it will be useful, 
 11  ##    but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12  ##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 13  ##    GNU General Public License for more details. 
 14   
 15  ##    You should have received a copy of the GNU Lesser General Public License 
 16  ##    and the GNU Lesser General Public Licens along with pyctags.  If not,  
 17  ##    see <http://www.gnu.org/licenses/>. 
 18   
 19  """ 
 20  Base class for wrappers around ctags programs. 
 21   
 22  This module uses the subprocess.Popen function.  Users of this module could pass arbitrary commands to the system. 
 23  """ 
 24   
 25  import subprocess 
 26  try: 
 27      # do relative imports for tests 
 28      # try this first in case pyctags is already installed, since we want to be testing the source bundled in the distribution 
 29   
 30      from kwargs_validator import the_validator as validator 
 31  except ImportError: 
 32      from pyctags.kwargs_validator import the_validator as validator 
 33   
34 -class ctags_base:
35 """ 36 This class exists to provide a template and some functionality for wrapping command line ctags programs. 37 38 The functions B{_query_tag_generator}, B{generate_tags}, and B{generate_tagfile} should be overriden in child classes. 39 """
40 - def __init__(self, *args, **kwargs):
41 """ 42 Base class to wrap ctags program. 43 - B{Keyword Arguments:} 44 - B{tag_program:} (str) path to ctags executable, or name of a ctags program in path 45 - B{files:} (sequence) files to process with ctags 46 """ 47 valid_kwargs = ['tag_program', 'files'] 48 validator.validate(kwargs.keys(), valid_kwargs) 49 50 self._file_list = list() 51 """ A list of file names to process.""" 52 53 self._executable_path = None 54 """ The ctags executable.""" 55 56 self.command_line = None 57 """ The command line generated and used.""" 58 59 self.warnings = list() 60 """ A place to store warnings from ctags.""" 61 62 if 'tag_program' in kwargs: 63 if (self.ctags_executable(kwargs['tag_program'])): 64 self._executable_path = kwargs['tag_program'] 65 if 'files' in kwargs: 66 self._file_list = list(kwargs['files'])
67 68
69 - def ctags_executable(self, path):
70 """ 71 Sets ctags path and executable. 72 @param path: ctags executable name or path to it 73 @type path: str 74 @return: executable found 75 @rtype: boolean 76 """ 77 rval = False 78 if type(path) == str: 79 # see if exe_file is executable 80 try: 81 subprocess.Popen(path, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) 82 rval = True 83 except OSError: 84 pass 85 if rval: 86 self._query_tag_generator(path) 87 88 return rval
89
90 - def _query_tag_generator(self, path):
91 """ 92 Abstract method, used to test ctags generator. 93 @raise NotImplementedError: Abstract method, must be overridden. 94 """ 95 raise NotImplementedError
96
97 - def generate_tags(self, *args, **kwargs):
98 """ 99 Abstract function to parse source files, returns list of tag strings. 100 @raise NotImplementedError: Abstract method, must be overridden per 101 ctags program 102 """ 103 raise NotImplementedError
104
105 - def generate_tagfile(self, *args, **kwargs):
106 """ 107 Abstract method to generate a tags file. 108 @raise NotImplementedError: Abstract method, must be overridden per 109 ctags program 110 """ 111 raise NotImplementedError
112
113 - def input_files(self, files):
114 """ 115 Sets the list of files to process with ctags. 116 @param files: sequence of files, relative or absolute path 117 @type files: sequence 118 """ 119 self._file_list = list(files)
120