#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2017  Nexedi SA and Contributors.
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
"""zgenprod1 - generate synthetic test database according to NEO PROD1 statistics"""

from __future__ import print_function

from neo.tests.stat_zodb import PROD1
from random import Random
import zodbtools.util
import sys
import logging

def usage(w):
    print(\
"""Usage: zgenprod1 url n""", file=w)

def main():
    argv = sys.argv[1:]

    if len(argv) != 2:
        print(__doc__)
        usage(sys.stderr)
        sys.exit(1)

    url = argv[0]
    n   = int(argv[1])

    # log -> stderr
    l = logging.getLogger()
    l.addHandler(logging.StreamHandler())

    zin  = PROD1(Random(0)).as_storage(n)
    zout = zodbtools.util.storageFromURL(url)

    zout.copyTransactionsFrom(zin)
    zout.close()

if __name__ == '__main__':
    main()
