コード例 #1
0
ファイル: communication.py プロジェクト: fahdely/rectenv
def download_url_file(urlsrc,
                      fdest,
                      proxy_info=None,
                      response_transfer_progress=None):
    sredurl = None
    sp = _split_utl(urlsrc)
    #Richiesta al server
    sock = _connect_socket(sp["host"], sp["port"], proxy_info)
    try:
        req = Request("GET", sp["path"], {
            'Host': sp["host"] + ':' + str(sp["port"], ),
            'Connection': 'close'
        })
        sock.sendall(req.to_message())

        #Legge risposta
        if utils.path_exists(fdest):
            utils.path_remove(fdest)
        ftmp = fdest + "TMP"
        if utils.path_exists(ftmp):
            utils.path_remove(ftmp)
        resp = Response(sock, ftmp, response_transfer_progress)
        if resp.get_code() == '301':
            sredurl = resp.get_headers()["Location"]
        elif resp.get_code() != '200':
            raise Exception("Download error " + str(resp.get_code()) + ".")
    finally:
        sock.shutdown(1)
        sock.close()
    if sredurl is not None:
        download_url_file(sredurl, fdest, proxy_info,
                          response_transfer_progress)
    else:
        if utils.path_exists(ftmp):
            utils.path_move(ftmp, fdest)
コード例 #2
0
 def _cpmv(self, tp, fs, fd, replace):
     bok = True
     if utils.path_isdir(fs):
         if not utils.path_exists(fd):
             utils.path_makedirs(fd)
             if tp=="copy":
                 self._agent_main.get_osmodule().fix_file_permissions("COPY_DIRECTORY",fd, fs)
             elif tp=="move":
                 self._agent_main.get_osmodule().fix_file_permissions("MOVE_DIRECTORY",fd, fs)
         lst=None
         try:
             lst=utils.path_list(fs)
             for fname in lst:
                 b = self._cpmv(tp, fs + utils.path_sep + fname, fd + utils.path_sep + fname, replace)
                 if bok is True:
                     bok = b
         except Exception:
             bok=False
         if tp=="move":
             try:
                 utils.path_remove(fs)
             except Exception:
                 bok=False
     else:
         b=True
         if utils.path_exists(fd):
             if replace is True:
                 try:
                     utils.path_remove(fd)
                 except Exception:
                     bok = False
                     b = False
             else:
                 b = False
         if b is True:
             try:
                 if tp=="copy":
                     utils.path_copy(fs, fd)
                     self._agent_main.get_osmodule().fix_file_permissions("COPY_FILE",fd, fs)
                 elif tp=="move":
                     utils.path_move(fs, fd)
                     self._agent_main.get_osmodule().fix_file_permissions("MOVE_FILE",fd)
             except Exception:
                 bok=False
     return bok