コード例 #1
0
 def execute(self,aSql):
     """execute a sql request on the database"""
     
     sql = sqlalchemy.text(aSql)
     
     if self._activateTimer:
         result = []
         func = self._conn.execute
         t= ftimer(func,[sql],{},result,number=1)
         self._log.debug("\nTime: %s secs \nDatabase: %s\nRequest: %s\n"%(t,self._database,aSql))
         return result[0]
     else:
         result = self._conn.execute(sql)
         return result
コード例 #2
0
def get_list_messages_to_copy(a_script,a_hostname,a_origin_dir,a_local_dir,a_remote_user='******',a_result_file='result.msgs'):
    
    # make local dir if not done
    ctbto.common.utils.makedirs(a_local_dir)
            
    # path under which the file is going to be stored
    destinationPath = "%s/%s"%(a_local_dir,a_result_file)

    func = subprocess.call
      
    res   = []  
    
    print("run (using ssh): \"%s %s %s %s %s\n"%(a_script,a_hostname,a_origin_dir,destinationPath,a_remote_user,) )
              
    t = ftimer(func,[[a_script,a_hostname,a_origin_dir,destinationPath,a_remote_user]],{},res,number=1)
    
    print("\nCreated file: %s in %s secs \n /n"%(destinationPath,t))
    
    if res[0] != 0:
        raise Exception(-1,"Trying to fetch remote file (using ssh) with\"%s %s %s %s %s. Error code %s\n"%(a_script,a_hostname,a_origin_dir,destinationPath,a_remote_user,res[0]) )
    
    return open(destinationPath)
コード例 #3
0
ファイル: rndata.py プロジェクト: pombredanne/java-balivernes
    def _getRemoteFile(self):
        """ fetch the file and store it in a temporary location """

        # make local dir if not done
        ctbto.common.utils.makedirs(self._localDir)

        # path under which the file is going to be stored
        # It is the original filename_id
        # for the moment always assume that it is a spectrum
        destinationPath = "%s/%s" % (self._localDir, self._localFilename)

        # if file there and caching activated open fd and quit
        if os.path.exists(destinationPath) and self._cachingActivated:
            self._log.info("Fetch %s from the cache %s" % (self._remotePath, destinationPath))
            self._fd = open(destinationPath, "r")
        # check to see if the file is not available locally
        elif os.path.exists(self._remotePath) and self._cachingActivated:
            self._log.info("Fetch %s, offset %s, size %s" % (self._remotePath, self._remoteOffset, self._remoteSize))
            self._fd = self._get_file_locally_available_in_cache(
                self._remotePath, self._remoteOffset, self._remoteSize, destinationPath
            )
        else:
            # try to get it remotely
            # try 3 times before to fail
            tries = 1
            res = []

            while tries < 4:

                func = subprocess.call

                self._log.info(
                    'Trying to fetch remote file (using ssh) with"%s %s %s %s %s %s %s"'
                    % (
                        self._remoteScript,
                        self._remoteHostname,
                        self._remotePath,
                        str(self._remoteOffset),
                        str(self._remoteSize),
                        destinationPath,
                        self._remoteUser,
                    )
                )

                t = ftimer(
                    func,
                    [
                        [
                            self._remoteScript,
                            self._remoteHostname,
                            self._remotePath,
                            str(self._remoteOffset),
                            str(self._remoteSize),
                            destinationPath,
                            self._remoteUser,
                        ]
                    ],
                    {},
                    res,
                    number=1,
                )

                self._log.debug(
                    "\nTime: %s secs \n Fetch file: %s on host: %s\n" % (t, self._remotePath, self._remoteHostname)
                )

                if res[0] != 0:
                    if tries >= 3:
                        raise CTBTOError(
                            -1,
                            'Error when executing remotely script :"%s %s %s %s %s %s %s". First Error code = %d\n'
                            % (
                                self._remoteScript,
                                self._remoteHostname,
                                self._remotePath,
                                str(self._remoteOffset),
                                str(self._remoteSize),
                                destinationPath,
                                self._remoteUser,
                                res[0],
                            ),
                        )
                    else:
                        tries += 1
                else:
                    tries += 4

            self._fd = open(destinationPath, "r")