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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import os
  6. from calibre.ebooks.rtf2xml import options_trem, configure_txt
  7.  
  8. class GetOptions:
  9.     
  10.     def __init__(self, system_arguments, rtf_dir, bug_handler, configuration_file = None):
  11.         self._GetOptions__system_arguments = system_arguments
  12.         self._GetOptions__rtf_dir = rtf_dir
  13.         self._GetOptions__configuration_file = configuration_file
  14.         self._GetOptions__bug_handler = bug_handler
  15.  
  16.     
  17.     def get_options(self):
  18.         return_options = self._GetOptions__get_config_options()
  19.         options_dict = {
  20.             'dir': [
  21.                 1],
  22.             'help': [
  23.                 0,
  24.                 'h'],
  25.             'show-warnings': [
  26.                 0],
  27.             'caps': [
  28.                 0],
  29.             'no-caps': [
  30.                 0],
  31.             'symbol': [
  32.                 0],
  33.             'no-symbol': [
  34.                 0],
  35.             'windings': [
  36.                 0],
  37.             'no-wingdings': [
  38.                 0],
  39.             'zapf': [
  40.                 0],
  41.             'no-zapf': [
  42.                 0],
  43.             'font': [
  44.                 0],
  45.             'no-font': [
  46.                 0],
  47.             'dtd': [
  48.                 1],
  49.             'no-dtd': [
  50.                 0],
  51.             'version': [
  52.                 0],
  53.             'output': [
  54.                 1,
  55.                 'o'],
  56.             'no-namespace': [
  57.                 0],
  58.             'level': [
  59.                 1],
  60.             'indent': [
  61.                 1],
  62.             'no-lists': [
  63.                 0],
  64.             'lists': [
  65.                 0],
  66.             'group-styles': [
  67.                 0],
  68.             'no-group-styles': [
  69.                 0],
  70.             'group-borders': [
  71.                 0],
  72.             'no-group-borders': [
  73.                 0],
  74.             'headings-to-sections': [
  75.                 0],
  76.             'no-headings-to-sections': [
  77.                 0],
  78.             'empty-para': [
  79.                 0],
  80.             'no-empty-para': [
  81.                 0],
  82.             'format': [
  83.                 1,
  84.                 'f'],
  85.             'config': [
  86.                 0] }
  87.         options_obj = options_trem.ParseOptions(system_string = self._GetOptions__system_arguments, options_dict = options_dict)
  88.         (options, arguments) = options_obj.parse_options()
  89.         if options == 0:
  90.             return_options['valid'] = 0
  91.             return return_options
  92.         the_keys = options.keys()
  93.         return_options['help'] = 0
  94.         if 'help' in the_keys:
  95.             return_options['help'] = 1
  96.             return return_options
  97.         return_options['config'] = 0
  98.         if 'config' in the_keys:
  99.             return_options['config'] = 1
  100.             return return_options
  101.         return_options['version'] = 0
  102.         if 'version' in the_keys:
  103.             return_options['version'] = 1
  104.             return return_options
  105.         return_options['out-dir'] = 0
  106.         return_options['out-file'] = 0
  107.         if 'level' in the_keys:
  108.             return_options['level'] = options['level']
  109.         
  110.         the_level = return_options.get('level')
  111.         if the_level:
  112.             
  113.             try:
  114.                 return_options['level'] = int(the_level)
  115.             except ValueError:
  116.                 sys.stderr.write('The options "--level" must be a number.\n')
  117.                 return_options['valid'] = 0
  118.                 return return_options
  119.             
  120.  
  121.         None<EXCEPTION MATCH>ValueError
  122.         if 'dtd' in the_keys:
  123.             return_options['raw-dtd-path'] = options['dtd']
  124.         
  125.         acceptable = [
  126.             'sdoc',
  127.             'raw',
  128.             'tei']
  129.         if 'format' in the_keys:
  130.             format = options['format']
  131.             if format not in acceptable:
  132.                 sys.stderr.write("--format must take either 'sdoc' or 'tei'\n")
  133.                 return_options['valid'] = 0
  134.                 return return_options
  135.             return_options['format'] = options['format']
  136.         
  137.         return_options['show-warnings'] = 0
  138.         if 'show-warnings' in the_keys:
  139.             return_options['show-warnings'] = 1
  140.         
  141.         if 'no-font' in the_keys:
  142.             return_options['convert-symbol'] = 0
  143.             return_options['convert-zapf'] = 0
  144.             return_options['convert-wingdings'] = 0
  145.         
  146.         if 'font' in the_keys:
  147.             return_options['convert-symbol'] = 1
  148.             return_options['convert-zapf'] = 1
  149.             return_options['convert-wingdings'] = 1
  150.         
  151.         if 'symbol' in the_keys:
  152.             return_options['convert-symbol'] = 1
  153.         
  154.         if 'no-symbol' in the_keys:
  155.             return_options['convert-symbol'] = 0
  156.         
  157.         if 'wingdings' in the_keys:
  158.             return_options['convert-wingdings'] = 1
  159.         
  160.         if 'no-wingdings' in the_keys:
  161.             return_options['convert-wingdings'] = 0
  162.         
  163.         if 'zapf' in the_keys:
  164.             return_options['convert-zapf'] = 1
  165.         
  166.         if 'no-zapf' in the_keys:
  167.             return_options['convert-zapf'] = 0
  168.         
  169.         if 'caps' in the_keys:
  170.             return_options['convert-caps'] = 1
  171.         
  172.         if 'no-caps' in the_keys:
  173.             return_options['convert-caps'] = 0
  174.         
  175.         if 'no-dtd' in the_keys:
  176.             return_options['no-dtd'] = 1
  177.         else:
  178.             return_options['no-dtd'] = 0
  179.         return_options['no-ask'] = 0
  180.         if 'no-ask' in the_keys:
  181.             return_options['no-ask'] = 1
  182.             sys.stderr.write('You can also permanetly set the no-ask option in the rtf2xml file.\n')
  183.         
  184.         if 'no-namespace' in the_keys:
  185.             return_options['no-namespace'] = 1
  186.         
  187.         if 'headings-to-sections' in the_keys:
  188.             return_options['headings-to-sections'] = 1
  189.         elif 'no-headings-to-sections' in the_keys:
  190.             return_options['headings-to-sections'] = 0
  191.         
  192.         if 'no-lists' in the_keys:
  193.             return_options['form-lists'] = 0
  194.         elif 'lists' in the_keys:
  195.             return_options['form-lists'] = 1
  196.         
  197.         if 'group-styles' in the_keys:
  198.             return_options['group-styles'] = 1
  199.         elif 'no-group-styles' in the_keys:
  200.             return_options['group-styles'] = 0
  201.         
  202.         if 'group-borders' in the_keys:
  203.             return_options['group-borders'] = 1
  204.         elif 'no-group-borders' in the_keys:
  205.             return_options['group-borders'] = 0
  206.         
  207.         if 'empty-para' in the_keys:
  208.             return_options['empty-paragraphs'] = 1
  209.         elif 'no-empty-para' in the_keys:
  210.             return_options['empty-paragraphs'] = 0
  211.         
  212.         if len(arguments) == 0:
  213.             sys.stderr.write('You must provide a file to convert.\n')
  214.             return_options['valid'] = 0
  215.             return return_options
  216.         if len(arguments) > 1:
  217.             sys.stderr.write('You can only convert one file at a time.\n')
  218.             return_options['valid'] = 0
  219.         else:
  220.             return_options['in-file'] = arguments[0]
  221.         smart_output = return_options.get('smart-output')
  222.         if smart_output == 'false':
  223.             smart_output = 0
  224.         
  225.         if smart_output and not return_options['out-file']:
  226.             in_file = return_options['in-file']
  227.             (the_file_name, ext) = os.path.splitext(in_file)
  228.             if ext != '.rtf':
  229.                 sys.stderr.write('Sorry, but this file does not have an "rtf" extension, so \nthe script will not attempt to convert it.\nIf it is in fact an rtf file, use the "-o" option.\n')
  230.                 return_options['valid'] = 0
  231.             else:
  232.                 return_options['out-file'] = '%s.xml' % the_file_name
  233.         
  234.         if not smart_output and not return_options['out-file']:
  235.             pass
  236.         
  237.         if 'indent' in the_keys:
  238.             
  239.             try:
  240.                 value = int(options['indent'])
  241.                 return_options['indent'] = value
  242.             except ValueError:
  243.                 sys.stderr.write('--indent must take an integer')
  244.                 return_options['valid'] = 0
  245.             except:
  246.                 None<EXCEPTION MATCH>ValueError
  247.             
  248.  
  249.         None<EXCEPTION MATCH>ValueError
  250.         return return_options
  251.  
  252.     
  253.     def __get_config_options(self):
  254.         configure_obj = configure_txt.Configure(bug_handler = self._GetOptions__bug_handler, configuration_file = self._GetOptions__configuration_file)
  255.         options_dict = configure_obj.get_configuration(type = 'normal')
  256.         if options_dict == 1:
  257.             sys.exit(1)
  258.         
  259.         options_dict['valid'] = 1
  260.         convert_caps = options_dict.get('convert-caps')
  261.         if convert_caps == 'false':
  262.             options_dict['convert-caps'] = 0
  263.         
  264.         convert_symbol = options_dict.get('convert-symbol')
  265.         if convert_symbol == 'false':
  266.             options_dict['convert-symbol'] = 0
  267.         
  268.         convert_wingdings = options_dict.get('convert-wingdings')
  269.         if convert_wingdings == 'false':
  270.             options_dict['convert-wingdings'] = 0
  271.         
  272.         convert_zapf = options_dict.get('convert-zapf-dingbats')
  273.         if convert_zapf == 'false':
  274.             options_dict['convert-zapf'] = 0
  275.         elif convert_zapf == 'true':
  276.             options_dict['convert-zapf'] = 1
  277.         
  278.         headings_to_sections = options_dict.get('headings-to-sections')
  279.         if headings_to_sections == 'true':
  280.             options_dict['headings-to-sections'] = 1
  281.         elif headings_to_sections == '1':
  282.             options_dict['headings-to-sections'] = 1
  283.         elif headings_to_sections == 'false':
  284.             options_dict['headings-to-sections'] = 0
  285.         elif headings_to_sections == '0':
  286.             options_dict['headings-to-sections'] = 0
  287.         else:
  288.             options_dict['headings-to-sections'] = 0
  289.         write_empty_paragraphs = options_dict.get('write-empty-paragraphs')
  290.         if write_empty_paragraphs == 'true':
  291.             options_dict['empty-paragraphs'] = 1
  292.         elif write_empty_paragraphs == '1':
  293.             options_dict['empty-paragraphs'] = 1
  294.         elif write_empty_paragraphs == 'false':
  295.             options_dict['empty-paragraphs'] = 0
  296.         elif write_empty_paragraphs == '0':
  297.             options_dict['empty-paragraphs'] = 0
  298.         else:
  299.             options_dict['empty-paragraphs'] = 1
  300.         form_lists = options_dict.get('lists')
  301.         if form_lists == 'true' or form_lists == '1':
  302.             options_dict['form-lists'] = 1
  303.         elif form_lists == 'false' or form_lists == '0':
  304.             options_dict['form-lists'] = 0
  305.         else:
  306.             options_dict['form-lists'] = 0
  307.         group_styles = options_dict.get('group-styles')
  308.         if group_styles == 'true' or group_styles == '1':
  309.             options_dict['group-styles'] = 1
  310.         elif group_styles == 'false' or group_styles == '0':
  311.             options_dict['group-styles'] = 0
  312.         else:
  313.             options_dict['group-styles'] = 0
  314.         group_borders = options_dict.get('group-borders')
  315.         if group_borders == 'true' or group_borders == '1':
  316.             options_dict['group-borders'] = 1
  317.         elif group_borders == 'false' or group_borders == '0':
  318.             options_dict['group-borders'] = 0
  319.         else:
  320.             options_dict['group-borders'] = 0
  321.         return options_dict
  322.  
  323.  
  324.