Пример #1
0
def do_genesis(args, data_dir=None):
    """Given the command args, take an series of input files containing
    GenesisData, combine all the batches into one GenesisData, and output the
    result into a new file.
    """

    if data_dir is None:
        data_dir = get_data_dir()

    if not os.path.exists(data_dir):
        raise CliException(
            "Data directory does not exist: {}".format(data_dir))

    genesis_batches = []
    for input_file in args.input_file:
        print('Processing {}...'.format(input_file))
        input_data = BatchList()
        try:
            with open(input_file, 'rb') as in_file:
                input_data.ParseFromString(in_file.read())
        except:
            raise CliException('Unable to read {}'.format(input_file))

        genesis_batches += input_data.batches

    _validate_depedencies(genesis_batches)
    if args.output:
        genesis_file = args.output
    else:
        genesis_file = os.path.join(data_dir, 'genesis.batch')

    print('Generating {}'.format(genesis_file))
    output_data = GenesisData(batches=genesis_batches)
    with open(genesis_file, 'wb') as out_file:
        out_file.write(output_data.SerializeToString())
Пример #2
0
def do_genesis(args):
    """Given the command args, take an series of input files containing
    GenesisData, combine all the batches into one GenesisData, and output the
    result into a new file.
    """
    genesis_batches = []
    for input_file in args.input_file:
        print('Processing {}...'.format(input_file))
        input_data = BatchList()
        try:
            with open(input_file, 'rb') as in_file:
                input_data.ParseFromString(in_file.read())
        except:
            raise CliException('Unable to read {}'.format(input_file))

        genesis_batches += input_data.batches

    _validate_depedencies(genesis_batches)

    print('Generating {}'.format(args.output))
    output_data = GenesisData(batches=genesis_batches)
    with open(args.output, 'wb') as out_file:
        out_file.write(output_data.SerializeToString())
Пример #3
0
 def _result_data(self, target_dir=None):
     target_dir = target_dir if target_dir else self._temp_dir
     with open(os.path.join(target_dir, "genesis.batch"), "rb") as f:
         output = GenesisData()
         output.ParseFromString(f.read())
         return output
Пример #4
0
 def _result_data(self):
     with open(os.path.join(self._temp_dir, "genesis.batch"), "rb") as f:
         output = GenesisData()
         output.ParseFromString(f.read())
         return output