Пример #1
0
def store_file(filename):
	if os.access(filename, os.R_OK):
		imsto = load_imsto(section)
		from _util import guess_mimetype
		ctype = guess_mimetype(filename)
		with open(filename) as fp:
			ret = imsto.store(fp, ctype, name=os.path.basename(filename))
			print ret
	else:
		print 'image {} not found or access deny'.format(filename)
Пример #2
0
def migrate(from_section, to_section, skip=0, limit=50, end_count=0, id=None):
    """merge and sync data between 2 storage engines"""
    if from_section == to_section:
        return False

    if not test_section(from_section) or not test_section(to_section):
        return False

    imsto1 = load_imsto(from_section)
    imsto2 = load_imsto(to_section)

    if id is not None:
        item = imsto1.get_meta(id)
        if item:
            print "start trans {},{},{}".format(item.id, item.filename,
                                                item.size)
            r = _store_item(imsto2, item)
            print 'trans ok: %s, %s' % (r, item.name)
        else:
            print 'item id %s not found' % id
        return

    total = imsto1.count()
    print 'total: {}'.format(total)

    p_count = 0
    offset = skip if isinstance(skip, Integral) and skip > 0 else 0
    while offset < total:
        print 'migrating page {}/{}'.format(offset, total)
        i = offset
        for item in imsto1.browse(limit, offset, only_items=True):
            print "start trans {:4d} {},{},{}".format(i, item.id,
                                                      item.filename, item.size)
            r = _store_item(imsto2, item)
            print 'trans ok: %s, %s' % (r, item.name)
            i += 1
            p_count += 1
            if end_count > 0 and p_count >= end_count:
                print 'end count done'
                return
        offset += limit

    print 'all done!'
Пример #3
0
def store_file(filename):
    if os.access(filename, os.R_OK):
        imsto = load_imsto(section)
        from _util import guess_mimetype
        ctype = guess_mimetype(filename)
        with open(filename) as fp:
            ret = imsto.store(fp, ctype, name=os.path.basename(filename))
            print ret
    else:
        print 'image {} not found or access deny'.format(filename)
Пример #4
0
def migrate(from_section, to_section, skip=0, limit=50, end_count=0, id=None):
	"""merge and sync data between 2 storage engines"""
	if from_section == to_section:
		return False

	if not test_section(from_section) or not test_section(to_section):
		return False

	imsto1 = load_imsto(from_section)
	imsto2 = load_imsto(to_section)

	if id is not None:
		item = imsto1.get_meta(id)
		if item:
			print "start trans {},{},{}".format(item.id, item.filename, item.size)
			r = _store_item(imsto2, item)
			print 'trans ok: %s, %s' % (r, item.name)
		else:
			print 'item id %s not found' % id
		return

	total = imsto1.count()
	print 'total: {}'.format(total)

	p_count = 0
	offset = skip if isinstance(skip, Integral) and skip > 0 else 0
	while offset < total:
		print 'migrating page {}/{}'.format(offset, total)
		i = offset
		for item in imsto1.browse(limit, offset, only_items=True):
			print "start trans {:4d} {},{},{}".format(i, item.id, item.filename, item.size)
			r = _store_item(imsto2, item)
			print 'trans ok: %s, %s' % (r, item.name)
			i += 1
			p_count += 1
			if end_count > 0 and p_count >= end_count:
				print 'end count done'
				return
		offset += limit

	print 'all done!'
Пример #5
0
def list_dir(limit=5,start=0,prefix=''):
	imsto = load_imsto(section)
	gallery = imsto.browse(limit, start)
	if gallery['total'] == 0:
		print 'total 0, empty'
		return

	print 'total {}'.format(gallery['total'])
	for item in gallery['items']:
		#print hasattr(item.file, 'read')
		#print(item)
		print("{0[filename]}\t{0[size]:8,d}".format(item))
Пример #6
0
def list_dir(limit=5, start=0, prefix=''):
    imsto = load_imsto(section)
    gallery = imsto.browse(limit, start)
    if gallery['total'] == 0:
        print 'total 0, empty'
        return

    print 'total {}'.format(gallery['total'])
    for item in gallery['items']:
        #print hasattr(item.file, 'read')
        #print(item)
        print("{0[filename]}\t{0[size]:8,d}".format(item))
Пример #7
0
	parser.add_argument('--id', metavar='id', type=str, help='Special file id')
	parser.add_argument('--path', metavar='path', type=str, help='Special file path')
	parser.add_argument('-v', '--verbose', action='store_true')
	parser.add_argument('-l', '--list', action='store_true', help='List files')
	#default=argparse.SUPPRESS
	parser.add_argument('--limit', type=int, default=5)
	parser.add_argument('--start', type=int, default=0)
	parser.add_argument('--prefix', type=str, default='')
	args, remaining = parser.parse_known_args()
	#print args

	section = args.section
	print section
	if args.list:
		list_dir(args.limit, args.start, prefix=args.prefix)
	elif args.fetch:
		imsto = load_imsto(section)
		_file, _path = imsto.load('orig/{}'.format(args.fetch))
		print _path
	elif args.query:
		imsto = load_imsto(section)
		method = imsto.get_meta if args.query == 'meta' else imsto.exists
		# print method
		print method(args.id or None,filename=args.path or None)
	elif args.add:
		store_file(filename=args.add)
	else:
		parser.print_help()
	#sys.exit(main())

Пример #8
0
                        metavar='path',
                        type=str,
                        help='Special file path')
    parser.add_argument('-v', '--verbose', action='store_true')
    parser.add_argument('-l', '--list', action='store_true', help='List files')
    #default=argparse.SUPPRESS
    parser.add_argument('--limit', type=int, default=5)
    parser.add_argument('--start', type=int, default=0)
    parser.add_argument('--prefix', type=str, default='')
    args, remaining = parser.parse_known_args()
    #print args

    section = args.section
    print section
    if args.list:
        list_dir(args.limit, args.start, prefix=args.prefix)
    elif args.fetch:
        imsto = load_imsto(section)
        _file, _path = imsto.load('orig/{}'.format(args.fetch))
        print _path
    elif args.query:
        imsto = load_imsto(section)
        method = imsto.get_meta if args.query == 'meta' else imsto.exists
        # print method
        print method(args.id or None, filename=args.path or None)
    elif args.add:
        store_file(filename=args.add)
    else:
        parser.print_help()
    #sys.exit(main())