<commit_before># -*- coding: utf-8 -*-
'''Provisioning. (alpha)
See http://github.com/exosite/exoline#provisioning for vendor token setup instructions.

Usage:
    exo [options] provision model list
    exo [options] provision model info <model>
    exo [options] provision model create (<rid>|<code>) [--noaliases] [--nocomments] [--nohistory]
    exo [options] provision model delete <model>
    exo [options] provision content list <model> [-l]
    exo [options] provision content put <model> <id> <file> [--mime=type] [--meta=meta]
    exo [options] provision content get <model> <id> <file>
    exo [options] provision content delete <model> <id>
    exo [options] provision content info <model> <id>
    exo [options] provision sn list <model> [--offset=num] [--limit=num]
    exo [options] provision sn add <model> (--file=<file> | <sn>...)
    exo [options] provision sn delete <model> (--file=<file> | <sn>...)
    exo [options] provision sn ranges <model>
    exo [options] provision sn addrange <model> <format> <first> <last> [--length=<digits>] [(--uppercase | --lowercase)]
    exo [options] provision sn delrange <model> <format> <first> <last> [--length=<digits>] [(--uppercase | --lowercase)]
    exo [options] provision sn regen <model> <sn>
    exo [options] provision sn disable <model> <sn>
	exo [options] provision sn activate <vendor> <model> <sn>

Command Options:
    --noaliases     Set no aliases option on model create
    --nocomments    Set no comments option on model create
    --nohistory     Set no history option on model create
    --mime=type     Set the mime type of the uploaded data. Will autodetect if omitted
    --offset=num    Offset to start listing at [default: 0]
    --limit=num     Maximum entries to return [default: 1000]

'''
from __future__ import unicode_literals
import inspect
import os
import sys
import re
import json
from pyonep import provision
import urllib, mimetypes

class Plugin():
	def command(self):
		return 'provision'

	########################
	class model:
		def list(self, cmd, args, options):
			pop = options['pop']
			exoconfig = options['config']
			key = exoconfig.config['vendortoken']

			mlist = pop.model_list(key)
			models = mlist.body
			print(models)

		def info(self, cmd, args, options):
			pop = options['pop']
			exoconfig = options['config']
			ExoException = options['exception']
			key = exoconfig.config['vendortoken']
			mlist = pop.model_info(key, args['<model>'])
			print(mlist.body)

		def create(self, cmd, args, options):
			pop = options['pop']
			exoconfig = options['config']
			ExoException = options['exception']
			key = exoconfig.config['vendortoken']

			mlist = pop.model_create(key, args['<model>'], args['<rid>'],
					args['--noaliases'] is None,
					args['--nocomments'] is None,
					args['--nohistory'] is None)
			print(mlist.body)


		def delete(self, cmd, args, options):
			pop = options['pop']
			exoconfig = options['config']
			ExoException = options['exception']
			key = exoconfig.config['vendortoken']
			mlist = pop.model_remove(key, args['<model>'])
			print(mlist.body)

	########################
	class content:
		def list(self, cmd, args, options):
			pop = options['pop']
			exoconfig = options['config']
			ExoException = options['exception']
			ExoUtilities = options['utils']
			key = exoconfig.config['vendortoken']

			mlist = pop.content_list(key, args['<model>'])
			if args['-l'] is None:
				files = mlist.body
				print(models)
			else:
				files = mlist.body.splitlines()
				for afile in files:
					mlist = pop.content_info(key, args['<model>'], afile)
					mime,size,updated,meta,protected = mlist.body.strip().split(',')
					
					# Format into human sizes
					#size
					# Format into Human time
					#updated = ExoUtilities.format_time(int(updated))

					res = "\t".join([afile, size, updated, protected, mime, meta])
					print(res)


		def info(self, cmd, args, options):
			pop = options['pop']
			exoconfig = options['config']
			ExoException = options['exception']
			key = exoconfig.config['vendortoken']
			mlist = pop.content_info(key, args['<model>'], args['<id>'])
			print(mlist.body)<commit_msg>Long listing for content.<commit_after># -*- coding: utf-8 -*-
'''Provisioning. (alpha)
See http://github.com/exosite/exoline#provisioning for vendor token setup instructions.

Usage:
    exo [options] provision model list [--long]
    exo [options] provision model info <model>
    exo [options] provision model create (<rid>|<code>) [--noaliases] [--nocomments] [--nohistory]
    exo [options] provision model delete <model>
    exo [options] provision content list <model> [--long]
    exo [options] provision content put <model> <id> <file> [--mime=type] [--meta=meta]
    exo [options] provision content get <model> <id> <file>
    exo [options] provision content delete <model> <id>
    exo [options] provision content info <model> <id>
    exo [options] provision sn list <model> [--offset=num] [--limit=num]
    exo [options] provision sn add <model> (--file=<file> | <sn>...)
    exo [options] provision sn delete <model> (--file=<file> | <sn>...)
    exo [options] provision sn ranges <model>
    exo [options] provision sn addrange <model> <format> <first> <last> [--length=<digits>] [(--uppercase | --lowercase)]
    exo [options] provision sn delrange <model> <format> <first> <last> [--length=<digits>] [(--uppercase | --lowercase)]
    exo [options] provision sn regen <model> <sn>
    exo [options] provision sn disable <model> <sn>
	exo [options] provision sn activate <vendor> <model> <sn>

Command Options:
    -l --long       Long listing
    --noaliases     Set no aliases option on model create
    --nocomments    Set no comments option on model create
    --nohistory     Set no history option on model create
    --mime=type     Set the mime type of the uploaded data. Will autodetect if omitted
    --offset=num    Offset to start listing at [default: 0]
    --limit=num     Maximum entries to return [default: 1000]

'''
from __future__ import unicode_literals
import inspect
import os
import sys
import re
import json
from pyonep import provision
import urllib, mimetypes
import time

class Plugin():
	def command(self):
		return 'provision'

	########################
	class model:
		def list(self, cmd, args, options):
			pop = options['pop']
			exoconfig = options['config']
			key = exoconfig.config['vendortoken']

			mlist = pop.model_list(key)
			models = mlist.body
			print(models)

		def info(self, cmd, args, options):
			pop = options['pop']
			exoconfig = options['config']
			ExoException = options['exception']
			key = exoconfig.config['vendortoken']
			mlist = pop.model_info(key, args['<model>'])
			print(mlist.body)

		def create(self, cmd, args, options):
			pop = options['pop']
			exoconfig = options['config']
			ExoException = options['exception']
			key = exoconfig.config['vendortoken']

			mlist = pop.model_create(key, args['<model>'], args['<rid>'],
					args['--noaliases'] is None,
					args['--nocomments'] is None,
					args['--nohistory'] is None)
			print(mlist.body)


		def delete(self, cmd, args, options):
			pop = options['pop']
			exoconfig = options['config']
			ExoException = options['exception']
			key = exoconfig.config['vendortoken']
			mlist = pop.model_remove(key, args['<model>'])
			print(mlist.body)

	########################
	class content:
		def list(self, cmd, args, options):
			pop = options['pop']
			exoconfig = options['config']
			ExoException = options['exception']
			ExoUtilities = options['utils']
			key = exoconfig.config['vendortoken']

			def humanSize(size):
				size = int(size)
				if size > (1024*1024):
					return "{0}M".format(size/(1024*1024))
				elif size > 1024:
					return "{0}k".format(size/(1024))
				return "{0}B".format(size)

			mlist = pop.content_list(key, args['<model>'])
			if args['--long'] is None:
				files = mlist.body
				print(models)
			else:
				files = mlist.body.splitlines()
				for afile in files:
					mlist = pop.content_info(key, args['<model>'], afile)
					mime,size,updated,meta,protected = mlist.body.strip().split(',')
					
					# Format into human sizes
					size = humanSize(size)
					# Format into Human time
					#updated = time.strftime('%Y-%m-%dT%H:%M:%S%Z', time.localtime(int(updated)))
					updated = time.strftime('%c', time.localtime(int(updated)))

					res = "\t".join([afile, size, updated, protected, mime, meta])
					print(res)


		def info(self, cmd, args, options):
			pop = options['pop']
			exoconfig = options['config']
			ExoException = options['exception']
			key = exoconfig.config['vendortoken']
			mlist = pop.content_info(key, args['<model>'], args['<id>'])
			print(mlist.body)
{'fraction_non_alphanumeric': 0.15964650522208196, 'fraction_numerical': 0.004476070239871456, 'mean_word_length': 3.71027027027027, 'pattern_counts': {'":': 0, '<': 99, '<?xml version=': 0, '>': 101, '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': '5296862', 'n_tokens_mistral': 3202, 'n_tokens_neox': 2797, 'n_words': 812}