Beispiel #1
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"
Beispiel #2
0
    def __init__(self, dsn, root):
        self.files = {}  #todo# remove
        self.data = defaultdict(str)  #todo# remove
        self.fd = 0  #todo# remove
        now = time()
        self.files['/'] = dict(st_mode=(S_IFDIR | 0755),
                               st_ctime=now,
                               st_mtime=now,
                               st_atime=now,
                               st_nlink=2)

        self.log = logging.getLogger(__name__)
        self.setup_logging()
        self.log.info("*** Fuse Initialised")
        metafilter.model.set_dsn(dsn)
        self.sess = Session()
        self.root = '/'
        self.dsn = "sqlite://"

        try:
            os.chdir(root)
        except OSError:
            print >> sys.stderr, "can't enter root (%r) of underlying filesystem" % root
            sys.exit(1)
        print LOG.fatal("No DSN specified!")
        return 9

    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"

Beispiel #4
0
        print LOG.fatal("No DSN specified!")
        return 9

    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__':
Beispiel #5
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"