# Path: PyDvi/Font/Encoding.py
# class Encoding(object):
# 
#     """
#     Parse an encoding file and store the association between the index and the glyph's name.
# 
#     Public attributes are:
# 
#       ``name``
#     """
# 
#     ##############################################
# 
#     def __init__(self, filename):
# 
#         self.name = None
# 
#         self._glyph_indexes = [] # Map glyph index to glyph name
#         self._glyph_names = {} # Map glyph name  to glyph index
# 
#         try:
#             with TexCommentedFile(filename) as encoding_file:
#                 content = encoding_file.concatenate_lines()
#                 open_braket_index = content.index('[')
#                 close_braket_index = content.index(']')
#                 self._parse_name(content[:open_braket_index])
#                 self._parse_glyph_names(content[open_braket_index+1:close_braket_index])
#         except:
#             raise NameError('Bad encoding file')
# 
#         # Init glyph_names dict
#         for i in xrange(len(self._glyph_indexes)):
#             self._glyph_names[self._glyph_indexes[i]] = i
# 
#     ##############################################
# 
#     def __len__(self):
# 
#         """ Return the number of glyphes. """
# 
#         return len(self._glyph_indexes)        
# 
#     ##############################################
# 
#     def __getitem__(self, index):
# 
#         """ If *index* is a glyph index then return the corresponding symbolic name else try to
#         return the glyph index corresponding to the symbolic name *index*.
#         """
# 
#         try:
#             return self.to_name(int(index))
#         except ValueError:
#             return self.to_index(index)
# 
#     ##############################################
# 
#     def _parse_name(self, line):
# 
#         """ Find the encoding name at the left of the line, as '/CorkEncoding'. """
# 
#         # try
#         name_start_index = line.index('/')
#         self.name = line[name_start_index +1:].strip()
# 
#     ##############################################
# 
#     def _parse_glyph_names(self, line):
# 
#         """ Find glyph names in *line*, as '/grave /acute /circumflex ...'. """
# 
#         for word in line.split('/'):
#             word = word.strip()
#             if word:
#                 self._glyph_indexes.append(word)
# 
#     ##############################################
# 
#     def to_name(self, i):
# 
#         """ Return the symbolic name corresponding to the glyph index *i*. """
# 
#         return self._glyph_indexes[i]
# 
#     ##############################################
# 
#     def to_index(self, name):
# 
#         """ Return the glyph index corresponding to the symbolic name. """
# 
#         return self._glyph_names[name]
# 
#     ##############################################
# 
#     def print_summary(self):
# 
#         message = 'Encoding %s:\n\n' % (self.name)
#         for i in xrange(len(self)):
#             message += '| %3i | %s\n' % (i, self.to_name(i))
# 
#         print_card(message)
# 
# Path: PyDvi/Kpathsea.py
# def kpsewhich(filename, file_format=None, options=None):
# 
#     """Wrapper around the :command:`kpsewhich` command, cf. kpsewhich(1).
# 
#     *file_format*
#       used to specify the file format, see :command:`kpsewhich` help for the file format list.
# 
#     *options*
#       additional option for :command:`kpsewhich`.
# 
#     Examples::
# 
#        >>> kpsewhich('cmr10', file_format='tfm')
#        '/usr/share/texmf/fonts/tfm/public/cm/cmr10.tfm'
#     """
# 
#     key = '{}-{}-{}'.format(filename, file_format, options)
#     if key in _cache:
#         return _cache[key]
# 
#     command = ['kpsewhich']
#     if file_format is not None:
#         command.append("--format='%s'" % (file_format))
#     if options is not None:
#         command.append(options)
#     command.append(filename)
# 
#     shell_command = ' '.join(command)
#     _module_logger.debug('Run shell command: ' + shell_command)
#     pipe = subprocess.Popen(shell_command, shell=True, stdout=subprocess.PIPE)
#     stdout = pipe.communicate()[0]
#     _module_logger.debug('stdout:\n' + stdout)
#     path = stdout.rstrip()
#     path = path if path else None # Fixme: could raise an exception
# 
#     _cache[key] = path
#     return path


import argparse
import sys
from PyDvi.Font.Encoding import Encoding
from PyDvi.Kpathsea import kpsewhich
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 
####################################################################################################

####################################################################################################
#
#                                              Audit
#
# - 13/11/2011 Fabrice
#   x
#
####################################################################################################

####################################################################################################


####################################################################################################


####################################################################################################

parser = argparse.ArgumentParser(description='Test Encoding.')
parser.add_argument('encoding', metavar='Encoding',
                    help='TeX encoding, e.g. cork')
args = parser.parse_args()

####################################################################################################


# Path: PyDvi/Font/Encoding.py
# class Encoding(object):
# 
#     """
#     Parse an encoding file and store the association between the index and the glyph's name.
# 
#     Public attributes are:
# 
#       ``name``
#     """
# 
#     ##############################################
# 
#     def __init__(self, filename):
# 
#         self.name = None
# 
#         self._glyph_indexes = [] # Map glyph index to glyph name
#         self._glyph_names = {} # Map glyph name  to glyph index
# 
#         try:
#             with TexCommentedFile(filename) as encoding_file:
#                 content = encoding_file.concatenate_lines()
#                 open_braket_index = content.index('[')
#                 close_braket_index = content.index(']')
#                 self._parse_name(content[:open_braket_index])
#                 self._parse_glyph_names(content[open_braket_index+1:close_braket_index])
#         except:
#             raise NameError('Bad encoding file')
# 
#         # Init glyph_names dict
#         for i in xrange(len(self._glyph_indexes)):
#             self._glyph_names[self._glyph_indexes[i]] = i
# 
#     ##############################################
# 
#     def __len__(self):
# 
#         """ Return the number of glyphes. """
# 
#         return len(self._glyph_indexes)        
# 
#     ##############################################
# 
#     def __getitem__(self, index):
# 
#         """ If *index* is a glyph index then return the corresponding symbolic name else try to
#         return the glyph index corresponding to the symbolic name *index*.
#         """
# 
#         try:
#             return self.to_name(int(index))
#         except ValueError:
#             return self.to_index(index)
# 
#     ##############################################
# 
#     def _parse_name(self, line):
# 
#         """ Find the encoding name at the left of the line, as '/CorkEncoding'. """
# 
#         # try
#         name_start_index = line.index('/')
#         self.name = line[name_start_index +1:].strip()
# 
#     ##############################################
# 
#     def _parse_glyph_names(self, line):
# 
#         """ Find glyph names in *line*, as '/grave /acute /circumflex ...'. """
# 
#         for word in line.split('/'):
#             word = word.strip()
#             if word:
#                 self._glyph_indexes.append(word)
# 
#     ##############################################
# 
#     def to_name(self, i):
# 
#         """ Return the symbolic name corresponding to the glyph index *i*. """
# 
#         return self._glyph_indexes[i]
# 
#     ##############################################
# 
#     def to_index(self, name):
# 
#         """ Return the glyph index corresponding to the symbolic name. """
# 
#         return self._glyph_names[name]
# 
#     ##############################################
# 
#     def print_summary(self):
# 
#         message = 'Encoding %s:\n\n' % (self.name)
#         for i in xrange(len(self)):
#             message += '| %3i | %s\n' % (i, self.to_name(i))
# 
#         print_card(message)
# 
# Path: PyDvi/Kpathsea.py
# def kpsewhich(filename, file_format=None, options=None):
# 
#     """Wrapper around the :command:`kpsewhich` command, cf. kpsewhich(1).
# 
#     *file_format*
#       used to specify the file format, see :command:`kpsewhich` help for the file format list.
# 
#     *options*
#       additional option for :command:`kpsewhich`.
# 
#     Examples::
# 
#        >>> kpsewhich('cmr10', file_format='tfm')
#        '/usr/share/texmf/fonts/tfm/public/cm/cmr10.tfm'
#     """
# 
#     key = '{}-{}-{}'.format(filename, file_format, options)
#     if key in _cache:
#         return _cache[key]
# 
#     command = ['kpsewhich']
#     if file_format is not None:
#         command.append("--format='%s'" % (file_format))
#     if options is not None:
#         command.append(options)
#     command.append(filename)
# 
#     shell_command = ' '.join(command)
#     _module_logger.debug('Run shell command: ' + shell_command)
#     pipe = subprocess.Popen(shell_command, shell=True, stdout=subprocess.PIPE)
#     stdout = pipe.communicate()[0]
#     _module_logger.debug('stdout:\n' + stdout)
#     path = stdout.rstrip()
#     path = path if path else None # Fixme: could raise an exception
# 
#     _cache[key] = path
#     return path


# Path: test/test_encoding.py
import argparse
import sys
from PyDvi.Font.Encoding import Encoding
from PyDvi.Kpathsea import kpsewhich

# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 
####################################################################################################

####################################################################################################
#
#                                              Audit
#
# - 13/11/2011 Fabrice
#   x
#
####################################################################################################

####################################################################################################


####################################################################################################


####################################################################################################

parser = argparse.ArgumentParser(description='Test Encoding.')
parser.add_argument('encoding', metavar='Encoding',
                    help='TeX encoding, e.g. cork')
args = parser.parse_args()

####################################################################################################


encoding_file = kpsewhich(args.encoding, file_format='enc files')