コード例 #1
0
ファイル: remove_arrays.py プロジェクト: cerbo/scidb
def main():
    """The main function gets command-line argument as a pattern, and removes all arrays with that pattern.
    """
    parser = argparse.ArgumentParser(
                                     description='Remove all SciDB arrays whose names match a given pattern.',
                                     epilog=
                                     'assumptions:\n' +
                                     '  - iquery is in your path.',
                                     formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('-f', '--force', action='store_true',
                        help='Forced removal of the arrays without asking for confirmation.')
    parser.add_argument('-c', '--host',
                        help='Host name to be passed to iquery.')
    parser.add_argument('-p', '--port',
                        help='Port number to be passed to iquery.')
    parser.add_argument('-t', '--temp-only', action='store_true',
                        help='Limiting the candidates to temp arrays.')
    parser.add_argument('-U', '--user-name',
                        help='User name to be passed to iquery.')
    parser.add_argument('-P', '--user-password',
                        help='User password to be passed to iquery.')
    parser.add_argument('-v', '--verbose ', default=True,
                        help='display verbose output.')
    parser.add_argument('regex', metavar='REGEX', type=str, nargs='?', default='.*',
                        help='''Regular expression to match against array names.
                        The utility will remove arrays whose names match the regular expression.
                        Default is '.+', meaning to remove all arrays, because the pattern matches all names.
                        The regular expression must match the full array name.
                        For instance, '.*s' will match array 'dogs' because it ends with 's',
                        but will not match array 'moose' because it does not end with 's'.'''
                        )

    args = parser.parse_args()


    try:
        iquery_cmd = scidb_afl.get_iquery_cmd(args)
        namespaces = scidb_afl.get_namespace_names(iquery_cmd)
        for namespace in namespaces:
            print "\nSearching namespace: ", namespace

            names = scidb_afl.get_array_names(
                iquery_cmd = iquery_cmd,
                temp_only=args.temp_only,
                namespace=namespace)

            names_to_remove = []

            for name in names:
                match_name = re.match('^'+args.regex+'$', name)
                if match_name:
                    names_to_remove.append(name)

            if not names_to_remove:
                print "There are no arrays to remove in namespace", namespace
                continue

            if not args.force:
                print 'The following arrays are about to be removed from namespace ' + namespace + ':'
                print names_to_remove
                proceed = scidb_psf.confirm(prompt='Are you sure you want to remove?', resp=False)
                if not proceed:
                    return

            for name in names_to_remove:
                scidb_afl.remove_array(name, namespace, iquery_cmd)

            if namespace != 'public':
                names = scidb_afl.get_array_names(
                    iquery_cmd=iquery_cmd,
                    temp_only=args.temp_only,
                    namespace=namespace)
                if not names:
                    scidb_afl.afl(
                        iquery_cmd,
                        'drop_namespace(\'' + namespace + '\');')

                    print "namespace " + namespace + " removed"


        print 'Number of arrays removed =', len(names_to_remove)
    except Exception, e:
        print >> sys.stderr, '------ Exception -----------------------------'
        print >> sys.stderr, e

        if args.verbose:
            print >> sys.stderr, '------ Traceback (for debug purpose) ---------'
            traceback.print_exc()

        print >> sys.stderr, '----------------------------------------------'
        sys.exit(-1)  # upon an exception, throw -1
コード例 #2
0
def main():
    """The main function gets command-line argument as a pattern, and removes all arrays with that pattern.
    """
    parser = argparse.ArgumentParser(
        description=
        'Remove all SciDB arrays whose names match a given pattern.',
        epilog='assumptions:\n' + '  - iquery is in your path.',
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument(
        '-f',
        '--force',
        action='store_true',
        help='Forced removal of the arrays without asking for confirmation.')
    parser.add_argument('-c',
                        '--host',
                        help='Host name to be passed to iquery.')
    parser.add_argument('-p',
                        '--port',
                        help='Port number to be passed to iquery.')
    parser.add_argument('-t',
                        '--temp-only',
                        action='store_true',
                        help='Limiting the candidates to temp arrays.')
    parser.add_argument('-U',
                        '--user-name',
                        help='User name to be passed to iquery.')
    parser.add_argument('-P',
                        '--user-password',
                        help='User password to be passed to iquery.')
    parser.add_argument('-v',
                        '--verbose ',
                        default=True,
                        help='display verbose output.')
    parser.add_argument(
        'regex',
        metavar='REGEX',
        type=str,
        nargs='?',
        default='.*',
        help='''Regular expression to match against array names.
                        The utility will remove arrays whose names match the regular expression.
                        Default is '.+', meaning to remove all arrays, because the pattern matches all names.
                        The regular expression must match the full array name.
                        For instance, '.*s' will match array 'dogs' because it ends with 's',
                        but will not match array 'moose' because it does not end with 's'.'''
    )

    args = parser.parse_args()

    try:
        iquery_cmd = scidb_afl.get_iquery_cmd(args)
        namespaces = scidb_afl.get_namespace_names(iquery_cmd)
        for namespace in namespaces:
            print "\nSearching namespace: ", namespace

            names = scidb_afl.get_array_names(iquery_cmd=iquery_cmd,
                                              temp_only=args.temp_only,
                                              namespace=namespace)

            names_to_remove = []

            for name in names:
                match_name = re.match('^' + args.regex + '$', name)
                if match_name:
                    names_to_remove.append(name)

            if not names_to_remove:
                print "There are no arrays to remove in namespace", namespace
                continue

            if not args.force:
                print 'The following arrays are about to be removed from namespace ' + namespace + ':'
                print names_to_remove
                proceed = scidb_psf.confirm(
                    prompt='Are you sure you want to remove?', resp=False)
                if not proceed:
                    return

            for name in names_to_remove:
                scidb_afl.remove_array(name, namespace, iquery_cmd)

            if namespace != 'public':
                names = scidb_afl.get_array_names(iquery_cmd=iquery_cmd,
                                                  temp_only=args.temp_only,
                                                  namespace=namespace)
                if not names:
                    scidb_afl.afl(iquery_cmd,
                                  'drop_namespace(\'' + namespace + '\');')

                    print "namespace " + namespace + " removed"

        print 'Number of arrays removed =', len(names_to_remove)
    except Exception, e:
        print >> sys.stderr, '------ Exception -----------------------------'
        print >> sys.stderr, e

        if args.verbose:
            print >> sys.stderr, '------ Traceback (for debug purpose) ---------'
            traceback.print_exc()

        print >> sys.stderr, '----------------------------------------------'
        sys.exit(-1)  # upon an exception, throw -1
コード例 #3
0
ファイル: pg_seq_reset.py プロジェクト: jonghunDB/SciDB
def main(argv=None):
    """Argument parsing and last-ditch exception handling.

    See http://www.artima.com/weblogs/viewpost.jsp?thread=4829
    """
    if argv is None:
        argv = sys.argv

    global _pgm
    _pgm = "%s:" % os.path.basename(argv[0])  # colon for easy use by print

    # Where possible, options mimic those of psql(1).
    parser = argparse.ArgumentParser(
        description="""Generate SQL to reset SciDB Postgres sequences.""")
    parser.add_argument(
        '-H',
        '--host',
        default='127.0.0.1',  # Not localhost,
        help="Postgres hostname")  # to match run.py
    parser.add_argument('-x',
                        '--execute',
                        action='count',
                        help="""Don't just print SQL commands, execute them.
                        Asks for confirmation, unless you use -xx""")
    parser.add_argument('-p',
                        '--port',
                        default='5432',
                        help="Postgres TCP port")
    parser.add_argument('-U',
                        '--username',
                        default=os.getlogin(),
                        help="Postgres username")
    parser.add_argument('-v',
                        '--verbose',
                        action='count',
                        help='Enable debug logging')
    parser.add_argument('-w',
                        '--no-password',
                        action='store_true',
                        help="""Never issue a password prompt.  If the server
                        requires a password and one cannot be found in the
                        ~/.pgpass file, connection attempts will fail.""")
    parser.add_argument('dbname', help="Postgres database name")

    global _args
    _args = parser.parse_args(argv[1:])

    if _args.execute == 1:
        if not confirm("This will modify the database, are you sure?"):
            print "Goodbye."
            return 0

    try:
        global _psql
        _psql = Psql(host=_args.host,
                     port=_args.port,
                     database=_args.dbname,
                     user=_args.username,
                     debug=(_args.verbose > 1))  # -vv for extra loud
        if _args.no_password:
            _psql.update({"options": ["--no-password"]})
            return process()
        with PgpassContext(_psql):
            return process()
    except AppError as e:
        print >> sys.stderr, _pgm, e
        return 1
    except KeyboardInterrupt:
        print >> sys.stderr, "^C"
        return 2
    except Exception as e:
        print >> sys.stderr, _pgm, "Unhandled exception:", e
        traceback.print_exc()  # always want this for unexpected exceptions
        return 2
コード例 #4
0
ファイル: remove_arrays.py プロジェクト: stjordanis/scidb-1
def main():
    """The main function gets command-line argument as a pattern, and removes all arrays with that pattern.

    @exception AppError if something goes wrong.
    @note If print_traceback_upon_exception (defined at the top of the script) is True,
          stack trace will be printed. This is helpful during debugging.
    """
    parser = argparse.ArgumentParser(
        description=
        'Remove all SciDB arrays whose names match a given pattern.',
        epilog='assumptions:\n' + '  - iquery is in your path.',
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument(
        '-f',
        '--force',
        action='store_true',
        help='Forced removal of the arrays without asking for confirmation.')
    parser.add_argument('-c',
                        '--host',
                        help='Host name to be passed to iquery.')
    parser.add_argument('-p',
                        '--port',
                        help='Port number to be passed to iquery.')
    parser.add_argument('-t',
                        '--temp-only',
                        action='store_true',
                        help='Limiting the candidates to temp arrays.')
    parser.add_argument(
        'regex',
        metavar='REGEX',
        type=str,
        nargs='?',
        default='.*',
        help='''Regular expression to match against array names.
                        The utility will remove arrays whose names match the regular expression.
                        Default is '.+', meaning to remove all arrays, because the pattern matches all names.
                        The regular expression must match the full array name.
                        For instance, '.*s' will match array 'dogs' because it ends with 's',
                        but will not match array 'moose' because it does not end with 's'.'''
    )
    args = parser.parse_args()

    try:
        names = scidb_afl.get_array_names(temp_only=args.temp_only)
        iquery_cmd = scidb_afl.get_iquery_cmd(args)
        names_to_remove = []

        for name in names:
            match_name = re.match('^' + args.regex + '$', name)
            if match_name:
                names_to_remove.append(name)

        if not names_to_remove:
            print 'There is no array to remove.'
            sys.exit(0)

        if not args.force:
            print 'The following arrays are about to be removed:'
            print names_to_remove
            proceed = scidb_psf.confirm(
                prompt='Are you sure you want to remove?', resp=False)
            if not proceed:
                sys.exit(0)

        for name in names_to_remove:
            scidb_afl.afl(iquery_cmd, 'remove(' + name + ')')

        print 'Number of arrays removed =', len(names_to_remove)
    except Exception, e:
        print >> sys.stderr, '------ Exception -----------------------------'
        print >> sys.stderr, e

        if _print_traceback_upon_exception:
            print >> sys.stderr, '------ Traceback (for debug purpose) ---------'
            traceback.print_exc()

        print >> sys.stderr, '----------------------------------------------'
        sys.exit(-1)  # upon an exception, throw -1
コード例 #5
0
ファイル: remove_arrays.py プロジェクト: Goon83/scidb
def main():
    """The main function gets command-line argument as a pattern, and removes all arrays with that pattern.

    @exception AppError if something goes wrong.
    @note If print_traceback_upon_exception (defined at the top of the script) is True,
          stack trace will be printed. This is helpful during debugging.
    """
    parser = argparse.ArgumentParser(
                                     description='Remove all SciDB arrays whose names match a given pattern.',
                                     epilog=
                                     'assumptions:\n' +
                                     '  - iquery is in your path.',
                                     formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('-f', '--force', action='store_true',
                        help='Forced removal of the arrays without asking for confirmation.')
    parser.add_argument('-c', '--host',
                        help='Host name to be passed to iquery.')
    parser.add_argument('-p', '--port',
                        help='Port number to be passed to iquery.')
    parser.add_argument('-t', '--temp-only', action='store_true',
                        help='Limiting the candidates to temp arrays.')
    parser.add_argument('regex', metavar='REGEX', type=str, nargs='?', default='.*',
                        help='''Regular expression to match against array names.
                        The utility will remove arrays whose names match the regular expression.
                        Default is '.+', meaning to remove all arrays, because the pattern matches all names.
                        The regular expression must match the full array name.
                        For instance, '.*s' will match array 'dogs' because it ends with 's',
                        but will not match array 'moose' because it does not end with 's'.'''
                        )
    args = parser.parse_args()

    try:
        names = scidb_afl.get_array_names(temp_only=args.temp_only)
        iquery_cmd = scidb_afl.get_iquery_cmd(args)
        names_to_remove = []

        for name in names:
            match_name = re.match('^'+args.regex+'$', name)
            if match_name:
                names_to_remove.append(name)

        if not names_to_remove:
            print 'There is no array to remove.'
            sys.exit(0)

        if not args.force:
            print 'The following arrays are about to be removed:'
            print names_to_remove
            proceed = scidb_psf.confirm(prompt='Are you sure you want to remove?', resp=False)
            if not proceed:
                sys.exit(0)

        for name in names_to_remove:
            scidb_afl.afl(iquery_cmd, 'remove('+name+')')

        print 'Number of arrays removed =', len(names_to_remove)
    except Exception, e:
        print >> sys.stderr, '------ Exception -----------------------------'
        print >> sys.stderr, e

        if _print_traceback_upon_exception:
            print >> sys.stderr, '------ Traceback (for debug purpose) ---------'
            traceback.print_exc()

        print >> sys.stderr, '----------------------------------------------'
        sys.exit(-1)  # upon an exception, throw -1
コード例 #6
0
ファイル: remove_arrays.py プロジェクト: jonghunDB/SciDB
def main():
    """The main function gets command-line argument as a pattern, and removes all arrays with that
    pattern.
    
    Note:  Empty namespaces will NOT be removed.
    """
    parser = argparse.ArgumentParser(
        description=
        'Remove all SciDB arrays whose names match a given pattern.',
        epilog='assumptions:\n' + '  - iquery is in your path.',
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument(
        '-f',
        '--force',
        action='store_true',
        help='Forced removal of the arrays without asking for confirmation.')
    parser.add_argument('-c',
                        '--host',
                        help='Host name to be passed to iquery.')
    parser.add_argument('-p',
                        '--port',
                        help='Port number to be passed to iquery.')
    parser.add_argument('-t',
                        '--temp-only',
                        action='store_true',
                        help='Limiting the candidates to temp arrays.')
    parser.add_argument('-A',
                        '--auth-file',
                        help='Authentication file to be passed to iquery.')
    parser.add_argument(
        '-U',
        '--user-name',
        help=
        'Deprecated: Use --auth-file instead.  User name to be passed to iquery.'
    )
    parser.add_argument(
        '-P',
        '--user-password',
        help=
        'Deprecated: Use --auth-file instead.  User password to be passed to iquery.'
    )

    parser.add_argument('-v',
                        '--verbose',
                        default=True,
                        help='display verbose output.')
    parser.add_argument(
        'regex',
        metavar='REGEX',
        type=str,
        nargs='?',
        default='.*',
        help='''Regular expression to match against array names.
                        The utility will remove arrays whose names match the regular expression.
                        Default is '.+', meaning to remove all arrays, because the pattern matches all names.
                        The regular expression must match the full array name.
                        For instance, '.*s' will match array 'dogs' because it ends with 's',
                        but will not match array 'moose' because it does not end with 's'.'''
    )

    _temp_auth_file = None
    _arrays_removed = 0
    args = parser.parse_args()

    try:
        if args.verbose == True:
            print >> sys.stderr, "args={0}".format(args)

        if args.user_name and args.user_password and (args.auth_file == None):
            print >> sys.stderr, '\nWARNING:  --user-name and --user-password are deprecated. Use --auth-file instead.\n'
            _temp_auth_file = create_auth_file(args.user_name,
                                               args.user_password)
            args.auth_file = _temp_auth_file.name
            args.user_name = None
            args.user_password = None

        iquery_cmd = scidb_afl.get_iquery_cmd(args)
        namespaces = scidb_afl.get_namespace_names(iquery_cmd)

        if args.verbose == True:
            print >> sys.stderr, "namespaces={0}".format(namespaces)

        _arrays_removed = 0
        for namespace in namespaces:
            if args.verbose == True:
                print >> sys.stderr, "\nSearching namespace: ", namespace

            names = scidb_afl.get_array_names(iquery_cmd=iquery_cmd,
                                              temp_only=args.temp_only,
                                              namespace=namespace)

            if args.verbose == True:
                print >> sys.stderr, "names={0}".format(names)

            names_to_remove = []

            for name in names:
                match_name = re.match('^' + args.regex + '$', name)
                if match_name:
                    if args.verbose == True:
                        print >> sys.stderr, "Schedule {0}.{1} to be removed".format(
                            namespace, name)
                    names_to_remove.append(name)

            if not names_to_remove:
                if args.verbose == True:
                    print "There are no arrays to remove in namespace", namespace
                continue

            if not args.force:
                print 'The following arrays are about to be removed from namespace {0}:'.format(
                    namespace)
                print names_to_remove

                proceed = scidb_psf.confirm(
                    prompt='Are you sure you want to remove?', resp=False)
                if not proceed:
                    return

            for name in names_to_remove:
                scidb_afl.remove_array(name, namespace, iquery_cmd)
                if args.verbose == True:
                    print >> sys.stderr, "array {0}.{1} removed".format(
                        namespace, name)
                _arrays_removed += 1

            if namespace != 'public':
                names = scidb_afl.get_array_names(iquery_cmd=iquery_cmd,
                                                  temp_only=args.temp_only,
                                                  namespace=namespace)

                if not names:
                    scidb_afl.afl(iquery_cmd,
                                  "drop_namespace('{0}');".format(namespace))

                    if args.verbose == True:
                        print >> sys.stderr, "namespace {0} removed".format(
                            namespace)

        if args.verbose == True:
            print >> sys.stderr, 'Number of arrays removed =', _arrays_removed

        if _temp_auth_file:
            _temp_auth_file.close()
            _temp_auth_file = None

    except Exception, e:
        print >> sys.stderr, '------ Exception -----------------------------'
        print >> sys.stderr, e

        if args.verbose == True:
            print >> sys.stderr, 'Number of arrays removed =', _arrays_removed

        if args.verbose == True:
            print >> sys.stderr, '------ Traceback (for debug purpose) ---------'
            traceback.print_exc()

        if _temp_auth_file:
            _temp_auth_file.close()
            _temp_auth_file = None

        print >> sys.stderr, '----------------------------------------------'
        sys.exit(-1)  # upon an exception, throw -1