home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1091 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  4.3 KB  |  167 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import os
  5. import sys
  6.  
  7. class Configure:
  8.     
  9.     def __init__(self, configuration_file, bug_handler, debug_dir = None, show_config_file = None):
  10.         self._Configure__configuration_file = configuration_file
  11.         self._Configure__debug_dir = debug_dir
  12.         self._Configure__bug_handler = bug_handler
  13.         self._Configure__show_config_file = show_config_file
  14.  
  15.     
  16.     def get_configuration(self, type):
  17.         self._Configure__configuration_file = self._Configure__get_file_name()
  18.         return_dict = { }
  19.         return_dict['config-location'] = self._Configure__configuration_file
  20.         if self._Configure__show_config_file and self._Configure__configuration_file:
  21.             sys.stderr.write('configuration file is "%s"\n' % self._Configure__configuration_file)
  22.         
  23.         if self._Configure__show_config_file and not (self._Configure__configuration_file):
  24.             sys.stderr.write('No configuraiton file found; using default vaules\n')
  25.         
  26.         if self._Configure__configuration_file:
  27.             read_obj = open(self._Configure__configuration_file, 'r')
  28.             line_to_read = 1
  29.             line_num = 0
  30.             while line_to_read:
  31.                 line_num += 1
  32.                 line_to_read = read_obj.readline()
  33.                 line = line_to_read
  34.                 line = line.strip()
  35.                 if line[0:1] == '#':
  36.                     continue
  37.                 
  38.                 if not line:
  39.                     continue
  40.                 
  41.                 fields = line.split('=')
  42.                 if len(fields) != 2:
  43.                     msg = line
  44.                     msg += 'Error in configuration.txt, line %s\n' % line_num
  45.                     msg += 'Options take the form of option = value.\n'
  46.                     msg += 'Please correct the configuration file "%s" before continuing\n' % self._Configure__configuration_file
  47.                     raise self._Configure__bug_handler, msg
  48.                 len(fields) != 2
  49.                 att = fields[0]
  50.                 value = fields[1]
  51.                 att = att.strip()
  52.                 value = value.strip()
  53.                 return_dict[att] = value
  54.         
  55.         return_dict = self._Configure__parse_dict(return_dict)
  56.         if return_dict == 1:
  57.             msg = 'Please correct the configuration file "%s" before continuing\n' % self._Configure__configuration_file
  58.             raise self._Configure__bug_handler, msg
  59.         return_dict == 1
  60.         return return_dict
  61.  
  62.     
  63.     def __get_file_name(self):
  64.         home_var = os.environ.get('HOME')
  65.         if home_var:
  66.             home_config = os.path.join(home_var, '.rtf2xml')
  67.             if os.path.isfile(home_config):
  68.                 return home_config
  69.         
  70.         home_var = os.environ.get('USERPROFILE')
  71.         if home_var:
  72.             home_config = os.path.join(home_var, '.rtf2xml')
  73.             if os.path.isfile(home_config):
  74.                 return home_config
  75.         
  76.         script_file = os.path.join(sys.path[0], '.rtf2xml')
  77.         if os.path.isfile(script_file):
  78.             return script_file
  79.         return self._Configure__configuration_file
  80.  
  81.     
  82.     def __parse_dict(self, return_dict):
  83.         allowable = [
  84.             'configuration-directory',
  85.             'smart-output',
  86.             'level',
  87.             'convert-symbol',
  88.             'convert-wingdings',
  89.             'convert-zapf-dingbats',
  90.             'convert-caps',
  91.             'indent',
  92.             'group-styles',
  93.             'group-borders',
  94.             'headings-to-sections',
  95.             'lists',
  96.             'raw-dtd-path',
  97.             'write-empty-paragraphs',
  98.             'config-location',
  99.             'script-name']
  100.         the_keys = return_dict.keys()
  101.         for the_key in the_keys:
  102.             if the_key not in allowable:
  103.                 sys.stderr.write('options "%s" not a legal option.\n' % the_key)
  104.                 return 1
  105.         
  106.         configuration_dir = return_dict.get('configuration-directory')
  107.         if configuration_dir == None:
  108.             return_dict['configure-directory'] = None
  109.         elif not os.path.isdir(configuration_dir):
  110.             sys.stderr.write('The dirctory "%s" does not appear to be a directory.\n' % configuration_dir)
  111.             return 1
  112.         return_dict['configure-directory'] = configuration_dir
  113.         smart_output = return_dict.get('smart-output')
  114.         if not smart_output:
  115.             return_dict['smart-output'] = 0
  116.         elif smart_output != 'true' and smart_output != 'false':
  117.             sys.stderr.write('"smart-output" must be true or false.\n')
  118.             return 1
  119.         if smart_output == 'false':
  120.             return_dict['smart-output'] = 0
  121.         
  122.         int_options = [
  123.             'level',
  124.             'indent']
  125.         for int_option in int_options:
  126.             value = return_dict.get(int_option)
  127.             if not value:
  128.                 if int_option == 'level':
  129.                     return_dict['level'] = 1
  130.                 else:
  131.                     return_dict['indent'] = 0
  132.             int_option == 'level'
  133.             
  134.             try:
  135.                 int_num = int(return_dict[int_option])
  136.                 return_dict[int_option] = int_num
  137.             continue
  138.             sys.stderr.write('"%s" must be a number\n' % int_option)
  139.             sys.stderr.write('You choose "%s" ' % return_dict[int_option])
  140.             return 1
  141.  
  142.         
  143.         fonts = [
  144.             'convert-symbol',
  145.             'convert-wingdings',
  146.             'convert-zapf-dingbats',
  147.             'convert-caps']
  148.         for font in fonts:
  149.             value = return_dict.get(font)
  150.             if not value:
  151.                 return_dict[font] = 0
  152.                 continue
  153.             if value != 'true' and value != 'false':
  154.                 sys.stderr.write('"%s" must be true or false.\n' % font)
  155.                 continue
  156.             if value == 'false':
  157.                 return_dict[font] = 0
  158.                 continue
  159.         
  160.         return_dict['xslt-processor'] = None
  161.         return_dict['no-namespace'] = None
  162.         return_dict['format'] = 'raw'
  163.         return_dict['no-pyxml'] = 'true'
  164.         return return_dict
  165.  
  166.  
  167.