Gitlab Community Edition Instance
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cdstar
pycdstar3
Commits
99100bb9
Commit
99100bb9
authored
Oct 26, 2019
by
Marcel Hellkamp
Browse files
Allow to put_file() by name/path. Also add type detection by default.
parent
60408e18
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/pycdstar3/api.py
View file @
99100bb9
...
@@ -280,11 +280,30 @@ class CDStar:
...
@@ -280,11 +280,30 @@ class CDStar:
else
:
else
:
break
break
def
put_file
(
self
,
vault
,
archive
,
name
,
source
,
type
=
None
)
->
JsonObject
:
def
put_file
(
self
,
vault
,
archive
,
name
,
source
,
type
=
None
,
replace
=
True
)
->
JsonObject
:
""" Create or replace a single file on an existing archive.
If the file exists remotely and `replace=True` is set (default), the file content is overridden but everything
else (metadata, type, file id) stays the same. If `replace` is `False` then a file name conflict is an error.
:param vault: Vault name
:param archive: Archive ID
:param name: Target file name. May start with `/` (optional) but must not end with `/`.
:param source: Readable file, byte buffer or iterator, or a file path that will then be opened in 'rb' mode.
:param type: Mime-type to set on the uploaded file. (default: guess based on filename)
:param replace: If the remote file already exists, replace its content. (default: True)
:return:
"""
if
isinstance
(
source
,
PATH_TYPES
):
if
isinstance
(
source
,
PATH_TYPES
):
raise
ValueError
(
"Source must be a file-like object, byte string or iterator yielding byte strings."
)
with
open
(
source
,
'rb'
)
as
source
:
return
self
.
rest
(
"PUT"
,
vault
,
archive
,
_fix_filename
(
name
),
data
=
source
,
return
self
.
put_file
(
vault
,
archive
,
name
,
source
,
type
=
None
,
replace
=
True
)
headers
=
{
'Content-Type'
:
type
or
"application/x-autodetect"
})
headers
=
{
'Content-Type'
:
type
or
"application/x-autodetect"
}
if
not
replace
:
headers
[
'If-None-Match'
]
=
"*"
return
self
.
rest
(
"PUT"
,
vault
,
archive
,
_fix_filename
(
name
),
data
=
source
,
headers
=
headers
)
def
get_file
(
self
,
vault
,
archive
,
name
,
offset
=
0
)
->
FileDownload
:
def
get_file
(
self
,
vault
,
archive
,
name
,
offset
=
0
)
->
FileDownload
:
""" Request a file and return a stream-able :class:`FileDownload`.
""" Request a file and return a stream-able :class:`FileDownload`.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment