[config]
base_path: C:\Users\Jakob\blackboard\math_course
+ auth_type: cookie
+
+Schema:
+
+ base_path: string
+ auth_type: string, "cookie" or "oauth"
"""
from getpass import getpass
return getpass("Blackboard password: ")
+ @staticmethod
+ def await_ack():
+ input("Press Enter to continue: ")
+
@contextmanager
def deleting(path):
cfg_section = cfg_parser['config']
with StorageManager(Path('auth_cache')) as storage_mgr:
- auth_handler = auth.CookieAuthHandler(
- storage_mgr,
- BB_ROOT,
- Cli,
- auth.StorageMgrCookieJar(storage_mgr),
- )
- api_iface = api.ApiInterface(BB_ROOT, auth_handler)
+ ui = Cli
+
+ auth_type = cfg_section['auth_type']
+ if auth_type == 'cookie':
+ auth_handler = auth.CookieAuthHandler(
+ storage_mgr,
+ BB_ROOT,
+ ui,
+ auth.StorageMgrCookieJar(storage_mgr),
+ )
+ api_iface = api.ApiInterface(BB_ROOT, auth_handler)
+ elif auth_type == 'oauth':
+ # TODO dependency loop
+ auth_handler = auth.OauthHandler(storage_mgr, None)
+ api_iface = api.ApiInterface(BB_ROOT, auth_handler)
+ auth_handler.api_iface = api_iface
+ else:
+ raise ValueError("Invalid auth_type in config")
url = input("Blackboard URL: ")
params = urllib.parse.parse_qs(urllib.parse.urlparse(url).query)
log('info', "Checking attachment {id}: \"{fileName}\"".format(**attachment_doc), indent = 1)
# On Windows, can't reopen the temp file while it's open.
- # This is needed by `filecmp', so we can't use `tempfile''s auto deletion.
+ # Reopen is needed by `filecmp', so we can't use `tempfile''s auto deletion.
with tempfile.NamedTemporaryFile(delete = False) as tmp:
tmp_path = Path(tmp.name)
with api_iface.download_attachment(course_id, child_doc['id'], att_id) as resp:
)
for path_str in sorted(map(str, result.paths)):
log('error', path_str, indent = 3)
+ ui.await_ack()
else:
raise AssertionError()