<commit_before>#!/usr/bin/env python
# encoding: utf-8

""" Tabbed CLI Inteface Application
"""

import io
import sys

import argue

import tablib
from helpers import Struct, piped



FORMATS = [fmt.title for fmt in tablib.formats.FORMATS]

opts = []

opts.append(('v', 'version', False, 'Report tabbed version'))

for format in FORMATS:
	opts.append(('', format, False, 'Output to %s' % (format.upper())))



@argue.command(options=opts, usage='[FILE] [--FORMAT | FILE]')
def start(in_file=None, out_file=None, **opts):
	"""Covertly convert dataset formats"""
	
	opts = Struct(**opts)
	
	if opts.version:
		print('Tabbed, Ver. %s' % tablib.core.__version__)
		sys.exit(0)
	
	stdin = piped()
	
	if stdin:
		data = tablib.import_set(stdin)
		print data.json
		# test = tablib.Dataset()
		# print test.yaml
	
	elif in_file:
		
		try:
			in_file = io.open(in_file, 'r')
		except Exception, e:
			print(' %s cannot be read.' % in_file)
			sys.exit(65)
		
		file_ext = in_file.name.split('.')[-1]
		
		if file_ext.lower() in FORMATS:
			setattr(opts, file_ext, True)
		else:
			print('Import format not supported.')
			sys.exit(65)
	else:
		print('Please provide input.')
		sys.exit(65)
		

	
	_formats_sum = sum(opts[f] for f in FORMATS)
	
	# Multiple output formats given
	if _formats_sum > 1:
		print('Please specify a single output format.')
		sys.exit(64)
		
	# No output formats given
	elif _formats_sum < 1:
		print('Please specify an output format.')
		sys.exit(64)
	
	
	# fetch options.formats list
	# if sum(()) > 1<commit_msg>Changes.<commit_after>#!/usr/bin/env python
# encoding: utf-8

""" Tabbed CLI Inteface Application
"""

import io
import sys

import argue

import tablib
from helpers import Struct, piped



FORMATS = [fmt.title for fmt in tablib.formats.FORMATS]

opts = []

opts.append(('v', 'version', False, 'Report tabbed version'))

for format in FORMATS:
	opts.append(('', format, False, 'Output to %s' % (format.upper())))



@argue.command(options=opts, usage='[FILE] [--FORMAT | FILE]')
def start(in_file=None, out_file=None, **opts):
	"""Covertly convert dataset formats"""
	
	opts = Struct(**opts)
	
	if opts.version:
		print('Tabbed, Ver. %s' % tablib.core.__version__)
		sys.exit(0)
	
	stdin = piped()
	
	if stdin:
		data = tablib.import_set(stdin)
	
	elif in_file:
		
		try:
			in_stream =- io.open(in_file, 'r').read()
		except Exception, e:
			print(' %s cannot be read.' % in_file)
			sys.exit(65)
		
		try:
			tablib.import_set(in_stream)
		except Exception, e:
			raise e
			print('Import format not supported.')
			sys.exit(65)
	else:
		print('Please provide input.')
		sys.exit(65)
		

	_formats_sum = sum(opts[f] for f in FORMATS)
	
	# Multiple output formats given
	if _formats_sum > 1:
		print('Please specify a single output format.')
		sys.exit(64)
		
	# No output formats given
	elif _formats_sum < 1:
		print('Please specify an output format.')
		sys.exit(64)
	
	
	# fetch options.formats list
	# if sum(()) > 1
{'fraction_non_alphanumeric': 0.14382402707275804, 'fraction_numerical': 0.010490693739424704, 'mean_word_length': 3.647798742138365, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '710237', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1068, 'n_words': 298}