-
Notifications
You must be signed in to change notification settings - Fork 71
[SVCS-86] Add Papaya Renderer for Dicom and NifTi Files #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
fc577de
ba45d59
6937fee
0dbe5d5
eccfbd8
c834abf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .render import PapayaRenderer # noqa |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import os | ||
import shutil | ||
|
||
from mako.lookup import TemplateLookup | ||
|
||
from mfr.core import utils | ||
from mfr.core import extension | ||
from mfr.extensions import settings as ext_settings | ||
from mfr.extensions.papaya import settings as papaya_settings | ||
|
||
|
||
class PapayaRenderer(extension.BaseRenderer): | ||
|
||
data_dir = papaya_settings.DATA_DIR | ||
data_ttl = papaya_settings.DATA_TTL | ||
comp_ext = ext_settings.COMPRESSED_EXT | ||
|
||
TEMPLATE = TemplateLookup( | ||
directories=[ | ||
os.path.join(os.path.dirname(__file__), 'templates') | ||
]).get_template('viewer.mako') | ||
|
||
def render(self): | ||
self.remove_old_files() | ||
file_name = os.path.basename(self.file_path) | ||
file_ext = utils.get_full_file_ext(self.metadata.ext, self.metadata.name) | ||
file_name = file_name + file_ext | ||
shutil.copyfile(self.file_path, self.data_dir + file_name) | ||
return self.TEMPLATE.render(base=self.assets_url, file_name=file_name) | ||
|
||
def remove_old_files(self): | ||
|
||
for data_file in os.listdir(self.data_dir): | ||
if utils.file_expired(self.data_dir + data_file, self.data_ttl): | ||
os.unlink(self.data_dir + data_file) | ||
|
||
@property | ||
def file_required(self): | ||
return True | ||
|
||
@property | ||
def cache_result(self): | ||
return True |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from mfr import settings | ||
|
||
config = settings.child('PAPAYA_EXTENSION_CONFIG') | ||
|
||
# Directory to temporarily store papaya image files | ||
DATA_DIR = 'mfr/extensions/papaya/static/data/' | ||
# Files older then this many seconds will be deleted from DATA_DIR at the beginning of each render. | ||
DATA_TTL = 300 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Currently using a custom built papaya.js with option to remove the ability to open new files from the users desktop. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: Remove this file. PR was accepted and we are no longer using custom build. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 Nicely done! |
||
|
||
https://github.com/TomBaxter/Papaya/tree/feature/noNewFiles | ||
|
||
I have sent them a PR, hopefully they bite. | ||
|
||
https://github.com/rii-mango/Papaya/pull/101 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean the temporary files for rendering will get stuck here all the time? Each time users try to render a file, the old ones gets removed but new ones are created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is correct.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how much this will impact prod memory. MFR and WB pods constantly run out of space though. I will leave this for Phase 2 Review.