Пример #1
0
def tidy_the_stuff(text, tidy_dict):
	tmp_input_f_name = os.path.join(gen_utils.data_dir(), consts.tmp_input_f_name)
	tmp_output_f_name = os.path.join(gen_utils.data_dir(), consts.tmp_output_f_name)

	log_utils.debug('tidying')	
	
	f = open(tmp_input_f_name, 'w')
	f.write(text)
	f.close()
	
	cmd_str = 'tidy %s %s 2> %s' % (tidy_opt_utils.dict_to_str(tidy_dict),
		tmp_input_f_name,
		tmp_output_f_name)
		
	log_utils.debug(cmd_str)
	
	(stat, out) = commands.getstatusoutput(cmd_str)
		
	log_utils.debug('tidied')
	
	log_utils.debug('generating report items')
	
	f = open(tmp_output_f_name, 'r')
	lines = f.readlines()
	f.close()

	errs = [tidy_report_from_line(line) for line in lines]
	errs = [e for e in errs if e != None]
		
	log_utils.debug('generated report items')
	
	return (out, errs)
Пример #2
0
def tidy_the_stuff(text, tidy_dict):
    tmp_input_f_name = os.path.join(gen_utils.data_dir(),
                                    consts.tmp_input_f_name)
    tmp_output_f_name = os.path.join(gen_utils.data_dir(),
                                     consts.tmp_output_f_name)

    log_utils.debug('tidying')

    f = open(tmp_input_f_name, 'w')
    f.write(text)
    f.close()

    cmd_str = 'tidy %s %s 2> %s' % (tidy_opt_utils.dict_to_str(tidy_dict),
                                    tmp_input_f_name, tmp_output_f_name)

    log_utils.debug(cmd_str)

    (stat, out) = commands.getstatusoutput(cmd_str)

    log_utils.debug('tidied')

    log_utils.debug('generating report items')

    f = open(tmp_output_f_name, 'r')
    lines = f.readlines()
    f.close()

    errs = [tidy_report_from_line(line) for line in lines]
    errs = [e for e in errs if e != None]

    log_utils.debug('generated report items')

    return (out, errs)
Пример #3
0
    def test_opt_stream_to_dict_0(self):
        f_name = os.path.join(gen_utils.data_dir(),
                              consts.opt_names_to_f_names['misc_opts'])

        required_dict = {'write-back': 'no', 'gnu-emacs-file': ''}

        self._test_opt_stream_to_dict(f_name, 10, required_dict)
Пример #4
0
	def test_tidy_the_stuff_1(self):		
		f_name = os.path.join(gen_utils.data_dir(), 'bad_tidy_config.txt')		
		opts_dict = 	tidy_opt_utils.read_dict(f_name)
		
		(d, tidy_reports) = tidy_the_stuff('', opts_dict)
		
		self.assert_(len(tidy_reports) != 0)
Пример #5
0
    def test_opt_stream_to_dict_1(self):
        f_name = os.path.join(gen_utils.data_dir(), 'sample_tidy_config.txt')

        required_dict = {
            'indent': 'auto',
            'indent-spaces': '2',
            'wrap': '72',
            'markup': 'yes',
            'output-xml': 'no',
            'input-xml': 'no',
            'show-warnings': 'yes',
            'numeric-entities': 'yes',
            'quote-marks': 'yes',
            'quote-nbsp': 'yes',
            'quote-ampersand': 'no',
            'break-before-br': 'no',
            'uppercase-tags': 'no',
            'uppercase-attributes': 'no',
            'char-encoding': 'latin1',
            'new-inline-tags':
            'cfif, cfelse, math, mroot, \n   mrow, mi, mn, mo, msqrt, mfrac, msubsup, munderover,\n   munder, mover, mmultiscripts, msup, msub, mtext,\n   mprescripts, mtable, mtr, mtd, mth',
            'new-blocklevel-tags': 'cfoutput, cfquery',
            'new-empty-tags': 'cfelse'
        }

        self._test_opt_stream_to_dict(f_name, 18, required_dict)
Пример #6
0
    def test_tidy_the_stuff_1(self):
        f_name = os.path.join(gen_utils.data_dir(), 'bad_tidy_config.txt')
        opts_dict = tidy_opt_utils.read_dict(f_name)

        (d, tidy_reports) = tidy_the_stuff('', opts_dict)

        self.assert_(len(tidy_reports) != 0)
Пример #7
0
	def test_opt_stream_to_dict(self):
		f_name = os.path.join(gen_utils.data_dir(), consts.opt_names_to_f_names['misc_opts'])
		d = _opt_stream_to_dict(open(f_name, 'r'))
		
		self.assertEqual(len(d), 10)
		self.assertEqual(d['write-back'], False)
		self.assertEqual(gen_utils.is_bool_type(d['write-back']), True)
		self.assertEqual(d['gnu-emacs-file'], '')
Пример #8
0
    def test_notebook_1(self):
        sample_f_name = os.path.join(gen_utils.data_dir(),
                                     consts.sample_tidy_config_f_name)

        sample_dict = tidy_opt_utils.read_dict(sample_f_name)

        self._test_notebook(tidy_opt_utils.dict_to_names_dicts(sample_dict),
                            False)
Пример #9
0
	def test_opt_stream_to_dict_0(self):
		f_name = os.path.join(gen_utils.data_dir(), consts.opt_names_to_f_names['misc_opts'])
		
		required_dict = {
			'write-back': 'no',
			'gnu-emacs-file': ''}
		
		self._test_opt_stream_to_dict(f_name, 10, required_dict)
Пример #10
0
    def test_opt_stream_to_dict(self):
        f_name = os.path.join(gen_utils.data_dir(),
                              consts.opt_names_to_f_names['misc_opts'])
        d = _opt_stream_to_dict(open(f_name, 'r'))

        self.assertEqual(len(d), 10)
        self.assertEqual(d['write-back'], False)
        self.assertEqual(gen_utils.is_bool_type(d['write-back']), True)
        self.assertEqual(d['gnu-emacs-file'], '')
Пример #11
0
	def _test_tab(self, sensitive):		
		f_name = os.path.join(gen_utils.data_dir(), consts.opt_names_to_f_names['html_xhtml_xml_opts'])
		opts_dict = tidy_opt_utils.read_dict(f_name)
		
		o = tab(opts_dict, sensitive)

		o.connect('destroy', gtk.main_quit)	

		main_wnd = gtk.Window(gtk.WINDOW_TOPLEVEL)
		main_wnd.set_title('Output');
		main_wnd.add(o)

		main_wnd.show_all()
		gtk.main()
Пример #12
0
def default_names_dicts():
	"""
	Returns a pair-list of Tidy's default options.
	The first item in each pair is the name of the dictionary (e.g., "Diagnostics"); the second
	item in each pair is the dictionary itself.
	"""
	names = [consts.opt_names_to_logical_names[k] for k in consts.opts] 

	data_dir = gen_utils.data_dir()
	
	f_names = [os.path.join(data_dir, consts.opt_names_to_f_names[k]) for k in consts.opts]

	dicts = [_opt_stream_to_dict(open(f_name, 'r')) for f_name in f_names]	
	
	return [p for p in itertools.izip(names, dicts)]
Пример #13
0
def default_names_dicts():
    """
	Returns a pair-list of Tidy's default options.
	The first item in each pair is the name of the dictionary (e.g., "Diagnostics"); the second
	item in each pair is the dictionary itself.
	"""
    names = [consts.opt_names_to_logical_names[k] for k in consts.opts]

    data_dir = gen_utils.data_dir()

    f_names = [
        os.path.join(data_dir, consts.opt_names_to_f_names[k])
        for k in consts.opts
    ]

    dicts = [_opt_stream_to_dict(open(f_name, 'r')) for f_name in f_names]

    return [p for p in itertools.izip(names, dicts)]
Пример #14
0
def read_config_dict():
	"""
	Reads the configuration dictionary from a predefined file (defined in consts.py).
	"""
	log_utils.debug('reading config dict')

	data_dir = gen_utils.data_dir()	

	d = _default_config_dict()

	f_name = os.path.join(data_dir, consts.config_f_name)

	try:
		f = open(f_name, 'r')
		d = opt_stream_utils.opt_stream_to_dict(f)					
		f.close()
	except Exception, inst:		
		log_utils.warn(str(inst))
		log_utils.warn('couldn\'t read config dict from %s' % f_name)
Пример #15
0
def write_config_dict(d):
	"""
	Writes the configuration dictionary to a predefined file (defined in consts.py).
	"""
	log_utils.debug('writing config dict')
					
	custom_dict = tidy_opt_utils.names_dicts_to_dict(d[consts.custom_opts_names_dicts_category])
	tidy_opt_utils.write_dict(custom_dict, consts.custom_opt_file_name)
	
	tmp_d = {}
	
	for k in [k for k in d.keys() if k != consts.custom_opts_names_dicts_category]:
		tmp_d[k] = d[k]

	f_name = os.path.join(gen_utils.data_dir(), consts.config_f_name)

	f = open(f_name, 'w')
	opt_stream_utils.dict_to_opt_stream(tmp_d, f)
	f.close()
		
	log_utils.debug('wrote config dict')			
Пример #16
0
	def test_opt_stream_to_dict_1(self):
		f_name = os.path.join(gen_utils.data_dir(), 'sample_tidy_config.txt')
		
		required_dict = {
			'indent': 'auto',
			'indent-spaces': '2',
			'wrap': '72',
			'markup': 'yes',
			'output-xml': 'no',
			'input-xml': 'no',
			'show-warnings': 'yes',
			'numeric-entities': 'yes',
			'quote-marks': 'yes',
			'quote-nbsp': 'yes',
			'quote-ampersand': 'no',
			'break-before-br': 'no',
			'uppercase-tags': 'no',
			'uppercase-attributes': 'no',
			'char-encoding': 'latin1',
			'new-inline-tags': 'cfif, cfelse, math, mroot, \n   mrow, mi, mn, mo, msqrt, mfrac, msubsup, munderover,\n   munder, mover, mmultiscripts, msup, msub, mtext,\n   mprescripts, mtable, mtr, mtd, mth',
			'new-blocklevel-tags': 'cfoutput, cfquery',
			'new-empty-tags': 'cfelse'}
		
		self._test_opt_stream_to_dict(f_name, 18, required_dict)
Пример #17
0
    def __init__(self):
        super(html_tidy_plugin, self).__init__()
        self._instances = {}
        self._data_dir = gen_utils.data_dir()

        self.config_dict = config_dict.read_config_dict()
Пример #18
0
	def test_notebook_1(self):
	 	sample_f_name = os.path.join(gen_utils.data_dir(), consts.sample_tidy_config_f_name)
	 	
	 	sample_dict = tidy_opt_utils.read_dict(sample_f_name)
	 	
		self._test_notebook(tidy_opt_utils.dict_to_names_dicts(sample_dict), False)
Пример #19
0
	def __init__(self):
		super(html_tidy_plugin, self).__init__()
		self._instances = {}
		self._data_dir = gen_utils.data_dir()
		
		self.config_dict = config_dict.read_config_dict()