Passing local file path to remote add-item?
|
barnacle
Joined: 2009-03-10
Posts: 4 |
Posted: Tue, 2009-03-10 10:03
|
|
Hi, I'm trying to get a Python script working that will go through a set of directories on a regular basis and check for new files and then add them to gallery2. I found a prewritten package for the remote protocol which works great for queries, however I can't seem to get the add_item function to work. link to file: http://pypi.python.org/pypi/GalleryRemote/ This is the add_item function included...
def add_item(self, album, filename, caption, description):
"""
Add a photo to the specified album.
album - album name / identifier
filename - image to upload
caption - string caption to add to the image
description - string description to add to the image
"""
if self.version == 1:
request = {
'protocol_version' : self.protocol_version,
'cmd' : 'add-item',
'set_albumName' : album,
'userfile' : file,
'userfile_name' : filename,
'caption' : caption,
'extrafield.Description' : description
}
else:
request = {
'g2_controller' : 'remote:GalleryRemote',
'g2_form[protocol_version]' : self.protocol_version,
'g2_form[cmd]' : 'add-item',
'g2_form[set_albumName]' : album,
'g2_form[userfile]' : file,
'g2_form[userfile_name]' : filename,
'g2_form[caption]' : caption,
'g2_form[extrafield.Description]' : description
}
file = open(filename)
response = self._do_request(request)
# if we get here, everything went ok.
I'm not sure this function was ever tested as: 1) The use of file before assignment throws an error. 2) Judging from the remote protocol documentation the feilds for g2_form[userfile] and g2_form[userfile_name] should be g2_userfile and g2_userfile_name. I tried changing it to this...
def add_item(self, album, filename, caption, description):
"""
Add a photo to the specified album.
album - album name / identifier
filename - image to upload
caption - string caption to add to the image
description - string description to add to the image
"""
if self.version == 1:
request = {
'protocol_version' : self.protocol_version,
'cmd' : 'add-item',
'set_albumName' : album,
'userfile' : file,
'userfile_name' : filename,
'caption' : caption,
'extrafield.Description' : description
}
else:
request = {
'g2_controller' : 'remote:GalleryRemote',
'g2_form[protocol_version]' : self.protocol_version,
'g2_form[cmd]' : 'add-item',
'g2_form[set_albumName]' : album,
'g2_userfile' : filename,
'g2_userfile_name' : filename,
'g2_form[force_filename]' : 'yes',
'g2_form[caption]' : caption,
'g2_form[extrafield.Description]' : description
}
#file = open(filename)
response = self._do_request(request)
# if we get here, everything went ok.
Now it actually gets through to the gallery2 server but it's giving me a "Filename not specified" error. Right now my filename is set to '/usr/home/USERNAME_EDITED/images/wood_grain.png'. Any pointers for getting this to work? Thanks, |
|

Posts: 4
Any ideas? Perhaps I did a poor job of explaining?
I've tried using a web link as well 'http://www.surplusandoutdoors.com/images/product/main/ROPE-9MM-ACC258.jpg' for the filename and it still doesn't work...
I get the feeling that I'm missing something like an escape sequence or something else somewhat trivial. Are there characters in the file path that need escape sequences?
Posts: 4
I found a python script that actually works, not sure why I didn't see the link to it earlier...
http://codex.gallery2.org/Other_Clients#GUP
Now, if there was a way to get it to support symlinks it would be perfect.
Does anyone know if the remote protocol has the ability to support symlinks?