Esempio n. 1
0
 def value(self, varname):
     # return ERROR, VALUE, QUALITY
     if varname in self.lst:
         return False, self.var[varname].value(), self.var[varname].good()
     else:
         LOG.error("%s doesn't exist in vardb" % varname)
         return True, 0, 0
Esempio n. 2
0
    def backupuploadedfiles(self):
        if self.count > 0:
            new_list = []
            for tup in self.list:
                try:
                    os.system("mv %s %s" %
                              (tup['ufname'], tup['ufname'].replace(
                                  SETTINGS.UPATH, SETTINGS.UEDPATH)))
                    size = 0
                    while True:
                        size = getarchivesize(SETTINGS.UEDPATH)
                        if size > SETTINGS.MAX_SIZE:
                            oldest = str(oldestfile(SETTINGS.UEDPATH)[0])
                            os.remove("%s" % oldest)
                            LOG.info("%s deleted" % oldest)
                        else:
                            break
                    LOG.info("%s size = %s" % (SETTINGS.UEDPATH, size))
                    LOG.info("-" * GLOBAL.NCHAR)

                except OSError, e:
                    LOG.error("%s" % str(e))
                    new_list.append(tup)

            self.list = list(new_list)
            self.count = len(self.list)
Esempio n. 3
0
    def getallfiles_MLSD(self, lsrv, ut):
        LOG.info("-" * GLOBAL.NCHAR)
        # files_all = FilesManager()
        for lsrv in lsrv:
            arr = lsrv.split(';')
            dev = DevManager.DevManager(arr[3].strip(),
                                        arr[4].strip(),
                                        arr[0].strip(),
                                        ut,
                                        setMLSD=True)
            ftp = FtpManager.FtpManager(arr[0].strip(), arr[1].strip(),
                                        arr[2].strip())
            # ftp.error.resetall()

            files = FilesManager()
            lst = ftp.getnewfileslist(dev)

            if ftp.error.exit != 0:
                files.addfilesfromlist_MLSD(lst, dev)
                if files.count > 0:
                    ftp = getftp_MLSD(ftp, files)
                    self.extendlist(files.list)
                ftp.error.resetall()
            else:
                LOG.error("ERROR getting the list of files ::: Device=%s" %
                          dev.name)
        LOG.info("-" * GLOBAL.NCHAR)
Esempio n. 4
0
def formatShot(shot, vars_shot):
    if len(shot) != len(vars_shot):
        LOG.error("Variables and register does not match!")
        return shot
    shot_dict = {}
    #Accedo a cada variable del shot
    #shot=zip(vars_shot,shot)
    for i, vars in enumerate(shot):
        #shot[i] = {vars_shot[i]:vars}
        key = str(vars_shot[i])
        shot_dict[key] = vars
    return shot_dict
Esempio n. 5
0
 def putallfiles(self, rsrv):
     LOG.info("-" * GLOBAL.NCHAR)
     srv = rsrv.split(';')
     rpath = srv[3].strip()
     ftp = FtpManager.FtpManager(srv[0].strip(), srv[1].strip(),
                                 srv[2].strip())
     # ftp.error.resetall()
     if self.count > 0:
         # ftp, lst = putftp(ftp, self, rpath)
         self.list = ftp.putftp(self, rpath).list
         self.count = len(self.list)
         if ftp.error.exit != 1:
             LOG.error("ERROR uploading files")
     else:
         LOG.info("There are no files to upload")
         LOG.info("-" * GLOBAL.NCHAR)
Esempio n. 6
0
    def printerror(self, ref):
        s = 0
        n = 0
        if ref == "FTP":
            n = self.error.nerr_ftp
            s = 1
        elif ref == "SOCKET":
            n = self.error.nerr_soc
            s = 2
        elif ref == "GENERAL":
            n = 1000
            s = 0
        elif ref == "FTP.CLOSE":
            n = 1000
            s = 0

        self.error.exit = 0
        if (n > SETTINGS.MAX_RETRIES) and (str(self.error.e) !=
                                           self.error.msg):
            self.error.msg = str(self.error.e)
            LOG.error("%s ERROR: %s" % (ref, str(self.error.e)))
            self.error.exit = -1
        if n >= 1000:
            self.error.msg = ""
            self.error.exit = -1

        if ref == "FTP":
            self.error.nerr_ftp += 1
            self.error.exit = -1
        elif ref == "SOCKET":
            self.error.nerr_soc += 1
            self.error.exit = -1
        elif ref == "GENERAL":
            self.error.nerr_gen = 1000
            self.error.exit = -1
        elif ref == "FTP.CLOSE":
            self.error.nerr_cls = 1000
            self.error.exit = -1
        else:
            LOG.info("FTP error no managed")
            self.error.nerr_cls = 1000
            self.error.exit = -1

        LOG.error("%s ERROR: %s" % (ref, str(self.error.e)))
        time.sleep(s)
Esempio n. 7
0
    def getlistfromfile(self):
        try:

            dev_mod_file = "%s/%s" % (SETTINGS.MOD_PATH,
                                      SETTINGS.MODIFICATION_FILE_LOCAL + "_" +
                                      self.name)
            dev_data = []
            infile = open(
                "%s/%s" % (SETTINGS.MOD_PATH,
                           SETTINGS.MODIFICATION_FILE_LOCAL + "_" + self.name),
                'r')
            for line in infile:
                dev_data.append(line)
            # Cerramos el fichero.
            infile.close()
        except IOError as (errno, strerror):
            LOG.error("I/O error with modification file %s --> %s %s " %
                      (dev_mod_file, errno, strerror))
            pass
Esempio n. 8
0
def printerror(ref, ftp):
    s = 0
    n = 0
    if ref == "FTP":
        n = ftp.error.nerr_ftp
        s = 1
    elif ref == "SOCKET":
        n = ftp.error.nerr_soc
        s = 2
    elif ref == "GENERAL":
        n = 1000
        s = 0
    elif ref == "FTP.CLOSE":
        n = 1000
        s = 0

    ftp.error.exit = 0
    if (n > SETTINGS.MAX_RETRIES) and (str(ftp.error.e) != ftp.error.msg):
        ftp.error.msg = str(ftp.error.e)
        LOG.error("%s ERROR: %s" % (ref, str(ftp.error.e)))
        ftp.error.exit = -1
    if n >= 1000:
        ftp.error.msg = ""
        ftp.error.exit = -1

    if ref == "FTP":
        ftp.error.nerr_ftp += 1
        ftp.error.exit = -1
    elif ref == "SOCKET":
        ftp.error.nerr_soc += 1
        ftp.error.exit = -1
    elif ref == "GENERAL":
        ftp.error.nerr_gen = 1000
        ftp.error.exit = -1
    elif ref == "FTP.CLOSE":
        ftp.error.nerr_cls = 1000
        ftp.error.exit = -1

    LOG.error("%s ERROR: %s" % (ref, str(ftp.error.e)))
    time.sleep(s)
    return ftp
Esempio n. 9
0
def getallfiles(lsrv, ut):
    LOG.info("-" * GLOBAL.NCHAR)
    files_all = FilesManager()
    for lsrv in lsrv:
        arr = lsrv.split(';')
        dev = DevManager.DevManager(arr[3].strip(), arr[4].strip(),
                                    arr[0].strip(), ut)
        ftp = FtpManager.FtpManager(arr[0].strip(), arr[1].strip(),
                                    arr[2].strip())
        ftp.error.resetall()
        files = FilesManager.FilesManager()
        (ftp, lst) = getnewfileslist(ftp, dev)

        if ftp.error.exit != 0:
            files.addfilesfromlist(lst, dev)
            if files.count > 0:
                ftp = getftp(ftp, files)
                files_all.extendlist(files.list)
            ftp.error.resetall()
        else:
            LOG.error("ERROR getting the list of files ::: Device=%s" %
                      dev.name)
    LOG.info("-" * GLOBAL.NCHAR)
    return files_all
Esempio n. 10
0
        return last

    def getlistfromfile(self):
        try:

            dev_mod_file = "%s/%s" % (SETTINGS.MOD_PATH,
                                      SETTINGS.MODIFICATION_FILE_LOCAL + "_" +
                                      self.name)
            dev_data = []
            infile = open(
                "%s/%s" % (SETTINGS.MOD_PATH,
                           SETTINGS.MODIFICATION_FILE_LOCAL + "_" + self.name),
                'r')
            for line in infile:
                dev_data.append(line)
            # Cerramos el fichero.
            infile.close()
        except IOError as (errno, strerror):
            LOG.error("I/O error with modification file %s --> %s %s " %
                      (dev_mod_file, errno, strerror))
            pass
        except:
            LOG.error("ERROR getting data from local MODIFICATION file: %s" %
                      dev_mod_file)
            LOG.error("The content of data is: %s" % dev_data)
            error = sys.exc_info()[0]
            LOG.error("The error is %s" % error)
            dev_data = []
            pass
        return dev_data