예제 #1
0
class SharedProgressBar(object):
    def __init__(self, number_of_items):
        self.bar = ProgressBar(0, number_of_items, 77)
        self.number_of_items = number_of_items
        self.counter = 0
        self.old_bar_string = ""

    def update(self):
        self.counter += 1
        if self.old_bar_string != str(self.bar):
            sys.stdout.write(str(self.bar) + '\r')
            sys.stdout.flush()
            self.old_bar_string = str(self.bar)
        self.bar.updateAmount(self.counter)

    def flush(self):
        self.bar.updateAmount(self.number_of_items)
        sys.stdout.write(str(self.bar) + '\r')
        sys.stdout.flush()
예제 #2
0
        v = VBucketAwareMembaseClient(server, options.bucket)
        number_of_items = int(options.items)
        bar = ProgressBar(0, number_of_items, 77)
        old_bar_string = ""
        value = StringUtil.create_value("*", options.value_size)
        for i in range(0, number_of_items):
            key = "{0}-{1}".format(options.key_prefix, str(uuid.uuid4())[:5])
            if options.load_json:
                document = "\"name\":\"pymc-{0}\"".format(key, key)
                document = document + ",\"age\":{0}".format(random.randint(0, 1000))
                document = "{" + document + "}"
                a, b, c = v.set(key, 0, 0, document)
            else:
                a, b, c = v.set(key, 0, 0, value)
            a, b, c = v.get(key)

            bar.updateAmount(i)
            if old_bar_string != str(bar):
                sys.stdout.write(str(bar) + '\r')
                sys.stdout.flush()
                old_bar_string = str(bar)

        bar.updateAmount(number_of_items)
        sys.stdout.write(str(bar) + '\r')
        sys.stdout.flush()
        v.done()
        print ""
    except:
        print ""
        if v:
            v.done()