26 from PyQt4
import QtCore, QtGui, QtNetwork
32 gui.RemoteSiteLoader.__init__(self)
38 self.
ById(id, selection)
40 def ById(self, ids, selection=""):
41 for id
in re.findall(
'\w+', ids):
42 file_name=self.GetFileName(id)
43 file = QtCore.QFile(file_name)
45 url = QtCore.QUrl(self.
GetUrl(id))
46 request = QtNetwork.QNetworkRequest(url)
47 reply = self.networkmanager_.get(request)
50 gui.FileLoader.LoadObject(str(file_name),str(selection))
69 file_name=self.GetFileName(self.downloads_[reply][0])
70 file = QtCore.QFile(file_name)
71 if(reply.error()!=QtNetwork.QNetworkReply.NoError
or reply.bytesAvailable()==0):
72 self.HandleError(reply.errorString());
75 if(self.downloads_.has_key(reply)):
76 if(file.open(QtCore.QIODevice.WriteOnly)):
77 file.write(reply.readAll());
79 selection=self.downloads_[reply][1]
80 del(self.downloads_[reply])
81 gui.FileLoader.LoadObject(str(file_name),str(selection))
84 EXT_NAME_ATTRIBUTE_NAME =
"ExtName"
85 URL_ATTRIBUTE_NAME =
"Url"
86 UP_CASE_ATTRIBUTE_NAME =
"UpCase"
87 FILE_TYPE_ATTRIBUTE_NAME =
"FileType"
88 TMP_URL_ATTRIBUTE_NAME=
"TmpUrl"
89 IMG_ATTRIBUTE_NAME=
"Img"
90 DEFAULT_ATTRIBUTE_NAME=
"Default"
91 def __init__(self, name, url, up_case, file_type, tmp_url=None, img=False, default=False):
92 BaseRemoteLoader.__init__(self)
93 self.
name_ = QtCore.QString(name)
94 self.
url_ = QtCore.QString(url)
98 if file_type
is not None:
103 if tmp_url
is not None:
120 formatted_id = QtCore.QString(id).toUpper()
121 url = QtCore.QString(self.
url_)
122 url.replace(
"${ID}",formatted_id)
128 formatted_id = QtCore.QString(id).toUpper()
132 url = self.
tmp_url_ + QtCore.QDir.separator()
134 url = QtCore.QDir.tempPath() + QtCore.QDir.separator()
138 remote_url = QtCore.QString(self.
GetUrl(id))
139 index = remote_url.lastIndexOf(
".")
141 file_type = remote_url.right(remote_url.size()-index-1)
142 if file_type
is None:
144 if len(self.
name_)>0:
145 return url+formatted_id +
"_"+self.
name_+
"."+file_type
147 return url+formatted_id+
"."+file_type
150 ost.LogError(str(
"Could not download file\n"+message+
""))
153 group.SetAttribute(GenericLoader.EXT_NAME_ATTRIBUTE_NAME, str(self.
name_))
154 group.SetAttribute(GenericLoader.URL_ATTRIBUTE_NAME, str(self.
url_))
156 group.SetAttribute(GenericLoader.UP_CASE_ATTRIBUTE_NAME, str(self.
up_case_))
158 group.SetAttribute(GenericLoader.FILE_TYPE_ATTRIBUTE_NAME, str(self.
file_type_))
160 group.SetAttribute(GenericLoader.TMP_URL_ATTRIBUTE_NAME, str(self.
tmp_url_))
161 if self.
img_ is not None:
162 group.SetAttribute(GenericLoader.IMG_ATTRIBUTE_NAME, str(int(self.
img_)))
164 group.SetAttribute(GenericLoader.DEFAULT_ATTRIBUTE_NAME, str(int(self.
default_)))
176 if group.HasAttribute(GenericLoader.EXT_NAME_ATTRIBUTE_NAME):
177 name = QtCore.QString(group.GetAttribute(GenericLoader.EXT_NAME_ATTRIBUTE_NAME))
179 if group.HasAttribute(GenericLoader.URL_ATTRIBUTE_NAME):
180 url = QtCore.QString(group.GetAttribute(GenericLoader.URL_ATTRIBUTE_NAME))
182 if group.HasAttribute(GenericLoader.UP_CASE_ATTRIBUTE_NAME):
183 up_case = bool(group.GetAttribute(GenericLoader.UP_CASE_ATTRIBUTE_NAME))
185 if group.HasAttribute(GenericLoader.FILE_TYPE_ATTRIBUTE_NAME):
186 file_type = QtCore.QString(group.GetAttribute(GenericLoader.FILE_TYPE_ATTRIBUTE_NAME))
188 if group.HasAttribute(GenericLoader.TMP_URL_ATTRIBUTE_NAME):
189 tmp_url = QtCore.QString(group.GetAttribute(GenericLoader.TMP_URL_ATTRIBUTE_NAME))
191 if group.HasAttribute(GenericLoader.IMG_ATTRIBUTE_NAME):
192 img = bool(int(group.GetAttribute(GenericLoader.IMG_ATTRIBUTE_NAME)))
194 if group.HasAttribute(GenericLoader.DEFAULT_ATTRIBUTE_NAME):
195 default = bool(int(group.GetAttribute(GenericLoader.DEFAULT_ATTRIBUTE_NAME)))
197 return GenericLoader(name, url, up_case, file_type, tmp_url, img, default)