src/eric7/RemoteServer/EricServerFileSystemRequestHandler.py

branch
server
changeset 10596
ea35c92a3c7c
parent 10584
a596cf392291
child 10597
fbe93720ee9f
equal deleted inserted replaced
10594:6156d9675f62 10596:ea35c92a3c7c
36 "GetPathSep": self.__getPathSeparator, 36 "GetPathSep": self.__getPathSeparator,
37 "Chdir": self.__chdir, 37 "Chdir": self.__chdir,
38 "Getcwd": self.__getcwd, 38 "Getcwd": self.__getcwd,
39 "Listdir": self.__listdir, 39 "Listdir": self.__listdir,
40 "Mkdir": self.__mkdir, 40 "Mkdir": self.__mkdir,
41 "MakeDirs": self.__makedirs,
41 "Rmdir": self.__rmdir, 42 "Rmdir": self.__rmdir,
42 "Replace": self.__replace, 43 "Replace": self.__replace,
43 "Remove": self.__remove, 44 "Remove": self.__remove,
44 "Stat": self.__stat, 45 "Stat": self.__stat,
45 "Exists": self.__exists, 46 "Exists": self.__exists,
71 72
72 except KeyError: 73 except KeyError:
73 self.__server.sendJson( 74 self.__server.sendJson(
74 category=EricRequestCategory.FileSystem, 75 category=EricRequestCategory.FileSystem,
75 reply=request, 76 reply=request,
76 params={"Error": f"Request type '{request}' is not supported."}, 77 params={
78 "ok": False,
79 "error": f"Request type '{request}' is not supported.",
80 "info": list(self.__requestMethodMapping.keys()),
81 },
82 reqestUuid=reqestUuid,
77 ) 83 )
78 84
79 def __getPathSeparator(self, params): 85 def __getPathSeparator(self, params):
80 """ 86 """
81 Private method to report the path separator. 87 Private method to report the path separator.
94 @param params dictionary containing the request data 100 @param params dictionary containing the request data
95 @type dict 101 @type dict
96 @return dictionary containing the reply data 102 @return dictionary containing the reply data
97 @rtype dict 103 @rtype dict
98 """ 104 """
99 directory = params["directory"] 105 try:
100 try: 106 os.chdir(params["directory"])
101 os.chdir(directory)
102 return {"ok": True} 107 return {"ok": True}
103 except OSError as err: 108 except OSError as err:
104 return { 109 return {
105 "ok": False, 110 "ok": False,
106 "error": str(err), 111 "error": str(err),
168 @param params dictionary containing the request data 173 @param params dictionary containing the request data
169 @type dict 174 @type dict
170 @return dictionary containing the reply data 175 @return dictionary containing the reply data
171 @rtype dict 176 @rtype dict
172 """ 177 """
173 filename = params["filename"] 178 try:
174 statItems = params["st_names"] 179 result = os.stat(params["filename"])
175 180 resultDict = {st: getattr(result, st) for st in params["st_names"]}
176 try:
177 result = os.stat(filename)
178 resultDict = {st: getattr(result, st) for st in statItems}
179 return {"ok": True, "result": resultDict} 181 return {"ok": True, "result": resultDict}
180 except OSError as err: 182 except OSError as err:
181 return { 183 return {
182 "ok": False, 184 "ok": False,
183 "error": str(err), 185 "error": str(err),
222 @param params dictionary containing the request data 224 @param params dictionary containing the request data
223 @type dict 225 @type dict
224 @return dictionary containing the reply data 226 @return dictionary containing the reply data
225 @rtype dict 227 @rtype dict
226 """ 228 """
227 directory = params["directory"] 229 try:
228 230 os.mkdir(params["directory"])
229 try: 231 return {"ok": True}
230 os.makedirs(directory) 232 except OSError as err:
233 return {
234 "ok": False,
235 "error": str(err),
236 }
237
238 def __makedirs(self, params):
239 """
240 Private method to create a new directory.
241
242 @param params dictionary containing the request data
243 @type dict
244 @return dictionary containing the reply data
245 @rtype dict
246 """
247 try:
248 os.makedirs(params["directory"], exist_ok=params["exist_ok"])
231 return {"ok": True} 249 return {"ok": True}
232 except OSError as err: 250 except OSError as err:
233 return { 251 return {
234 "ok": False, 252 "ok": False,
235 "error": str(err), 253 "error": str(err),
242 @param params dictionary containing the request data 260 @param params dictionary containing the request data
243 @type dict 261 @type dict
244 @return dictionary containing the reply data 262 @return dictionary containing the reply data
245 @rtype dict 263 @rtype dict
246 """ 264 """
247 directory = params["directory"] 265 try:
248 266 os.rmdir(params["directory"])
249 try:
250 os.rmdir(directory)
251 return {"ok": True} 267 return {"ok": True}
252 except OSError as err: 268 except OSError as err:
253 return { 269 return {
254 "ok": False, 270 "ok": False,
255 "error": str(err), 271 "error": str(err),
263 @param params dictionary containing the request data 279 @param params dictionary containing the request data
264 @type dict 280 @type dict
265 @return dictionary containing the reply data 281 @return dictionary containing the reply data
266 @rtype dict 282 @rtype dict
267 """ 283 """
268 oldName = params["old_name"] 284 try:
269 newName = params["new_name"] 285 os.replace(params["old_name"], params["new_name"])
270
271 try:
272 os.replace(oldName, newName)
273 return {"ok": True} 286 return {"ok": True}
274 except OSError as err: 287 except OSError as err:
275 return { 288 return {
276 "ok": False, 289 "ok": False,
277 "error": str(err), 290 "error": str(err),
284 @param params dictionary containing the request data 297 @param params dictionary containing the request data
285 @type dict 298 @type dict
286 @return dictionary containing the reply data 299 @return dictionary containing the reply data
287 @rtype dict 300 @rtype dict
288 """ 301 """
289 filename = params["filename"] 302 try:
290 303 os.remove(params["filename"])
291 try:
292 os.remove(filename)
293 return {"ok": True} 304 return {"ok": True}
294 except OSError as err: 305 except OSError as err:
295 return { 306 return {
296 "ok": False, 307 "ok": False,
297 "error": str(err), 308 "error": str(err),

eric ide

mercurial