Beispiel #1
0
 def run_lftp(self):
     nb_data = -1
     sync = SP.Popen(self.cmd,
                     env=self.my_env,
                     stdout=SP.PIPE,
                     stderr=SP.PIPE)
     (stdout, stderr) = sync.communicate()
     logger.debug("STDOUT")
     logger.debug("\n{}".format(stdout))
     logger.debug("END STDOUT")
     logger.debug("return code: {}".format(sync.returncode))
     if sync.returncode == 0:
         nb_data = self.is_data_tansfered(stdout)
         if (nb_data > 0):
             logger.info(u"{} bytes transfered to library".format(nb_data))
         elif nb_data == 0:
             logger.info(u"No new data transfered")
         else:
             _msg = "Invalid inyterpreatation of stdout \n:{}".format(
                 stdout)
             raise TdcpbException(_msg)
     elif sync.returncode:
         _msg = "FTP command failed returncode= {} ".format(sync.returncode)
         logger.error(_msg)
         logger.error(stderr)
         raise TdcpbException(_msg)
     return nb_data
 def connect(self, address, port, user, password):
     try:
         self.client = TClient(address, port, user, password)
     except TransmissionError as err:
         raise TdcpbException(" {} TransmissionError {}".format(
             address, err))
     except socket.timeout as err:
         raise TdcpbException(" {} Socket error {}".format(address, err))
     else:
         self.dict_client['name'] = address
Beispiel #3
0
def tdcpb_check(p_dcp_folder, p_check_type=u"short"):

    if (p_check_type == u"short"):
        tdcpb_check_short(p_dcp_folder)

    elif (p_check_type == u"long"):
        tdcpb_check_long(p_dcp_folder)
    else:
        _err = "unknow verfication type:{}".format(p_check_type)
        logger.error(_err)
        raise TdcpbException(_err)
Beispiel #4
0
def tdcpb_check_long(p_dcp_folder):
    logger.info("Hash Check started for {}"\
        .format(os.path.basename(p_dcp_folder)))
    # do some basic check
    if not os.path.exists(p_dcp_folder):
        _msg = "dcp directory {} does not exist"\
            .format(p_dcp_folder)
        raise TdcpbException(_msg)

    _dcp_folder = os.path.abspath(p_dcp_folder)
    try :
        DCP = T_PARSER.DiParser(_dcp_folder)
        _res = DCP.check_hash()
    except T_PARSER. DiError as _err:
        raise TdcpbException(_err)
    if _res is not 'OK':
        _err = "DCP hash verfication failed"
        raise TdcpbException(_err)
    logger.info("Hash OK for {}". \
            format(os.path.basename(p_dcp_folder)))
Beispiel #5
0
def tdcpb_check_short(p_dcp_folder):
    _dcp_folder = os.path.abspath(p_dcp_folder)
    logger.info('File check started for {}'\
        .format(os.path.basename(_dcp_folder)))
    # do some basic check
    if not os.path.exists(_dcp_folder):
        _msg = "dcp directory {} does not exist"\
            .format(_dcp_folder)
        raise TdcpbException(_msg)
    #TODO : why not use normpath ?
    try :
        DCP = T_PARSER.DiParser(_dcp_folder)
        _nb = DCP.check_files()
    except T_PARSER. DiError as _err:
        raise TdcpbException(_err)
    if _nb == 0:
        _err = "DCP {} not well formed "\
            .format(os.path.basename(_dcp_folder))
        raise TdcpbException(_err)
    logger.info('File check OK for {}'\
        .format(os.path.basename(_dcp_folder)))
Beispiel #6
0
    def __init__(self, p_dir_path, p_config_data, dry_run=False):
        self.config_data = p_config_data
        # TODO verfiy p_dir_path
        self.dir_path = p_dir_path
        if 'ftp-ssl' in self.config_data and self.config_data[
                'ftp-ssl'] == True:
            lftp_tpl = self.LFTP_SSL_CMDS
        else:
            lftp_tpl = self.LFTP_CMDS
        try:
            if self.config_data['ftp-remote-path'] is None:
                logger.error('No remote path specified')
                _msg = u"No remote path specified', please verify".format(
                    self.config_data['ftp-remote-path'])
                raise TdcpbException(_msg)
            if self.config_data['ftp-remote-path'] == "/":
                lftp_cmd = lftp_tpl.format(local=self.dir_path,
                                           remote='',
                                           dry_run='')
            else:
                if not (self.config_data['ftp-remote-path']).endswith("/"):
                    _msg = u"ftp-remote-path({}) shall ends with /, please verify".format(
                        self.config_data['ftp-remote-path'])
                    raise TdcpbException(_msg)
                lftp_cmd = lftp_tpl.format(
                    local=self.dir_path,
                    remote=self.config_data['ftp-remote-path'],
                    dry_run='')
            _ftp_connect = "ftp://{}:{}@{}".format(
                self.config_data['ftp-user'], self.config_data['ftp-pass'],
                self.config_data['ftp-host'])
            self.cmd = ["lftp", _ftp_connect, "-e", lftp_cmd]
            self.my_env = os.environ
            self.my_env["LC_ALL"] = "C"

            logger.debug("Cmd: {}".format(" ".join(self.cmd)))
        except KeyError as err:
            msg = "KEY ERROR for {}".format(err)
            logger.error(msg)
            raise TdcpbException(msg)
 def info(cls, p_torrent_path):
     if not os.path.exists(p_torrent_path):
         _err = "torrent path not exist: {}".format(p_torrent_path)
         raise TdcpbException(_err)
     _torrent_info = {}
     (_info, _metainfo) = cls._get_torrent_meta(p_torrent_path)
     _torrent_info['name'] = _info['name']
     _torrent_info['hash'] = cls._calc_hash(_info)
     _torrent_info['creation_date'] = datetime.fromtimestamp(
         _metainfo['creation date'])
     _size = 0
     for _f in _info['files']:
         _size = _size + int(_f['length'])
     _torrent_info['size'] = _size
     return _torrent_info
Beispiel #8
0
    def mirror(self):
        logger.info("Starting FTP copy of {}".format(
            os.path.basename(self.dir_path)))
        retry = False
        try:
            self.run_lftp()
        except TdcpbException as _err:
            retry = True
        else:
            logger.info("Copy of {} successfull".format(
                os.path.basename(self.dir_path)))

        if retry:
            logger.warning("Retrying mirror cmd via lftp")
            try:
                self.run_lftp()
            except TdcpbException as _err:
                logger.error("Copy of {} FAILED".format(
                    os.path.basename(self.dir_path)))
                raise TdcpbException(_err)
            else:
                logger.info("Copy of {} successfull".format(
                    os.path.basename(self.dir_path)))
 def __init__(self, p_torrent_path):
     if not os.path.exists(p_torrent_path):
         _err = "torrent path not exist: {}".format(p_torrent_path)
         raise TdcpbException(_err)