Changeset - 665dfa112f2c
[Not reviewed]
default
0 6 0
Lars Kruse - 8 years ago 2017-08-25 14:30:57
devel@sumpfralle.de
py3: replace "file" with "open"
6 files changed with 12 insertions and 12 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/paster_commands/install_iis.py
Show inline comments
 
@@ -54,44 +54,44 @@ if __name__=='__main__':
 
    params = ISAPIParameters()
 
    sm = [ScriptMapParams(Extension="*", Flags=0)]
 
    vd = VirtualDirParameters(Name="%(virtualdir)s",
 
                              Description = "Kallithea",
 
                              ScriptMaps = sm,
 
                              ScriptMapUpdate = "replace")
 
    params.VirtualDirs = [vd]
 
    HandleCommandLine(params)
 
'''
 

	
 
class Command(BasePasterCommand):
 
    '''Kallithea: Install into IIS using isapi-wsgi'''
 

	
 
    requires_db_session = False
 

	
 
    def take_action(self, args):
 
        config_file = os.path.abspath(args.config_file)
 
        try:
 
            import isapi_wsgi
 
        except ImportError:
 
            self.error('missing requirement: isapi-wsgi not installed')
 

	
 
        dispatchfile = os.path.join(os.getcwd(), 'dispatch.py')
 
        print 'Writing %s' % dispatchfile
 
        with file(dispatchfile, 'w') as f:
 
        with open(dispatchfile, 'w') as f:
 
            f.write(dispath_py_template % {
 
                'inifile': config_file.replace('\\', '\\\\'),
 
                'virtualdir': args.virtualdir,
 
                })
 

	
 
        print ('Run \'python "%s" install\' with administrative privileges '
 
            'to generate the _dispatch.dll file and install it into the '
 
            'default web site') % (dispatchfile,)
 

	
 
    def get_parser(self, prog_name):
 
        parser = super(Command, self).get_parser(prog_name)
 

	
 
        parser.add_argument('--virtualdir',
 
                      action='store',
 
                      dest='virtualdir',
 
                      default='/',
 
                      help='The virtual folder to install into on IIS')
 

	
 
        return parser
kallithea/tests/models/test_notifications.py
Show inline comments
 
@@ -262,30 +262,30 @@ class TestNotifications(TestController):
 
                                kwargs[param_name] = v
 
                                new_params.append(('%s, %s=%r' % (desc, param_name, v), type_, body, kwargs))
 
                        params = new_params
 

	
 
                    for desc, type_, body, kwargs in params:
 
                        # desc is used as "global" variable
 
                        notification = NotificationModel().create(created_by=self.u1,
 
                                                           subject=u'unused', body=body, email_kwargs=kwargs,
 
                                                           recipients=[self.u2], type_=type_)
 

	
 
                # Email type TYPE_PASSWORD_RESET has no corresponding notification type - test it directly:
 
                desc = 'TYPE_PASSWORD_RESET'
 
                kwargs = dict(user='John Doe', reset_token='decbf64715098db5b0bd23eab44bd792670ab746', reset_url='http://reset.com/decbf64715098db5b0bd23eab44bd792670ab746')
 
                kallithea.lib.celerylib.tasks.send_email(['john@doe.com'],
 
                    "Password reset link",
 
                    EmailNotificationModel().get_email_tmpl(EmailNotificationModel.TYPE_PASSWORD_RESET, 'txt', **kwargs),
 
                    EmailNotificationModel().get_email_tmpl(EmailNotificationModel.TYPE_PASSWORD_RESET, 'html', **kwargs),
 
                    author=User.get(self.u1))
 

	
 
        out = '<!doctype html>\n<html lang="en">\n<head><title>Notifications</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>\n<body>\n%s\n</body>\n</html>\n' % \
 
            re.sub(r'<(/?(?:!doctype|html|head|title|meta|body)\b[^>]*)>', r'<!--\1-->', ''.join(l))
 

	
 
        outfn = os.path.join(os.path.dirname(__file__), 'test_dump_html_mails.out.html')
 
        reffn = os.path.join(os.path.dirname(__file__), 'test_dump_html_mails.ref.html')
 
        with file(outfn, 'w') as f:
 
        with open(outfn, 'w') as f:
 
            f.write(out)
 
        with file(reffn) as f:
 
        with open(reffn) as f:
 
            ref = f.read()
 
        assert ref == out # copy test_dump_html_mails.out.html to test_dump_html_mails.ref.html to update expectations
 
        os.unlink(outfn)
scripts/docs-headings.py
Show inline comments
 
@@ -11,69 +11,69 @@ spaces = [
 
    (0, 1), # we assume this is a over-and-underlined header
 
    (2, 1),
 
    (1, 1),
 
    (1, 0),
 
    (1, 0),
 
    ]
 

	
 
# http://sphinx-doc.org/rest.html :
 
#   for the Python documentation, this convention is used which you may follow:
 
#   # with overline, for parts
 
#   * with overline, for chapters
 
#   =, for sections
 
#   -, for subsections
 
#   ^, for subsubsections
 
#   ", for paragraphs
 
pystyles = ['#', '*', '=', '-', '^', '"']
 

	
 
# match on a header line underlined with one of the valid characters
 
headermatch = re.compile(r'''\n*(.+)\n([][!"#$%&'()*+,./:;<=>?@\\^_`{|}~-])\2{2,}\n+''', flags=re.MULTILINE)
 

	
 

	
 
def main():
 
    for fn in subprocess.check_output(['hg', 'loc', 'set:**.rst+kallithea/i18n/how_to']).splitlines():
 
        print 'processing %s:' % fn
 
        s = file(fn).read()
 
        s = open(fn).read()
 

	
 
        # find levels and their styles
 
        lastpos = 0
 
        styles = []
 
        for markup in headermatch.findall(s):
 
            style = markup[1]
 
            if style in styles:
 
                stylepos = styles.index(style)
 
                if stylepos > lastpos + 1:
 
                    print 'bad style %r with level %s - was at %s' % (style, stylepos, lastpos)
 
            else:
 
                stylepos = len(styles)
 
                if stylepos > lastpos + 1:
 
                    print 'bad new style %r - expected %r' % (style, styles[lastpos + 1])
 
                else:
 
                    styles.append(style)
 
            lastpos = stylepos
 

	
 
        # remove superfluous spacing (may however be restored by header spacing)
 
        s = re.sub(r'''(\n\n)\n*''', r'\1', s, flags=re.MULTILINE)
 

	
 
        if styles:
 
            newstyles = pystyles[pystyles.index(styles[0]):]
 

	
 
            def subf(m):
 
                title, style = m.groups()
 
                level = styles.index(style)
 
                before, after = spaces[level]
 
                newstyle = newstyles[level]
 
                return '\n' * (before + 1) + title + '\n' + newstyle * len(title) + '\n' * (after + 1)
 
            s = headermatch.sub(subf, s)
 

	
 
        # remove superfluous spacing when headers are adjacent
 
        s = re.sub(r'''(\n.+\n([][!"#$%&'()*+,./:;<=>?@\\^_`{|}~-])\2{2,}\n\n\n)\n*''', r'\1', s, flags=re.MULTILINE)
 
        # fix trailing space and spacing before link sections
 
        s = s.strip() + '\n'
 
        s = re.sub(r'''\n+((?:\.\. _[^\n]*\n)+)$''', r'\n\n\n\1', s)
 

	
 
        file(fn, 'w').write(s)
 
        open(fn, 'w').write(s)
 
        print subprocess.check_output(['hg', 'diff', fn])
 
        print
 

	
 
if __name__ == '__main__':
 
    main()
scripts/generate-ini.py
Show inline comments
 
@@ -69,54 +69,54 @@ ini_files = [
 
                'host': '0.0.0.0',
 
            },
 
            '[app:main]': {
 
                'initial_repo_scan': 'true',
 
                'debug': 'true',
 
                'app_instance_uuid': 'development-not-secret',
 
                'beaker.session.secret': 'development-not-secret',
 
            },
 
            '[handler_console]': {
 
                'level': 'DEBUG',
 
                'formatter': 'color_formatter',
 
            },
 
            '[handler_console_sql]': {
 
                'level': 'DEBUG',
 
                'formatter': 'color_formatter_sql',
 
            },
 
        },
 
    ),
 
]
 

	
 

	
 
def main():
 
    # make sure all mako lines starting with '#' (the '##' comments) are marked up as <text>
 
    print 'reading:', makofile
 
    mako_org = file(makofile).read()
 
    mako_org = open(makofile).read()
 
    mako_no_text_markup = re.sub(r'</?%text>', '', mako_org)
 
    mako_marked_up = re.sub(r'\n(##.*)', r'\n<%text>\1</%text>', mako_no_text_markup, flags=re.MULTILINE)
 
    if mako_marked_up != mako_org:
 
        print 'writing:', makofile
 
        file(makofile, 'w').write(mako_marked_up)
 
        open(makofile, 'w').write(mako_marked_up)
 

	
 
    # select the right mako conditionals for the other less sophisticated formats
 
    def sub_conditionals(m):
 
        """given a %if...%endif match, replace with just the selected
 
        conditional sections enabled and the rest as comments
 
        """
 
        conditional_lines = m.group(1)
 
        def sub_conditional(m):
 
            """given a conditional and the corresponding lines, return them raw
 
            or commented out, based on whether conditional is selected
 
            """
 
            criteria, lines = m.groups()
 
            if criteria not in selected_mako_conditionals:
 
                lines = '\n'.join((l if not l or l.startswith('#') else '#' + l) for l in lines.split('\n'))
 
            return lines
 
        conditional_lines = re.sub(r'^%(?:el)?if (.*):\n((?:^[^%\n].*\n|\n)*)',
 
            sub_conditional, conditional_lines, flags=re.MULTILINE)
 
        return conditional_lines
 
    mako_no_conditionals = re.sub(r'^(%if .*\n(?:[^%\n].*\n|%elif .*\n|\n)*)%endif\n',
 
        sub_conditionals, mako_no_text_markup, flags=re.MULTILINE)
 

	
 
    # expand mako variables
 
    def pyrepl(m):
 
        return mako_variable_values.get(m.group(1), m.group(0))
 
@@ -128,28 +128,28 @@ def main():
 
    # create ini files
 
    for fn, desc, settings in ini_files:
 
        print 'updating:', fn
 
        ini_lines = re.sub(
 
            '# Kallithea - config file generated with kallithea-config *#\n',
 
            ''.join('# %-77s#\n' % l.strip() for l in desc.strip().split('\n')),
 
            base_ini)
 
        def process_section(m):
 
            """process a ini section, replacing values as necessary"""
 
            sectionname, lines = m.groups()
 
            if sectionname in settings:
 
                section_settings = settings[sectionname]
 
                def process_line(m):
 
                    """process a section line and update value if necessary"""
 
                    setting, value = m.groups()
 
                    line = m.group(0)
 
                    if setting in section_settings:
 
                        line = '%s = %s' % (setting, section_settings[setting])
 
                        if '$' not in value:
 
                            line = '#%s = %s\n%s' % (setting, value, line)
 
                    return line.rstrip()
 
                lines = re.sub(r'^([^#\n].*) = ?(.*)', process_line, lines, flags=re.MULTILINE)
 
            return sectionname + '\n' + lines
 
        ini_lines = re.sub(r'^(\[.*\])\n((?:(?:[^[\n].*)?\n)*)', process_section, ini_lines, flags=re.MULTILINE)
 
        file(fn, 'w').write(ini_lines)
 
        open(fn, 'w').write(ini_lines)
 

	
 
if __name__ == '__main__':
 
    main()
scripts/logformat.py
Show inline comments
 
@@ -12,28 +12,28 @@ if len(sys.argv) < 2:
 

	
 
logre = r'''
 
(log\.(?:error|info|warning|debug)
 
[(][ \n]*
 
)
 
%s
 
(
 
[ \n]*[)]
 
)
 
'''
 
res = [
 
    # handle % () - keeping spaces around the old %
 
    (re.compile(logre % r'''("[^"]*"|'[^']*')   ([\n ]*) %  ([\n ]*) \( ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) \) ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
 
    # handle % without () - keeping spaces around the old %
 
    (re.compile(logre % r'''("[^"]*"|'[^']*')   ([\n ]*) %  ([\n ]*)    ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* )    ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
 
    # remove extra space if it is on next line
 
    (re.compile(logre % r'''("[^"]*"|'[^']*') , (\n [ ]) ([ ][\n ]*)    ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* )    ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
 
    # remove extra space if it is on same line
 
    (re.compile(logre % r'''("[^"]*"|'[^']*') , [ ]+  () (   [\n ]+)    ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* )    ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
 
    # remove trailing , and space
 
    (re.compile(logre % r'''("[^"]*"|'[^']*') ,       () (   [\n ]*)    ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* [^(), \n] ) [ ,]*''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
 
    ]
 

	
 
for f in sys.argv[1:]:
 
    s = file(f).read()
 
    s = open(f).read()
 
    for r, t in res:
 
        s = r.sub(t, s)
 
    file(f, 'w').write(s)
 
    open(f, 'w').write(s)
scripts/update-copyrights.py
Show inline comments
 
@@ -176,52 +176,52 @@ def insert_entries(
 
        normalize_name,
 
        format_f):
 
    """Update file with contributor information.
 
    all_entries: list of tuples with year and name
 
    no_entries: set of names or name and year tuples to ignore
 
    domain_extra: map domain name to extra credit name
 
    split_re: regexp matching the part of file to rewrite
 
    normalize_name: function to normalize names for grouping and display
 
    format_f: function formatting year list and name to a string
 
    """
 
    name_years = defaultdict(set)
 

	
 
    for year, name in all_entries:
 
        if name in no_entries or (name, year) in no_entries:
 
            continue
 
        domain = name.split('@', 1)[-1].rstrip('>')
 
        if domain in domain_extra:
 
            name_years[domain_extra[domain]].add(year)
 
        name_years[normalize_name(name)].add(year)
 

	
 
    l = [(list(sorted(year for year in years if year)), name)
 
         for name, years in name_years.items()]
 
    l.sort(key=sortkey)
 

	
 
    with file(filename) as f:
 
    with open(filename) as f:
 
        pre, post = re.split(split_re, f.read())
 

	
 
    with file(filename, 'w') as f:
 
    with open(filename, 'w') as f:
 
        f.write(pre +
 
                ''.join(format_f(years, name) for years, name in l) +
 
                post)
 

	
 

	
 
def main():
 
    repo_entries = [
 
        (year, name_fixes.get(name) or name_fixes.get(name.rsplit('<', 1)[0].strip()) or name)
 
        for year, name in
 
        (line.strip().split(' ', 1)
 
         for line in os.popen("""hg log -r '::.' -T '{date(date,"%Y")} {author}\n'""").readlines())
 
        ]
 

	
 
    insert_entries(
 
        filename='kallithea/templates/about.html',
 
        all_entries=repo_entries + other_about,
 
        no_entries=no_about,
 
        domain_extra=domain_extra,
 
        split_re=r'(?:  <li>Copyright &copy; [^\n]*</li>\n)*',
 
        normalize_name=lambda name: name.split('<', 1)[0].strip(),
 
        format_f=lambda years, name: '  <li>Copyright &copy; %s, %s</li>\n' % (nice_years(years, '&ndash;', ', '), name),
 
        )
 

	
 
    insert_entries(
0 comments (0 inline, 0 general)