Пример #1
0
def download_http(fqdn, folder, destiny, filename):

    try:

        if not os.path.exists(destiny):
            os.makedirs(destiny)
            tqdm.write('   -- Creating dir ' + destiny)

        # rinex = urllib.URLopener()
        tqdm.write('   -- %s%s ' % (fqdn, os.path.join(folder, filename)))
        # rinex.retrieve("http://%s%s" % (fqdn, os.path.join(folder, filename)), os.path.join(destiny, filename))
        p = subprocess.Popen(
            'wget -O %s http://%s%s || rm -f %s' %
            (os.path.join(destiny, filename), fqdn,
             os.path.join(folder, filename), os.path.join(destiny, filename)),
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)

        stdout, stderr = p.communicate()
        if stdout:
            tqdm.write(indent(stdout, 6))
        if stderr:
            tqdm.write(indent(stderr, 6))

    except Exception as e:
        # folder not present, skip
        tqdm.write('   -- http error: ' + str(e))
        return False

    if os.path.isfile(os.path.join(destiny, filename)):
        return True
    else:
        return False
Пример #2
0
def gamit_callback(job):

    result = job.result

    if result is not None:
        msg = []
        if 'error' not in result.keys():
            if result['nrms'] > 1:
                msg.append('    > NRMS > 1.0 (%.3f)' % result['nrms'])

            if result['wl'] < 60:
                msg.append('    > WL fixed < 60 (%.1f)' % result['wl'])

            if result['missing']:
                msg.append('    > Missing sites in solution: ' +
                           ', '.join(result['missing']))

            # DDG: only show sessions with problems to facilitate debugging.
            if result['success']:
                if len(msg) > 0:
                    tqdm.write(
                        ' -- %s Done processing: %s -> WARNINGS:\n%s' %
                        (print_datetime(), result['session'], '\n'.join(msg)))

                # insert information in gamit_stats
                try:
                    cnn = dbConnection.Cnn(
                        'gnss_data.cfg')  # type: dbConnection.Cnn
                    cnn.insert('gamit_stats', result)
                    cnn.close()
                except dbConnection.dbErrInsert as e:
                    tqdm.write(
                        ' -- %s Error while inserting GAMIT stat for %s: ' %
                        (print_datetime(), result['session'] + ' ' + str(e)))

            else:
                tqdm.write(' -- %s Done processing: %s -> FATAL:\n'
                           '    > Failed to complete. Check monitor.log:\n%s' %
                           (print_datetime(), result['session'],
                            indent('\n'.join(result['fatals']), 4)))
                # write FATAL to file
                f = open('FATAL.log', 'a')
                f.write(
                    'ON %s session %s -> FATAL: Failed to complete. Check monitor.log\n%s\n'
                    % (print_datetime(), result['session'],
                       indent('\n'.join(result['fatals']), 4)))
                f.close()
        else:
            tqdm.write(
                ' -- %s Error in session %s message from node follows -> \n%s'
                % (print_datetime(), result['session'], result['error']))

    else:
        tqdm.write(
            ' -- %s Fatal error on node %s message from node follows -> \n%s' %
            (print_datetime(), job.ip_addr, job.exception))
Пример #3
0
def download_ftp(fqdn, username, password, folder, destiny, filename):

    try:
        tqdm.write('   -- Connecting to ' + fqdn)

        # connect to ftp
        # ftp = ftplib.FTP(fqdn, username, password)

        if not os.path.exists(destiny):
            os.makedirs(destiny)
            tqdm.write('   -- Creating dir ' + destiny)

        # tqdm.write('   -- Changing folder to ' + folder)

        # ftp.cwd(folder)
        # ftp_list = ftp.nlst()

        # if filename in ftp_list:
        #     ftp.retrbinary("RETR " + filename, open(os.path.join(destiny, filename), 'wb').write)
        # else:
        #    ftp.quit()
        #    return False

        # ftp.quit()

        p = subprocess.Popen(
            'wget --user=%s --password=%s -O %s ftp://%s%s || rm -f %s' %
            (username, password, os.path.join(destiny, filename), fqdn,
             os.path.join(folder, filename), os.path.join(destiny, filename)),
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)

        stdout, stderr = p.communicate()

        if stdout:
            tqdm.write(indent(stdout, 6))
        if stderr:
            tqdm.write(indent(stderr, 6))

        if os.path.isfile(os.path.join(destiny, filename)):
            return True
        else:
            return False

    except Exception as e:
        # folder not present, skip
        tqdm.write('   -- ftp error: ' + str(e))
        return False