コード例 #1
0
ファイル: rescan_query.py プロジェクト: exhuma/metafilter
def main():
    parser = OptionParser(usage='usage: %prog [options] <scan_folder>')
    parser.add_option("-a", "--auto-tag-tail", dest="auto_tag_tail", default=False, action="store_true",
                help="Automatically add the 'leaf' folder-name to the tags")
    parser.add_option("-w", "--auto-tag-word", dest="auto_tag_words", default=[], action="append", metavar="WORD",
                help="If WORD appears anywhere as folder-name in the files path, add it to the tag list. This option can be specified as many times you want.")
    parser.add_option("-v", "--verbose", dest="verbose", default=False, action="store_true",
                help="Verbose output to stdout")
    parser.add_option("-p", "--purge", dest="purge", default=False, action="store_true",
                help="Automatically purge files from the database which have disappeared from disk.")
    parser.add_option("-q", "--quiet", dest="quiet", default=False, action="store_true",
                help="Suppresses informational messages from output (overrides -v)")
    parser.add_option("-d", "--dsn", dest="dsn",
                      help="The database DSN", default=CONF.get('database', 'dsn'))

    (options, args) = parser.parse_args()

    if options.verbose:
        CONSOLE_HANDLER.setLevel(logging.DEBUG)
    if options.quiet:
        CONSOLE_HANDLER.setLevel(logging.WARNING)

    if options.dsn:
        set_dsn(options.dsn)
    else:
        print LOG.fatal("No DSN specified!")
        return 9

    if not args:
        LOG.critical("No query specified!")
        print parser.print_usage()
        sys.exit(9)

    sess = Session()

    try:
        update_nodes_from_query(sess, args[0], None,
                options.auto_tag_tail, options.auto_tag_words, options.purge)
    except KeyboardInterrupt:
        response = raw_input("Operation cancelled by user. Commit results? [Y/n] ")
        if not response.strip() or response.strip().lower() == 'y':
            sess.commit()
            LOG.info('Successfully committed')


    sess.close()
    print "Rescan finished"
コード例 #2
0
    if options.since:
        try:
            options.since = datetime.strptime(options.since, "%Y-%m-%d")
        except Exception, exc:
            LOG.error(exc)
            options.since = None

    if not args:
        LOG.critical("No path specified!")
        print parser.print_usage()
        sys.exit(9)

    sess = Session()

    if not options.no_insert:
        update_nodes_from_path(sess, args[0], options.since,
                               options.auto_tag_tail, options.auto_tag_words)

    if options.purge:
        remove_orphans(sess, args[0])

    if options.md5:
        calc_md5(sess, args[0], options.since)

    sess.close()
    print "Rescan finished"


if __name__ == '__main__':
    main()
コード例 #3
0
ファイル: rescan_folder.py プロジェクト: exhuma/metafilter
    if options.since:
        try:
            options.since = datetime.strptime(options.since, "%Y-%m-%d")
        except Exception, exc:
            LOG.error(exc)
            options.since = None

    if not args:
        LOG.critical("No path specified!")
        print parser.print_usage()
        sys.exit(9)

    sess = Session()

    if not options.no_insert:
        update_nodes_from_path(sess, args[0], options.since,
                options.auto_tag_tail, options.auto_tag_words)

    if options.purge:
        remove_orphans(sess, args[0])

    if options.md5:
        calc_md5(sess, args[0], options.since)

    sess.close()
    print "Rescan finished"

if __name__ == '__main__':
    main()

コード例 #4
0
def main():
    parser = OptionParser(usage='usage: %prog [options] <scan_folder>')
    parser.add_option(
        "-a",
        "--auto-tag-tail",
        dest="auto_tag_tail",
        default=False,
        action="store_true",
        help="Automatically add the 'leaf' folder-name to the tags")
    parser.add_option(
        "-w",
        "--auto-tag-word",
        dest="auto_tag_words",
        default=[],
        action="append",
        metavar="WORD",
        help=
        "If WORD appears anywhere as folder-name in the files path, add it to the tag list. This option can be specified as many times you want."
    )
    parser.add_option("-v",
                      "--verbose",
                      dest="verbose",
                      default=False,
                      action="store_true",
                      help="Verbose output to stdout")
    parser.add_option(
        "-p",
        "--purge",
        dest="purge",
        default=False,
        action="store_true",
        help=
        "Automatically purge files from the database which have disappeared from disk."
    )
    parser.add_option(
        "-q",
        "--quiet",
        dest="quiet",
        default=False,
        action="store_true",
        help="Suppresses informational messages from output (overrides -v)")
    parser.add_option("-d",
                      "--dsn",
                      dest="dsn",
                      help="The database DSN",
                      default=CONF.get('database', 'dsn'))

    (options, args) = parser.parse_args()

    if options.verbose:
        CONSOLE_HANDLER.setLevel(logging.DEBUG)
    if options.quiet:
        CONSOLE_HANDLER.setLevel(logging.WARNING)

    if options.dsn:
        set_dsn(options.dsn)
    else:
        print LOG.fatal("No DSN specified!")
        return 9

    if not args:
        LOG.critical("No query specified!")
        print parser.print_usage()
        sys.exit(9)

    sess = Session()

    try:
        update_nodes_from_query(sess, args[0], None, options.auto_tag_tail,
                                options.auto_tag_words, options.purge)
    except KeyboardInterrupt:
        response = raw_input(
            "Operation cancelled by user. Commit results? [Y/n] ")
        if not response.strip() or response.strip().lower() == 'y':
            sess.commit()
            LOG.info('Successfully committed')

    sess.close()
    print "Rescan finished"