Author: sebb Date: Sat Dec 16 13:47:39 2023 New Revision: 1914713 URL: http://svn.apache.org/viewvc?rev=1914713&view=rev Log: Pylint
Modified: attic/site/retire.py Modified: attic/site/retire.py URL: http://svn.apache.org/viewvc/attic/site/retire.py?rev=1914713&r1=1914712&r2=1914713&view=diff ============================================================================== --- attic/site/retire.py (original) +++ attic/site/retire.py Sat Dec 16 13:47:39 2023 @@ -30,26 +30,25 @@ import os import re from urlutils import loadyaml, loadjson, urlexists -CWIKI='https://cwiki.apache.org/confluence/display/' - if len(sys.argv) == 1: print("Please provide a list of project ids") sys.exit(1) +CWIKI='https://cwiki.apache.org/confluence/display/' JIRA='https://issues.apache.org/jira/rest/api/2/project' MYHOME = dirname(abspath(getsourcefile(lambda:0))) -projects = join((MYHOME), 'xdocs', 'projects') -stylesheets = join((MYHOME), 'xdocs', 'stylesheets') -flagged = join((MYHOME), 'xdocs', 'flagged') -cwiki_retired = join((MYHOME), 'cwiki_retired') +PROJECTS = join((MYHOME), 'xdocs', 'projects') +SYLESHEETS = join((MYHOME), 'xdocs', 'stylesheets') +FLAGGED = join((MYHOME), 'xdocs', 'flagged') +CWIKI_RETIRED = join((MYHOME), 'cwiki_retired') # get details of the retired projects -retirees = loadyaml('https://whimsy.apache.org/public/committee-retired.json')['retired'] +RETIREES = loadyaml('https://whimsy.apache.org/public/committee-retired.json')['retired'] lists = {} for host,names in loadyaml('https://lists.apache.org/api/preferences.lua')['lists'].items(): proj = host.replace('.apache.org','') - if proj in retirees: + if proj in RETIREES: lists[proj] = list(names.keys()) def list_jira(pid): @@ -69,16 +68,16 @@ def list_jira(pid): # updates xdocs/stylesheets/project.xml # <li><a href="/projects/abdera.html">Abdera</a></li> def update_stylesheet(pid): - xmlfile = join(stylesheets,'project.xml') - xmlfilet = join(stylesheets,'project.xml.t') + xmlfile = join(SYLESHEETS,'project.xml') + xmlfilet = join(SYLESHEETS,'project.xml.t') print("Updating %s" % xmlfile) found = False - with open(xmlfile,'r') as r, open(xmlfilet,'w') as w: + with open(xmlfile,'r', encoding='utf-8') as r, open(xmlfilet,'w', encoding='utf-8') as w: for l in r: if not found: m = re.search(r'^(\s+<li><a href="/projects/)([^.]+)(.html">)[^<]+(</a></li>)', l) if m: - stem = m.group(2) + stem = m.group(2) if stem == pid: print("Already present in projects.xml") print(l) @@ -87,7 +86,7 @@ def update_stylesheet(pid): return if stem > pid: # Found insertion point found = True - name = retirees[pid]['display_name'] + name = RETIREES[pid]['display_name'] w.write("%s%s%s%s%s\n" % (m.group(1), pid, m.group(3), name, m.group(4))) w.write(l) # write the original line if found: @@ -101,29 +100,29 @@ def update_stylesheet(pid): def create_jira_template(pid): outfile = join(MYHOME, "%s.jira.tmp" % pid) print("Creating %s" % outfile) - with open(join(MYHOME, '_template.jira'), 'r') as t: + with open(join(MYHOME, '_template.jira'), 'r', encoding='utf-8') as t: template = Template(t.read()) out = template.substitute(tlpid = pid) - with open(outfile, 'w') as o: + with open(outfile, 'w', encoding='utf-8') as o: o.write(out) - + # create the project.xml file from the template def create_project(pid): - outfile = join(projects, "%s.xml" % pid) + outfile = join(PROJECTS, "%s.xml" % pid) print("Creating %s" % outfile) - with open(join(projects, '_template.xml'), 'r') as t: + with open(join(PROJECTS, '_template.xml'), 'r', encoding='utf-8') as t: template = Template(t.read()) - meta = retirees[pid] + meta = RETIREES[pid] mnames = lists[pid] mnames.remove('dev') jiras = list_jira(pid) - out = template.substitute(tlpid = pid, + out = template.substitute(tlpid = pid, FullName = meta['display_name'], Month_Year = meta['retired'], mail_names = ",".join(sorted(mnames)), jira_names = ",".join(sorted(jiras)), description = meta.get('description', 'TBA')) - with open(outfile, 'w') as o: + with open(outfile, 'w', encoding='utf-8') as o: o.write(out) os.system("svn add %s" % outfile) print("Check XML file for customisations such as JIRA and mailing lists") @@ -131,30 +130,26 @@ def create_project(pid): def check_wiki(pid): url = CWIKI + pid.upper() if urlexists(url): - flagfile = join(cwiki_retired, f"{pid}.txt") - with open(flagfile, 'a'): + flagfile = join(CWIKI_RETIRED, f"{pid}.txt") + with open(flagfile, 'a', encoding='utf-8'): pass # if wiki uses alias, would need to add tlp name here os.system("svn add %s" % flagfile) - pass else: print(f"Could not find CWIKI entry at {url}, perhaps it uses an alias?") # TODO how to search cwiki for aliases? for arg in sys.argv[1:]: print("Processing "+arg) - if not arg in retirees: + if not arg in RETIREES: print("%s does not appear to be a retired project" % arg) continue - flagdir = join(flagged, arg) + flagdir = join(FLAGGED, arg) if os.path.exists(flagdir): print("flagged/%s already exists" % arg) continue create_jira_template(arg) - try: - os.mkdir(flagdir) - os.system("svn add %s" % flagdir) - create_project(arg) - update_stylesheet(arg) - check_wiki(arg) - except Exception as e: - print(e) + os.mkdir(flagdir) + os.system("svn add %s" % flagdir) + create_project(arg) + update_stylesheet(arg) + check_wiki(arg)