Skip to content

Commit

Permalink
And support for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Frédéric Collonval committed Dec 4, 2020
1 parent a7fef8f commit 38c26b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ This is needed to build the link to broken notebook.
## Notes

- The service must be run as `root` because report processes are executed through `su <user> --login` command to
- On Unix platforms, the service must be run as `root` because report processes are executed through `su <user> --login` command to
impersonate the authenticated user and setting the environment variables afresh.

## Development
Expand Down
12 changes: 8 additions & 4 deletions papermill_report/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import json
import logging
import os
import pwd
import re
import stat
import sys
Expand All @@ -24,6 +23,11 @@

ANONYMOUS_USER = "anonymous_pm_report"

try:
import pwd
except ImportError: # None Unix
pwd = None

if os.environ.get("JUPYTERHUB_API_TOKEN"):
from jupyterhub.services.auth import HubOAuthenticated
else:
Expand Down Expand Up @@ -323,7 +327,7 @@ def _save_broken_report(self, notebook_path: Path, username: str) -> Path:
Returns:
The copied broken report path
"""
local_user = pwd.getpwnam(username) if username != ANONYMOUS_USER else None
local_user = pwd.getpwnam(username) if pwd is not None and username != ANONYMOUS_USER else None
prefix = datetime.strftime(datetime.now(), "%Y-%m-%d") + "_broken_"
broken_notebook = Path(self.broken_path) / (prefix + notebook_path.name)
if not broken_notebook.parent.exists():
Expand Down Expand Up @@ -439,7 +443,7 @@ async def get(self, template_path: str):
str(output_nb),
]
try:
if username != ANONYMOUS_USER:
if pwd is not None and username != ANONYMOUS_USER:
# Generate the report impersonating the authenticated user
await _execute_command(
["su", username, "-l", "-c", " ".join(command)], cwd=tmp_folder
Expand All @@ -466,7 +470,7 @@ async def get(self, template_path: str):
str(output_nb),
]

if username != ANONYMOUS_USER:
if pwd is not None and username != ANONYMOUS_USER:
await _execute_command(
["su", username, "-l", "-c", " ".join(command)], cwd=tmp_folder
)
Expand Down

0 comments on commit 38c26b5

Please sign in to comment.