Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
kamaki
Commits
9c0b3e77
Commit
9c0b3e77
authored
Jul 31, 2013
by
Stavros Sachtouris
Browse files
Merge branch 'feature-detect-content-type' into develop
parents
cedde35d
e8be7922
Changes
4
Hide whitespace changes
Inline
Side-by-side
Changelog
View file @
9c0b3e77
...
...
@@ -40,4 +40,5 @@ Features:
- Expose the project API of astakosclient to kamaki CLI [#4155]
- Full support for compute v2 basic API [#4139]
- Use container:path format in register [#3778]
- Guess mimetype when uploading and use it in upload [#4196]
kamaki/cli/commands/pithos.py
View file @
9c0b3e77
...
...
@@ -40,7 +40,7 @@ from kamaki.cli.command_tree import CommandTree
from
kamaki.cli.errors
import
raiseCLIError
,
CLISyntaxError
,
CLIBaseUrlError
from
kamaki.cli.utils
import
(
format_size
,
to_bytes
,
print_dict
,
print_items
,
pretty_keys
,
pretty_dict
,
page_hold
,
bold
,
ask_user
,
get_path_size
,
print_json
)
page_hold
,
bold
,
ask_user
,
get_path_size
,
print_json
,
guess_mime_type
)
from
kamaki.cli.argument
import
FlagArgument
,
ValueArgument
,
IntArgument
from
kamaki.cli.argument
import
KeyValueArgument
,
DateArgument
from
kamaki.cli.argument
import
ProgressBarArgument
...
...
@@ -983,11 +983,12 @@ class file_manifest(_file_container_command, _optional_output_cmd):
@
errors
.
pithos
.
container
@
errors
.
pithos
.
object_path
def
_run
(
self
):
ctype
,
cenv
=
guess_mime_type
(
self
.
path
)
self
.
_optional_output
(
self
.
client
.
create_object_by_manifestation
(
self
.
path
,
content_encoding
=
self
[
'content_encoding'
],
content_encoding
=
self
[
'content_encoding'
]
or
cenc
,
content_disposition
=
self
[
'content_disposition'
],
content_type
=
self
[
'content_type'
],
content_type
=
self
[
'content_type'
],
or
ctype
,
sharing
=
self
[
'sharing'
],
public
=
self
[
'public'
]))
...
...
@@ -1135,6 +1136,10 @@ class file_upload(_file_container_command, _optional_output_cmd):
container_info_cache
=
dict
()
for
f
,
rpath
in
self
.
_path_pairs
(
local_path
,
remote_path
):
print
(
'%s --> %s:%s'
%
(
f
.
name
,
self
.
client
.
container
,
rpath
))
if
not
(
self
[
'content_type'
]
and
self
[
'content_encoding'
]):
ctype
,
cenc
=
guess_mime_type
(
f
.
name
)
params
[
'content_type'
]
=
self
[
'content_type'
]
or
ctype
params
[
'content_encoding'
]
=
self
[
'content_encoding'
]
or
cenc
if
self
[
'unchunked'
]:
r
=
self
.
client
.
upload_object_unchunked
(
rpath
,
f
,
...
...
kamaki/cli/utils.py
View file @
9c0b3e77
...
...
@@ -75,6 +75,20 @@ def suggest_missing(miss=None, exclude=[]):
print
(
''
)
def
guess_mime_type
(
filename
,
default_content_type
=
'application/octet-stream'
,
default_encoding
=
None
):
assert
filename
,
'Cannot guess mimetype for empty filename'
try
:
from
mimetypes
import
guess_type
ctype
,
cenc
=
guess_type
(
filename
)
return
ctype
or
default_content_type
,
cenc
or
default_encoding
except
ImportError
:
print
'WARNING: Cannot import mimetypes, using defaults'
return
(
default_content_type
,
default_encoding
)
def
remove_colors
():
global
bold
global
red
...
...
kamaki/clients/pithos/__init__.py
View file @
9c0b3e77
...
...
@@ -456,6 +456,7 @@ class PithosClient(PithosRestClient):
format
=
'json'
,
hashmap
=
True
,
content_type
=
content_type
,
content_encoding
=
content_encoding
,
if_etag_match
=
if_etag_match
,
if_etag_not_match
=
'*'
if
if_not_exist
else
None
,
etag
=
etag
,
...
...
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