Function: Recursive function to get everything under the remote location ftp_loc and transfer these to the local location local_loc for module module_id ftp_loc is the absolute location on the remove server however local_loc is the absolute location on the local machine where the fi
(ftp, ftp_loc, local_loc, module_id, config, ftp_pool)
| 53 | logger.error("[" + module_id + "] Failed to copy Error:" + str(sys.exc_info()[0]) + " " + str(sys.exc_info()[1])) |
| 54 | |
| 55 | def recur_get(ftp, ftp_loc, local_loc, module_id, config, ftp_pool): |
| 56 | """ Function: Recursive function to get everything under the remote location ftp_loc |
| 57 | and transfer these to the local location local_loc for module module_id |
| 58 | ftp_loc is the absolute location on the remove server however local_loc is the |
| 59 | absolute location on the local machine where the files/directories are to be created |
| 60 | """ |
| 61 | local_ftp_loc = ftp_loc |
| 62 | logger.debug( "Parameters for recur_get ftp_loc: " + local_ftp_loc ) |
| 63 | logger.debug( "Parameters for recur_get local_loc: " + local_loc ) |
| 64 | logger.debug( "FTP' CDing to location: " + local_ftp_loc ) |
| 65 | ftp.cwd("/") |
| 66 | ftp.cwd(local_ftp_loc) |
| 67 | for file in ftp.nlst(): |
| 68 | if file == "." or file == "..": |
| 69 | continue |
| 70 | try: |
| 71 | logger.debug( "current position is " + ftp.pwd()) |
| 72 | logger.debug( "Taking up position at " + local_ftp_loc) |
| 73 | ftp.cwd("/") |
| 74 | ftp.cwd(local_ftp_loc) |
| 75 | logger.debug("Try CDing to directory :" + file + "from" + local_ftp_loc) |
| 76 | ftp.cwd(file) |
| 77 | ftp.cwd('..') |
| 78 | # A rather weired method to see if a file or directory exists on the remote server |
| 79 | # Since unix and windows has different conventions for directory name, this is the only |
| 80 | # platform independent method I could think of, suggestions welcome |
| 81 | logger.debug( "Success, this is a directory: " + file ) |
| 82 | stage_location_tmp = os.path.join(local_loc, file) |
| 83 | logger.debug( "Creating a local folder : " + stage_location_tmp ) |
| 84 | try: |
| 85 | os.makedirs(stage_location_tmp) |
| 86 | except: |
| 87 | logger.debug( "Already Exists: " + file + " [" + str(sys.exc_info()[1])+ "]" ) |
| 88 | #The local_ftp_loc string is saved so that it does not get corrupted |
| 89 | #when the function gets into the recursive loop |
| 90 | str_for_ftp = local_ftp_loc |
| 91 | recur_get(ftp, str_for_ftp + "/" + file , os.path.join(local_loc, file), module_id, config, ftp_pool) |
| 92 | #original position of the ftp object is restored here |
| 93 | ftp.cwd("/") |
| 94 | ftp.cwd(local_ftp_loc) |
| 95 | except ftplib.error_perm : |
| 96 | logger.info( "File: " + file ) |
| 97 | logger.debug("[" + str(sys.exc_info()[1])+ "]") |
| 98 | localfile = os.path.join(local_loc, file) |
| 99 | try: |
| 100 | ftp_pool.asynchronous_ftp_get( local_ftp_loc + "/" + file,localfile) |
| 101 | except: |
| 102 | logger.error("Error reading from remote machine") |
| 103 | logger.error("Error:" + str(sys.exc_info()[0]) + " " + str(sys.exc_info()[1])) |
| 104 | raise |
| 105 | except: |
| 106 | logger.info( "Other error " + file + " " + " [" + str(sys.exc_info()[1])+ "]" ) |
| 107 | raise |
| 108 | |
| 109 | def get_build(module_id, config): |
| 110 | """ Function to get the module from the FTP Server |