* Date fixed in CLI prompt
* Obsolete files deleted * URL to github added as homepage setup.py
This commit is contained in:
parent
cce9b830ab
commit
65d1c9b2d2
@ -1,14 +0,0 @@
|
|||||||
# Copyright (c) 2013 Mirantis, Inc.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
# not use this file except in compliance with the License. You may obtain
|
|
||||||
# a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
# License for the specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
|||||||
# Copyright (c) 2013 Mirantis, Inc.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
# not use this file except in compliance with the License. You may obtain
|
|
||||||
# a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
# License for the specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
@ -1,40 +0,0 @@
|
|||||||
# Copyright (c) 2013 Mirantis, Inc.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
# not use this file except in compliance with the License. You may obtain
|
|
||||||
# a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
# License for the specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
|
|
||||||
short_names = {}
|
|
||||||
values = {}
|
|
||||||
|
|
||||||
|
|
||||||
def register_shortening(short_name, fqns):
|
|
||||||
existing = short_names.get(short_name)
|
|
||||||
if existing and existing != fqns:
|
|
||||||
raise Exception(
|
|
||||||
"A namespace ('{0}') is already registered as '{1}'".format(
|
|
||||||
existing, short_name))
|
|
||||||
short_names[short_name] = fqns
|
|
||||||
|
|
||||||
|
|
||||||
def register_symbol(fqns, symbol):
|
|
||||||
if not fqns in values:
|
|
||||||
values[fqns] = {symbol}
|
|
||||||
else:
|
|
||||||
values[fqns].add(symbol)
|
|
||||||
|
|
||||||
|
|
||||||
def get_fqns(short_name):
|
|
||||||
return short_names.get(short_name)
|
|
||||||
|
|
||||||
|
|
||||||
def validate(fqns, value):
|
|
||||||
return fqns in values and value in values[fqns]
|
|
@ -1,50 +0,0 @@
|
|||||||
# Copyright (c) 2013 Mirantis, Inc.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
# not use this file except in compliance with the License. You may obtain
|
|
||||||
# a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
# License for the specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
|
|
||||||
import types
|
|
||||||
import examples.ns.definition
|
|
||||||
from yaql.functions.old.decorators import arg
|
|
||||||
|
|
||||||
|
|
||||||
@arg('short_name', type=types.StringType)
|
|
||||||
@arg('value', type=types.StringType)
|
|
||||||
def expand_property_namespace(short_name, value):
|
|
||||||
fqns = examples.ns.definition.get_fqns(short_name)
|
|
||||||
if not fqns:
|
|
||||||
raise Exception(
|
|
||||||
"Namespace with alias '{0}' is unknown".format(short_name))
|
|
||||||
if not examples.ns.definition.validate(fqns, value):
|
|
||||||
raise Exception(
|
|
||||||
"Namespace '{0}' does not contain name '{1}'".format(fqns, value))
|
|
||||||
return "{0}.{1}".format(fqns, value)
|
|
||||||
|
|
||||||
@arg('short_name', type=types.StringType)
|
|
||||||
@arg('value', eval_arg=False, function_only=True)
|
|
||||||
def expand_function_namespace(short_name, value):
|
|
||||||
fqns = examples.ns.definition.get_fqns(short_name)
|
|
||||||
if not fqns:
|
|
||||||
raise Exception(
|
|
||||||
"Namespace with alias '{0}' is unknown".format(short_name))
|
|
||||||
if not examples.ns.definition.validate(fqns, value.function_name):
|
|
||||||
raise Exception(
|
|
||||||
"Namespace '{0}' does not contain name '{1}'".format(fqns, value))
|
|
||||||
value.function_name = "{0}.{1}".format(fqns, value.function_name)
|
|
||||||
return value
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def register_in_context(context):
|
|
||||||
context.register_function(expand_property_namespace, 'operator_:')
|
|
||||||
context.register_function(expand_function_namespace, 'operator_:')
|
|
||||||
|
|
@ -1,60 +0,0 @@
|
|||||||
# Copyright (c) 2013 Mirantis, Inc.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
# not use this file except in compliance with the License. You may obtain
|
|
||||||
# a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
# License for the specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
|
|
||||||
import types
|
|
||||||
|
|
||||||
import containers
|
|
||||||
from examples.ns import definition
|
|
||||||
from examples import ns_functions
|
|
||||||
from yaql.tests import testdata
|
|
||||||
import yaql
|
|
||||||
|
|
||||||
|
|
||||||
# DEPRECATED. Use cli to run samples
|
|
||||||
|
|
||||||
context = yaql.create_context()
|
|
||||||
ns_functions.register_in_context(context)
|
|
||||||
data = testdata.data
|
|
||||||
|
|
||||||
definition.register_shortening('tst', 'com.examples.test')
|
|
||||||
definition.register_symbol('com.examples.test', 'Symbol')
|
|
||||||
definition.register_symbol('com.examples.test', 'Function')
|
|
||||||
|
|
||||||
context.register_function(testdata.process_customer, 'com.examples.test.Function')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
expression_list = [
|
|
||||||
# "$.services.join($.users, $1.yaql:owner=$2.id, dict('Service Name'=>$1.yaql:name,'User email'=>$2.email, 'Parent type'=>$1.yaql:parent_service))[$.'Parent type'=ex:Service0]",
|
|
||||||
# "range(0, 10 * random()).select(dict(num => $)).list()",
|
|
||||||
# "range(0).select(random()).takeWhile($ < 0.9).sum()",
|
|
||||||
# "$.users[0].tst:Function()"
|
|
||||||
"$.services"
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
parsed_list = [yaql.parse(expr) for expr in expression_list]
|
|
||||||
results = [expr.evaluate(data, context) for expr in parsed_list]
|
|
||||||
|
|
||||||
i = 1
|
|
||||||
for res in results:
|
|
||||||
print "result #{0}".format(i)
|
|
||||||
i += 1
|
|
||||||
if isinstance(res, containers.Iterable) and not isinstance(res, types.StringType):
|
|
||||||
for r in res:
|
|
||||||
print r
|
|
||||||
else:
|
|
||||||
print res
|
|
||||||
|
|
2
setup.py
2
setup.py
@ -19,7 +19,7 @@ setup(name='yaql',
|
|||||||
description="Yet Another Query Language",
|
description="Yet Another Query Language",
|
||||||
author='Mirantis, Inc.',
|
author='Mirantis, Inc.',
|
||||||
author_email='info@mirantis.com',
|
author_email='info@mirantis.com',
|
||||||
url='http://mirantis.com',
|
url='https://github.com/ativelkov/yaql',
|
||||||
install_requires=['ply'],
|
install_requires=['ply'],
|
||||||
entry_points={
|
entry_points={
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
|
@ -37,7 +37,7 @@ PROMPT = "yaql> "
|
|||||||
def main(context, show_tokens):
|
def main(context, show_tokens):
|
||||||
print "Yet Another Query Language - command-line query tool"
|
print "Yet Another Query Language - command-line query tool"
|
||||||
print "Version {0}".format(version)
|
print "Version {0}".format(version)
|
||||||
print "Copyright (c) 2013 Mirantis, Inc"
|
print "Copyright (c) 2014 Mirantis, Inc"
|
||||||
print
|
print
|
||||||
if not context.get_data():
|
if not context.get_data():
|
||||||
print "No data loaded into context "
|
print "No data loaded into context "
|
||||||
|
Loading…
Reference in New Issue
Block a user