66import json
77import logging
88import requests
9-
9+ import posixpath
1010from pyclowder .client import ClowderClient
1111
1212
@@ -27,26 +27,26 @@ def create_empty(connector, host, key, collectionname, description, parentid=Non
2727
2828 if parentid :
2929 if spaceid :
30- url = '%sapi /collections/newCollectionWithParent?key=%s' % ( host , key )
30+ url = posixpath . join ( host , 'api /collections/newCollectionWithParent?key=%s' % key )
3131 result = requests .post (url , headers = {"Content-Type" : "application/json" },
3232 data = json .dumps ({"name" : collectionname , "description" : description ,
3333 "parentId" : [parentid ], "space" : spaceid }),
3434 verify = connector .ssl_verify if connector else True )
3535 else :
36- url = '%sapi /collections/newCollectionWithParent?key=%s' % ( host , key )
36+ url = posixpath . join ( host , 'api /collections/newCollectionWithParent?key=%s' % key )
3737 result = requests .post (url , headers = {"Content-Type" : "application/json" },
3838 data = json .dumps ({"name" : collectionname , "description" : description ,
3939 "parentId" : [parentid ]}),
4040 verify = connector .ssl_verify if connector else True )
4141 else :
4242 if spaceid :
43- url = '%sapi /collections?key=%s' % ( host , key )
43+ url = posixpath . join ( host , 'api /collections?key=%s' % key )
4444 result = requests .post (url , headers = {"Content-Type" : "application/json" },
4545 data = json .dumps ({"name" : collectionname , "description" : description ,
4646 "space" : spaceid }),
4747 verify = connector .ssl_verify if connector else True )
4848 else :
49- url = '%sapi /collections?key=%s' % ( host , key )
49+ url = posixpath . join ( host , 'api /collections?key=%s' % key )
5050 result = requests .post (url , headers = {"Content-Type" : "application/json" },
5151 data = json .dumps ({"name" : collectionname , "description" : description }),
5252 verify = connector .ssl_verify if connector else True )
@@ -59,7 +59,7 @@ def create_empty(connector, host, key, collectionname, description, parentid=Non
5959
6060
6161def delete (connector , host , key , collectionid ):
62- url = "%sapi /collections/%s?key=%s" % (host , collectionid , key )
62+ url = posixpath . join ( host , "api /collections/%s?key=%s" % (collectionid , key ) )
6363
6464 result = requests .delete (url , verify = connector .ssl_verify if connector else True )
6565 result .raise_for_status ()
@@ -77,7 +77,7 @@ def get_child_collections(connector, host, key, collectionid):
7777 collectionid -- the collection to get children of
7878 """
7979
80- url = "%sapi /collections/%s/getChildCollections?key=%s" % (host , collectionid , key )
80+ url = posixpath . join ( host , "api /collections/%s/getChildCollections?key=%s" % (collectionid , key ) )
8181
8282 result = requests .get (url ,
8383 verify = connector .ssl_verify if connector else True )
@@ -96,7 +96,7 @@ def get_datasets(connector, host, key, collectionid):
9696 datasetid -- the collection to get datasets of
9797 """
9898
99- url = "%sapi /collections/%s/datasets?key=%s" % (host , collectionid , key )
99+ url = posixpath . join ( host , "api /collections/%s/datasets?key=%s" % (host , collectionid , key )
100100
101101 result = requests .get (url ,
102102 verify = connector .ssl_verify if connector else True )
@@ -126,7 +126,7 @@ def upload_preview(connector, host, key, collectionid, previewfile, previewmetad
126126 headers = {'Content - Type ': ' application / json '}
127127
128128 # upload preview
129- url = '%sapi /previews?key=%s' % ( host , key )
129+ url = posixpath . join ( host , 'api /previews?key=%s' % key )
130130 with open (previewfile , 'rb' ) as filebytes :
131131 result = requests .post (url , files = {"File" : filebytes },
132132 verify = connector .ssl_verify if connector else True )
@@ -136,14 +136,14 @@ def upload_preview(connector, host, key, collectionid, previewfile, previewmetad
136136
137137 # associate uploaded preview with original collection
138138 if collectionid and not (previewmetadata and 'section_id' in previewmetadata and previewmetadata ['section_id' ]):
139- url = '%sapi /collections/%s/previews/%s?key=%s' % (host , collectionid , previewid , key )
139+ url = posixpath . join ( host , 'api /collections/%s/previews/%s?key=%s' % (collectionid , previewid , key ) )
140140 result = requests .post (url , headers = headers , data = json .dumps ({}),
141141 verify = connector .ssl_verify if connector else True )
142142 result .raise_for_status ()
143143
144144 # associate metadata with preview
145145 if previewmetadata is not None :
146- url = '%sapi /previews/%s/metadata?key=%s' % (host , previewid , key )
146+ url = posixpath . join ( host , 'api /previews/%s/metadata?key=%s' % (previewid , key ) )
147147 result = requests .post (url , headers = headers , data = json .dumps (previewmetadata ),
148148 verify = connector .ssl_verify if connector else True )
149149 result .raise_for_status ()
0 commit comments