def remove(o): SQL = "SELECT * FROM deleteorder WHERE ordernumber = %s" data = (o, ) rows = sql.select(SQL, data) for row in rows: orderNumber = row[0] notice = row[1] status = row[2] directory = row[3] folder = os.path.join(directory, str(orderNumber)) print('Order {order} [{notice}] has the status {status}'.format( order=orderNumber, notice=notice, status=status)) question = 'Are you sure you want to delete this order at {d}?'.format( d=folder) decision = utilities.query_yes_no(question, default="yes") if decision == 'yes': utilities.deletefiles(folder) utilities.deletefolder(folder) if not os.path.exists(folder): sql.setOrderStatus(orderNumber, 'DELETED') elif decision == 'no': print('Nothing will be delete.') else: print('ERROR: {d} not a local folder.'.format(d=folder)) print('INFO: Are you on the right computer?') exit()
def process(): SQL = ("SELECT * FROM processmanifest") data = ('',) rows = sql.select(SQL, data) print('INFO: Processing Manifest for', len(rows), 'orders with the status MANIFEST') for row in rows: orderNumber = row[0] path = row[1] manifestfile = str(row[2]) if os.path.exists(os.path.join(path, str(orderNumber), manifestfile)): if manifest.loadxml(os.path.join(path, str(orderNumber), manifestfile), orderNumber) == 1: sql.setOrderStatus(str(orderNumber), 'READY') else: sql.setOrderStatus(str(orderNumber), 'ERROR') exit()
def download(u, p, o): manifestname = manifest.getName(u) if manifestname == '': print('ERROR: There seems to be no Manifest file for order {number}'.format(number=o)) sql.setOrderStatus(o, 'NOMANIFEST') else: u += manifestname p = os.path.join(p, manifestname) ftp.file(u, p) if os.path.exists(p): # also check file size here SQL = "UPDATE orders set manifest = %s WHERE ordernumber = %s" data = (manifestname, o) sql.update(SQL, data) sql.setOrderStatus(o, 'MANIFEST') else: print('ERROR: There is no Manifest for order {o}'.format(o=o))
def download(): SQL = "SELECT * FROM downloadimages" # all that are not finished data = ('', ) rows = sql.select(SQL, data) print('INFO: {d} images to download'.format(d=len(rows))) for row in rows: orderNumber = row[0] filename = row[1] destination = row[2] server = row[3] checksum = row[4] filesize = row[5] if not utilities.freespace(destination): print( 'ERROR: Not enough space on server the limit is {limit}GB'. format(limit=cfg_limit)) exit() # this will exit the whole program else: print('INFO: Still enough space, limit is {limit}GB'.format( limit=cfg_limit)) # actually downloading the file dest = os.path.join(destination, str(orderNumber), str(filename)) url = 'ftp://ftp.class.{s}.noaa.gov/{o}/001/{f}'.format( s=server, o=orderNumber, f=filename) ftpres = ftp.file(str(url), str(dest)) if ftpres is None: print('INFO: Download completed') else: print('INFO: Finished with Error {r}'.format(r=ftpres)) sql.setImageStatus(orderNumber, filename, 'ERROR') continue # continiue with next row if ( # check in the database if the checksum was given, if not, it is non-verified download (not checksum == '') and (image.checksumcheck(dest, checksum.replace('-', ''))) and (utilities.getFileSize(dest) == filesize)): print('INFO: Download size and md5 verified') sql.setImageStatus(orderNumber, filename, 'FINISHED') else: print('ERROR: Download of {d} has errors'.format(d=dest)) sql.setImageStatus(orderNumber, filename, 'ERROR') if sql.ordercomplete(orderNumber) is True: sql.setOrderStatus(orderNumber, 'FINISHED')
def main(argv): arg_parser = create_arg_parser() parsed_args = arg_parser.parse_args(sys.argv[1:]) mode = parsed_args.mode if mode == 'info': print('Allowed foldersize for {d} is {s} [GB]'.format(d=cfg_path, s=cfg_limit)) size = utilities.filesandfolders.getFolderSize(cfg_path) / (1024**3) if size < cfg_limit: print( 'Currently {:6.2f} [GB] are occupied, still {:6.2f} [GB] free.' .format(size, (cfg_limit - size))) else: print('Folder is full. You are {:6.2f} [GB] over the limit'.format( (size - cfg_limit))) elif mode == 'list': if (parsed_args.view == '') or (parsed_args.view == 'overview'): sql.printSQL("SELECT * FROM overview", '') elif (parsed_args.view == 'imagesummary'): sql.printSQL("SELECT * FROM imagesummary", '') elif (parsed_args.view == 'orders'): sql.printSQL("SELECT * FROM orders", '') elif (parsed_args.view == 'images'): sql.printSQL("SELECT * FROM images", '') else: print('Something went wrong') elif mode == 'addOrder': print('Add a new order') orderserver = zip(parsed_args.orderNumber, parsed_args.server) directory = checkInput.path(parsed_args.path) for i in orderserver: orderNumber = checkInput.orderNumber(i[0]) server = checkInput.server(i[1]) question = 'Order {o} from Server {s} will be added at {p}'.format( o=orderNumber, s=server, p=directory) answer = utilities.queries.query_yes_no(question) if answer == 'yes': try: downloadmanager.order.add(orderNumber, server, directory) except: print('There was an error, the order has not been added') else: print('Order will not be added.') exit() elif mode == 'getManifest': print('Get the manifest for NEW orders') SQL = "SELECT * FROM getmanifest" data = ('', ) rows = sql.select(SQL, data) for row in rows: orderNumber = str(row[0]) server = str(row[1]) path = str(row[2]) url = 'ftp://ftp.class.{s}.noaa.gov/{o}/'.format(s=server, o=orderNumber) destination = os.path.join(path, orderNumber) if not os.path.isdir(path): sql.setOrderStatus(orderNumber, 'CHECKPATH') print('This path does not exist on this server') continue else: if not os.path.isdir(destination): os.mkdir(os.path.expanduser(destination)) downloadmanager.manifest.download(url, destination, orderNumber) elif mode == 'processManifest': downloadmanager.manifest.process() elif mode == 'downloadImages': downloadmanager.image.download() elif mode == 'deleteOrder': orderNumber = checkInput.orderNumber(parsed_args.orderNumber) downloadmanager.order.remove(orderNumber) elif mode == 'generateFootprint': print('Do some processing') datadir = checkInput.datadir(parsed_args.datadir) workingdir = checkInput.workingdir(parsed_args.workingdir) proc.footprint.info() proc.footprint.generate(datadir, workingdir) exit()