Esempio n. 1
0
def make_me_magic(write):
    """ Main script.

    Here we find templates, replace old-style url tags and add future import where necessary.
    """
    # Search for files with appropriate extensions.
    log.info('Files needing modification:')
    found = False
    for file_path in find_files(os.walk(CURRENT_PATH)):
        with open(file_path, 'r+') as t_file:
            file_content = t_file.read()
            # Checking for presence of old-style tags and absence of load url from future
            if has_deprecated_tag(file_content):
                found = True
                log.info(file_path.replace(CURRENT_PATH + '/', ''))
                new_content = parse_file(file_content)

                if write:
                    t_file.seek(0)
                    t_file.write(new_content)
                    log.info('    File updated')

    if not found:
        log.info('All files are up to date. Congrats!')
    else:
        if not write:
            log.info('No actual changes made. Run future_url --write to fix files right now.')
Esempio n. 2
0
def make_me_magic(write):
    """ Main script.

    Here we find templates, replace old-style url tags and add future import where necessary.
    """
    # Search for files with appropriate extensions.
    log.info('Files needing modification:')
    found = False
    for file_path in find_files(os.walk(CURRENT_PATH)):
        with open(file_path, 'r+') as t_file:
            file_content = t_file.read()
            # Checking for presence of old-style tags and absence of load url from future
            if has_deprecated_tag(file_content):
                found = True
                log.info(file_path.replace(CURRENT_PATH + '/', ''))
                new_content = parse_file(file_content)

                if write:
                    t_file.seek(0)
                    t_file.write(new_content)
                    log.info('    File updated')

    if not found:
        log.info('All files are up to date. Congrats!')
    else:
        if not write:
            log.info(
                'No actual changes made. Run future_url --write to fix files right now.'
            )
Esempio n. 3
0
    def assertTemplateFixed(self, template_name):
        base = os.path.abspath(os.path.dirname(__file__))
        input_filepath = os.path.join(base, 'examples', template_name + '.html')
        expected_filepath = os.path.join(base, 'expected', template_name + '.fixed.html')

        output = parse_file(codecs.open(input_filepath, 'r', 'utf-8').read())
        expected_output = codecs.open(expected_filepath, 'r', 'utf-8').read()
        self.assertEqual(output, expected_output)
Esempio n. 4
0
    def assertTemplateFixed(self, template_name):
        base = os.path.abspath(os.path.dirname(__file__))
        input_filepath = os.path.join(base, 'examples',
                                      template_name + '.html')
        expected_filepath = os.path.join(base, 'expected',
                                         template_name + '.fixed.html')

        output = parse_file(codecs.open(input_filepath, 'r', 'utf-8').read())
        expected_output = codecs.open(expected_filepath, 'r', 'utf-8').read()
        self.assertEqual(output, expected_output)