annotate Sphinx/source/plugins/python/storage-area.py @ 1018:868552e0caf8

python venv
author Alain Mazy <am@osimis.io>
date Thu, 25 Jan 2024 11:33:50 +0100
parents a296fe06fd86
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
748
a296fe06fd86 Implementing a custom storage area in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 import orthanc
a296fe06fd86 Implementing a custom storage area in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 import os
a296fe06fd86 Implementing a custom storage area in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3
a296fe06fd86 Implementing a custom storage area in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 def GetPath(uuid, contentType):
a296fe06fd86 Implementing a custom storage area in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 # Returns the path where to store the given attachment
a296fe06fd86 Implementing a custom storage area in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 return 'attachment-%d-%s' % (contentType, uuid)
a296fe06fd86 Implementing a custom storage area in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7
a296fe06fd86 Implementing a custom storage area in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 def OnCreate(uuid, contentType, data):
a296fe06fd86 Implementing a custom storage area in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 with open(GetPath(uuid, contentType), 'wb') as f:
a296fe06fd86 Implementing a custom storage area in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 f.write(data)
a296fe06fd86 Implementing a custom storage area in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11
a296fe06fd86 Implementing a custom storage area in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 def OnRead(uuid, contentType):
a296fe06fd86 Implementing a custom storage area in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 with open(GetPath(uuid, contentType), 'rb') as f:
a296fe06fd86 Implementing a custom storage area in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 return f.read()
a296fe06fd86 Implementing a custom storage area in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15
a296fe06fd86 Implementing a custom storage area in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 def OnRemove(uuid, contentType):
a296fe06fd86 Implementing a custom storage area in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 os.remove(GetPath(uuid, contentType))
a296fe06fd86 Implementing a custom storage area in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18
a296fe06fd86 Implementing a custom storage area in Python
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 orthanc.RegisterStorageArea(OnCreate, OnRead, OnRemove)