Commit 5ae01d56 authored by Laurent Wouters's avatar Laurent Wouters
Browse files

Initial import

parents
\.idea
^build$
^dist$
\.egg-info$
^.tox$
^.cache$
\.pyc$
\.pyo$
\.bak$
\.old$
\~$
\#.*?\#$
\.swp$
^doc/book/en/apidoc$
\.old$
\.pybuild
cubicweb/server/test/data/slapd.conf
debian/python-cubicweb
debian/*.log
debian/*.substvars
debian/cubicweb-doc
debian/cubicweb
debian/files
syntax: regexp
.*/data.*/database/.*
.*/data/ldapdb/.*
.*/data/uicache/
.*/data/libpython/cubicweb_.*/i18n/.*\.po
^doc/html/
^doc/doctrees/
^doc/book/en/devweb/js_api/
^doc/_build
^doc/js_api/
test-results.xml
include *.py
include */*.py
recursive-include cubicweb_tsgen *.py
recursive-include cubicweb_tsgen/data *.gif *.png *.ico *.css *.js
recursive-include cubicweb_tsgen/i18n *.po
recursive-include cubicweb_tsgen/wdoc *
recursive-include test/data bootstrap_cubes *.py
include *.ini
recursive-include debian changelog compat control copyright rules
include cubicweb-tsgen.spec
===================
cubicweb-tsgen
===================
cubicweb-tsgen provides a cubicweb-ctl command in order to generate the Typescript interfaces for a YAMS schema.
Basic use in Python
-------------------
.. highlight:: bash
cubicweb-ctl tsgen myinstance
# for el5, force use of python2.6
%if 0%{?el5}
%define python python26
%define __python /usr/bin/python2.6
%else
%define python python
%define __python /usr/bin/python
%endif
%{!?_python_sitelib: %define _python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
Name: cubicweb-tsgen
Version: 0.1.0
Release: logilab.1%{?dist}
Summary: Typescript interface generator
Group: Applications/Internet
License: LGPL
Source0: cubicweb-tsgen-%{version}.tar.gz
BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
BuildRequires: %{python} %{python}-setuptools
Requires: cubicweb >= 3.27.0.dev0
Requires: %{python}-six >= 1.4.0
%description
Typescript interface generator
%prep
%setup -q -n cubicweb-tsgen-%{version}
%if 0%{?el5}
# change the python version in shebangs
find . -name '*.py' -type f -print0 | xargs -0 sed -i '1,3s;^#!.*python.*$;#! /usr/bin/python2.6;'
%endif
%install
%{__python} setup.py --quiet install --no-compile --prefix=%{_prefix} --root="$RPM_BUILD_ROOT"
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-, root, root)
%{_python_sitelib}/*
# copyright 2003-2019 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.
#
# CubicWeb is free software: you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option)
# any later version.
#
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
"""Generation of Typescript interfaces for a YAMS schema"""
import codecs
from cubicweb import cwctl
from cubicweb.cwconfig import CubicWebConfiguration as cwcfg
_PRIMITIVES = {
"String": "string",
"Password": "string",
"Int": "number",
"Float": "number",
"Boolean": "boolean",
"Time": "string",
"Date": "string",
"Datetime": "string",
"TZTime": "string",
"TZDatetime": "string",
"Bytes": "string",
"BigInt": "string",
"Decimal": "string",
"Interval": "string",
"Jsonb": "any"
}
class TsSchemaGenerator:
"""
Generator of Typescript interfaces for a YAMS schema
"""
def __init__(self, schema):
"""
Initializes this generator
:param schema: The input YAMS schema
"""
self.schema = schema
self.errors = []
self._slices = []
def _print(self, text):
"""
Prints a piece of text to the output
:param text: The piece of text
:return: Nothing
"""
self._slices.append(text)
def _handle_attribute(self, entity, relation):
"""
Handles an attribute for a entity type
:param entity: The type of entity
:param relation: The attribute
:return: Nothing
"""
if relation.description is not None and len(relation.description) > 0:
self._print(" /**\n")
self._print(" * %s\n" % relation.description)
self._print(" */\n")
name = relation.type
field_type = relation.objects(entity)[0].type
if field_type in _PRIMITIVES:
field_type = _PRIMITIVES[field_type]
else:
field_type = "string"
self._print(" %s: %s;\n" % (name, field_type))
def _handle_relation_subject(self, entity, relation):
"""
Handles a relation for a entity type (when the entity is the subject)
:param entity: The type of entity
:param relation: The relation
:return: Nothing
"""
objects = relation.objects(entity.type)
for object_type in objects:
if relation.description is not None and len(relation.description) > 0:
self._print(" /**\n")
self._print(" * %s\n" % relation.description)
self._print(" */\n")
name = relation.type
self._print(" %s_%s_%s: number[];\n" % (name, entity.type, object_type.type))
def _handle_relation_object(self, entity, relation):
"""
Handles a relation for a entity type (when the entity is the object)
:param entity: The type of entity
:param relation: The relation
:return: Nothing
"""
subjects = relation.subjects(entity.type)
for subject in subjects:
if relation.description is not None and len(relation.description) > 0:
self._print(" /**\n")
self._print(" * %s\n" % relation.description)
self._print(" */\n")
name = relation.type
self._print(" %s_%s_%s: number[];\n" % (name, subject.type, entity.type))
def _handle_entity_type(self, entity):
"""
Handles a type of entity
:param entity: The type of entity
:return: Nothing
"""
if entity.description is not None and len(entity.description) > 0:
self._print("/**\n")
self._print(" * %s\n" % entity.description)
self._print(" */\n")
self._print("export interface %s" % entity.type)
parent = entity.specializes()
if parent is not None:
self._print(" extends %s" % parent.type)
self._print(" {\n")
for relation in entity.subject_relations():
if relation.type == "eid":
self._handle_attribute(entity, relation)
elif relation.final:
self._handle_attribute(entity, relation)
else:
self._handle_relation_subject(entity, relation)
for relation in entity.object_relations():
self._handle_relation_object(entity, relation)
self._print("}\n\n")
def generate(self):
"""
Generates the Typescript interfaces
:return: The text for the Typescript interfaces
"""
entities = [entity for entity in self.schema.entities() if not entity.final]
entities.sort(key=lambda x: x.type)
for entity in entities:
self._handle_entity_type(entity)
return ''.join(self._slices)
class TsGenCommand(cwctl.InstanceCommand):
"""Generates the Typescript type interfaces for an instance
<instance>...
identifiers of the instances to consider. If no instance is
given, recompile for all registered instances.
"""
name = 'tsgen'
@staticmethod
def tsgen_instance(app_id):
"""
Generates the Typescript type interfaces for an instance
:param app_id: The identifier of the instance
:return: Nothing
"""
config = cwcfg.config_for(app_id)
config.quick_start = True # notify this is not a regular start
schema = config.repository().schema
errors = TsGenCommand.tsgen_schema(schema)
if errors:
print('\n'.join(errors))
@staticmethod
def tsgen_schema(schema):
"""
Generates the Typescript type interfaces for a YAMS schema
:param schema: The schema
:return: The errors, if any
"""
generator = TsSchemaGenerator(schema)
content = generator.generate()
file = codecs.open("schema.ts", "w", "utf-8")
file.write(content)
file.close()
return generator.errors
cwctl.CWCTL.register(TsGenCommand)
# pylint: disable=W0622
"""cubicweb-tsgen application packaging information"""
modname = 'cubicweb_tsgen'
distname = 'cubicweb-tsgen'
numversion = (0, 1, 0)
version = '.'.join(str(num) for num in numversion)
license = 'LGPL'
author = 'LOGILAB S.A. (Paris, FRANCE)'
author_email = 'contact@logilab.fr'
description = 'Typescript interface generator'
web = 'http://www.cubicweb.org/project/%s' % distname
__depends__ = {
'cubicweb': '>= 3.26.4'
}
__recommends__ = {}
classifiers = [
'Environment :: Web Environment',
'Framework :: CubicWeb',
'Programming Language :: Python',
'Programming Language :: JavaScript',
]
msgid ""
msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
msgid ""
msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
msgid ""
msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
cubicweb-graphql (0.1.0-1) UNRELEASED; urgency=low
* initial release
-- LOGILAB S.A. (Paris, FRANCE) <contact@logilab.fr> Thu, 21 Jun 2018 10:36:00 +0000
Source: cubicweb-tsgen
Section: web
Priority: optional
Maintainer: LOGILAB S.A. (Paris, FRANCE) <contact@logilab.fr>
Build-Depends:
debhelper (>= 7),
dh-python,
python (>= 2.6.5),
python-setuptools,
Standards-Version: 3.9.3
X-Python-Version: >= 2.6
Package: cubicweb-tsgen
Architecture: all
Depends:
python-cubicweb (>= 3.26.0),
python-six (>= 1.4.0),
${python:Depends},
${misc:Depends},
Description: Typescript interface generator
CubicWeb is a semantic web application framework.
.
Typescript interface generator
.
This package will install all the components you need to run an application
using the cubicweb-tsgen cube.
Upstream Author:
LOGILAB S.A. (Paris, FRANCE) <contact@logilab.fr>
Copyright:
Copyright (c) 2019 LOGILAB S.A. (Paris, FRANCE).
http://www.logilab.fr -- mailto:contact@logilab.fr
#!/usr/bin/make -f
%:
dh $@ --with python2
This diff is collapsed.
#!/usr/bin/env python
# pylint: disable=W0142,W0403,W0404,W0613,W0622,W0622,W0704,R0904,C0103,E0611
#
# copyright 2003-2018 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of a cubicweb-tsgen.
#
# CubicWeb is free software: you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option)
# any later version.
#
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
"""cubicweb_tsgen setup module using data from
cubicweb_tsgen/__pkginfo__.py file
"""
from os.path import join, dirname
from setuptools import find_packages, setup
here = dirname(__file__)
# load metadata from the __pkginfo__.py file so there is no risk of conflict
# see https://packaging.python.org/en/latest/single_source_version.html
pkginfo = join(here, 'cubicweb_tsgen', '__pkginfo__.py')
__pkginfo__ = {}
with open(pkginfo) as f:
exec(f.read(), __pkginfo__)
# get required metadatas
distname = __pkginfo__['distname']
version = __pkginfo__['version']
license = __pkginfo__['license']
description = __pkginfo__['description']
web = __pkginfo__['web']
author = __pkginfo__['author']
author_email = __pkginfo__['author_email']
classifiers = __pkginfo__['classifiers']
with open(join(here, 'README.rst')) as f:
long_description = f.read()
# get optional metadatas
data_files = __pkginfo__.get('data_files', None)
dependency_links = __pkginfo__.get('dependency_links', ())
requires = {}
for entry in ("__depends__",): # "__recommends__"):
requires.update(__pkginfo__.get(entry, {}))
install_requires = ["{0} {1}".format(d, v and v or "").strip()
for d, v in requires.items()]
setup(
name=distname,
version=version,
license=license,
description=description,
long_description=long_description,
author=author,
author_email=author_email,
url=web,
classifiers=classifiers,
packages=find_packages(exclude=['test']),
install_requires=install_requires,
include_package_data=True,
entry_points={
'cubicweb.cubes': [
'tsgen=cubicweb_tsgen',
],
},
zip_safe=False
)
[tox]
envlist = py27,py34,flake8
[testenv]
deps =
pytest
commands =
{envpython} -m pytest {posargs:test}
[testenv:flake8]
skip_install = true
whitelist_externals =
flake8
deps =
flake8
commands = flake8
[flake8]
exclude = cubicweb_tsgen/migration/*,test/data/*,.tox/*
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment