Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ Authors
=======

* Pranav Ballaney - https://github.com/ballaneypranav

* Wayne42 - https://github.com/Wayne42/
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

Changelog
=========
1.1.0-alpha4 (2021-10-20)
-------------------------
* fixed utf-8 errors (some special characters were printed wrong on uploaded pages)

1.1.0-alpha3 (2020-11-08)
-------------------------
Expand Down
59 changes: 22 additions & 37 deletions src/igem_wikisync/wikisync.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env python
# coding: utf8

import os
import shutil
import sys
Expand All @@ -21,8 +24,7 @@ def run(team: str,
src_dir: str,
build_dir: str,
year=date.today().year,
silence_warnings=False,
poster_mode=False):
silence_warnings=False):
'''
Runs iGEM-WikiSync and uploads all files to iGEM servers
while replacing relative URLs with those on the iGEM server.
Expand All @@ -35,10 +37,6 @@ def run(team: str,
Optional Arguments:
year: Subdomain for igem.org. Current year by default.
silence_warnings: Broken link warnings are not printed to console if true. The log still contains everything.
poster_mode: Run WikiSync in poster mode.
* Renames files to T--[TeamName]--Poster_[filename].extension
* Adds the poster template the HTML file
* Fails if any other HTML/CSS/JS file is provided

Returns:
1: Incorrect input in function call.
Expand Down Expand Up @@ -75,8 +73,7 @@ def run(team: str,
'src_dir': src_dir,
'build_dir': build_dir,
'year': str(year),
'silence_warnings': silence_warnings,
'poster_mode': poster_mode
'silence_warnings': silence_warnings
}

# * 2. Load or create upload_map
Expand All @@ -103,9 +100,9 @@ def run(team: str,
logger.critical(message)
sys.exit(2)

# # * 7. Save cookies
# # TODO: check if this works, might not
# cookiejar.save()
# * 7. Save cookies
# TODO: check if this works, might not
cookiejar.save()

# * 8. Cache files
files = cache_files(upload_map, config)
Expand Down Expand Up @@ -233,30 +230,18 @@ def cache_files(upload_map, config):
extension = infile.suffix[1:].lower()

# create appropriate file object
# file objects contain corresponding paths and
if extension in ['html', 'css', 'js']:

file_object = None
if extension == 'html':
file_object = HTMLfile(infile, config)

elif extension == 'css':
file_object = CSSfile(infile, config)

elif extension == 'js':
file_object = JSfile(infile, config)

# In poster mode, make sure URL starts with /Poster after team
if config['poster_mode']:
link_URL = file_object.link_URL
after_team = link_URL.split(config['team'])[1]
if len(after_team) < 7 or after_team[0:7] != "/Poster":
message = 'All files must start with /Poster in poster mode.'
logger.debug(message, exc_info=True)
logger.critical(message)
raise Exception

cache[extension][file_object.path] = file_object
# file objects contain corresponding paths and URLs
if extension == 'html':
file_object = HTMLfile(infile, config)
cache['html'][file_object.path] = file_object

elif extension == 'css':
file_object = CSSfile(infile, config)
cache['css'][file_object.path] = file_object

elif extension == 'js':
file_object = JSfile(infile, config)
cache['js'][file_object.path] = file_object

elif extension.lower() in ['png', 'gif', 'jpg', 'jpeg', 'pdf', 'ppt', 'txt',
'zip', 'mp3', 'mp4', 'webm', 'mov', 'swf', 'xls',
Expand Down Expand Up @@ -414,7 +399,7 @@ def build_and_upload(files, browser, config, upload_map):

# open file
try:
with open(file_object.src_path, 'r') as file:
with open(file_object.src_path, 'r', encoding='utf-8') as file:
contents = file.read()
except Exception:
message = f'Could not open/read {file_object.path}. Skipping.'
Expand Down Expand Up @@ -446,7 +431,7 @@ def build_and_upload(files, browser, config, upload_map):
if not os.path.isdir(build_path.parent):
os.makedirs(build_path.parent)
# and write the processed contents
with open(build_path, 'w') as file:
with open(build_path, 'w', encoding='utf-8') as file:
file.write(processed)
except Exception:
message = f"Couldn not write {str(file_object.build_path)}. Skipping."
Expand Down