예제 #1
0
def listDatasets(url):
    """ Print a list of local and remote datasets """

    tdir = pw.Config.SCIPION_TESTS
    print("Local datasets in %s" % yellow(tdir))
    for folder in sorted(os.listdir(tdir)):
        if isdir(join(tdir, folder)):
            if exists(join(tdir, folder, 'MANIFEST')):
                print("  * %s" % folder)
            else:
                print("  * %s (not in dataset format)" % folder)

    try:
        print("\nRemote datasets in %s" % yellow(url))
        for line in sorted(urlopen('%s/MANIFEST' % url)):
            print("  * %s" % line.decode("utf-8").strip('./\n'))
    except Exception as e:
        print("Error reading %s (%s)" % (url, e))
예제 #2
0
def listDatasets(url):
    """ Print a list of local and remote datasets """

    tdir = os.environ['SCIPION_TESTS']
    print "Local datasets in %s" % yellow(tdir)
    for folder in sorted(os.listdir(tdir)):
        if isdir(join(tdir, folder)):
            if exists(join(tdir, folder, 'MANIFEST')):
                print "  * %s" % folder
            else:
                print "  * %s (not in dataset format)" % folder

    try:
        print "\nRemote datasets in %s" % yellow(url)
        for line in sorted(urlopen('%s/MANIFEST' % url)):
            print "  * %s" % line.strip('./\n')
    except Exception as e:
        print "Error reading %s (%s)" % (url, e)
예제 #3
0
def listDatasets(url):
    """ Print a list of local and remote datasets """

    tdir = os.environ['SCIPION_TESTS']
    print "Local datasets in %s" % yellow(tdir)
    for folder in sorted(os.listdir(tdir)):
        if isdir(join(tdir, folder)):
            if exists(join(tdir, folder, 'MANIFEST')):
                print "  * %s" % folder
            else:
                print "  * %s (not in dataset format)" % folder

    try:
        print "\nRemote datasets in %s" % yellow(url)
        for line in sorted(urlopen('%s/MANIFEST' % url)):
            print "  * %s" % line.strip('./\n')
    except Exception as e:
        print "Error reading %s (%s)" % (url, e)
예제 #4
0
def main():
    # Get arguments.
    args = get_parser().parse_args()

    # Dispatch the easy cases first (list and check), and then take care of
    # the more complex ones.
    if args.list:
        listDatasets(args.url)
        sys.exit(0)

    if args.check_all:
        datasets = [
            x.decode("utf-8").strip('./\n')
            for x in urlopen('%s/MANIFEST' % args.url)
        ]
        print('Checking datasets: %s' % ' '.join(datasets))

        all_uptodate = True
        for dataset in datasets:
            all_uptodate &= check(dataset, url=args.url, verbose=args.verbose)
        if all_uptodate:
            print('All datasets are up-to-date.')
            sys.exit(0)
        else:
            print('Some datasets are not updated.')
            sys.exit(1)

    if not args.datasets:
        sys.exit('At least --list, --check-all or datasets needed.\n'
                 'Run with --help for more info.')

    print('Selected datasets: %s' % yellow(' '.join(args.datasets)))

    testFolder = pw.Config.SCIPION_TESTS

    if args.format:
        for dataset in args.datasets:
            datasetFolder = join(testFolder, dataset)
            print('Formatting %s (creating MANIFEST file)' % dataset)

            if not exists(datasetFolder):
                sys.exit('ERROR: %s does not exist in datasets folder %s.' %
                         (dataset, testFolder))
            createMANIFEST(datasetFolder)
        sys.exit(0)

    if args.download:
        # Download datasets.
        try:
            for dataset in args.datasets:
                if exists(join(testFolder, dataset)):
                    print('Local copy of dataset %s detected.' % dataset)
                    print('Checking for updates...')
                    update(dataset, url=args.url, verbose=args.verbose)
                else:
                    print('Dataset %s not in local machine. '
                          'Downloading...' % dataset)
                    download(dataset, url=args.url, verbose=args.verbose)
        except IOError as e:
            print('Warning: %s' % e)
            if e.errno == 13:  # permission denied
                print('Maybe you need to run as the user that '
                      'did the global installation?')
            sys.exit(1)
        sys.exit(0)

    if args.upload:
        # Upload datasets.
        for dataset in args.datasets:
            try:
                upload(dataset,
                       login=args.login,
                       remoteFolder=args.remotefolder,
                       delete=args.delete)
            except Exception as e:
                print('Error when uploading dataset %s: %s' % (dataset, e))
                if ask() != 'y':
                    sys.exit(1)
        sys.exit(0)

    # If we get here, we did not use the right arguments. Show a little help.
    get_parser().print_usage()
예제 #5
0
def main():
    # Get arguments.
    args = get_parser().parse_args()

    #print scipion_logo

    # Dispatch the easy cases first (list and check), and then take care of
    # the more complex ones.
    if args.list:
        listDatasets(args.url)
        sys.exit(0)

    if args.check_all:
        datasets = [x.strip('./\n') for x in urlopen('%s/MANIFEST' % args.url)]
        print 'Checking datasets: %s' % ' '.join(datasets)

        all_uptodate = True
        for dataset in datasets:
            all_uptodate &= check(dataset, url=args.url, verbose=args.verbose)
        if all_uptodate:
            print 'All datasets are up-to-date.'
            sys.exit(0)
        else:
            print 'Some datasets are not updated.'
            sys.exit(1)

    if not args.datasets:
        sys.exit('At least --list, --check-all or datasets needed.\n'
                 'Run with --help for more info.')

    print 'Selected datasets: %s' % yellow(' '.join(args.datasets))

    if args.format:
        for dataset in args.datasets:
            print 'Formatting %s (creating MANIFEST file)' % dataset
            if not exists(join(os.environ['SCIPION_TESTS'], dataset)):
                sys.exit('ERROR: %s does not exist in datasets folder %s.' %
                         (dataset, os.environ['SCIPION_TESTS']))
            createMANIFEST(join(os.environ['SCIPION_TESTS'], dataset))
        sys.exit(0)

    if args.download:
        # Download datasets.
        try:
            for dataset in args.datasets:
                if exists(join(os.environ['SCIPION_TESTS'], dataset)):
                    print 'Local copy of dataset %s detected.' % dataset
                    print 'Checking for updates...'
                    update(dataset, url=args.url, verbose=args.verbose)
                else:
                    print ('Dataset %s not in local machine. '
                           'Downloading...' % dataset)
                    download(dataset, url=args.url, verbose=args.verbose)
        except IOError as e:
            print 'Warning: %s' % e
            if e.errno == 13:  # permission denied
                print ('Maybe you need to run as the user that '
                       'did the global installation?')
            sys.exit(1)
        sys.exit(0)

    if args.upload:
        # Upload datasets.
        for dataset in args.datasets:
            try:
                upload(dataset, delete=args.delete)
            except Exception as e:
                print 'Error when uploading dataset %s: %s' % (dataset, e)
                if ask() != 'y':
                    sys.exit(1)
        sys.exit(0)

    # If we get here, we did not use the right arguments. Show a little help.
    get_parser().print_usage()