Skip to content
Snippets Groups Projects
Commit 5fd3ca55 authored by Mathieu Haefele's avatar Mathieu Haefele Committed by Fabrice Roy
Browse files

PYTHONPATH error handled

parent 88653d44
Branches dev-page-meso-roy
No related tags found
No related merge requests found
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
archive_evt.py takes as parameter the rst file of an event where the schedule directive is used for the event's program and replace the directive with program's content in rst.
Usage:
python3 archive_evt.py path/to/evt_to_archive.rst
"""
import sys
import os
import re
try:
import rst_directives as rd
except ImportError:
cwd = os.getcwd()
l = cwd.split("/")
print("You have to set up properly your PYTHONPATH:")
if "website" in l:
index = l.index("website")
print("export PYTHONPATH=$PYTHONPATH:%s/plugins"%("/".join(l[:index+1])))
else:
print("export PYTHONPATH=$PYTHONPATH:/path_to_website_repo/plugins")
sys.exit(1)
def fetch_line_schedule(evt_content):
schedule_pattern = re.compile("^([\s]*)\.\. schedule::")
for i, l in enumerate(evt_content):
res = schedule_pattern.search(l)
if res != None:
return i, len(res.group(1))
print("Error: no schedule directive in the file")
return -1, None
def fetch_indico_id(evt_content, l_sched):
indico_url_pattern = re.compile("[\s]*:indico_url: ([\W\w0-9/:\.]*)\n")
indico_event_pattern = re.compile("[\s]*:indico_event: ([0-9]*)")
indico_url = ""
indico_event = -1
item = l_sched+1
while (indico_url=="" or indico_event ==-1) and item < len(evt_content):
res = indico_url_pattern.search(evt_content[item])
if res != None:
indico_url=res.group(1)
res = indico_event_pattern.search(evt_content[item])
if res != None:
indico_event=int(res.group(1))
item += 1
return indico_url, indico_event, item
def indent_content(content, indent):
return "\n".join(
" "*indent + line for line in content.splitlines()
)
def gen_rst_evt_with_program(evt_orig):
f = open(evt_orig, "r")
evt_content = f.readlines()
f.close()
l_sched, content_indent = fetch_line_schedule(evt_content)
if l_sched < 0:
return ""
url, evt, last_line = fetch_indico_id(evt_content, l_sched)
if url=="" or evt < 0:
print("Error could not find indico_url or indico_event directives")
return ""
prog_to_insert = rd.get_indico_event_as_schedule(url, evt)
return "".join(evt_content[:l_sched+1]) + "\n" + indent_content(prog_to_insert, content_indent+4) + "".join(evt_content[last_line:])
def write(content_with_prog, evt_to_treat):
f = open(evt_to_treat, "w")
f.write(content_with_prog)
f.close()
if __name__ == "__main__":
if len(sys.argv) != 2:
print("""archive_evt.py takes as parameter the rst file of an event where the schedule directive is used for the event's program and replace the directive with program's content in rst.
Usage:
python3 %s path/to/evt_to_archive.rst"%(sys.argv[0])""")
sys.exit(1)
evt_to_treat = sys.argv[1]
content_with_prog = gen_rst_evt_with_program(evt_to_treat)
write(content_with_prog, evt_to_treat)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment