CORD-2648 convert core attics to decl
Change-Id: I7146244bfa468bbd9c9bba77708262749842aa53
diff --git a/lib/xos-genx/xosgenx/generator.py b/lib/xos-genx/xosgenx/generator.py
old mode 100755
new mode 100644
index 33e96b1..cc00742
--- a/lib/xos-genx/xosgenx/generator.py
+++ b/lib/xos-genx/xosgenx/generator.py
@@ -111,10 +111,9 @@
print "Saved: %s" % file_name
@staticmethod
- def _write_file_per_model(rendered, dir, extension, quiet):
+ def _write_file_per_model(rendered, dir, suffix, quiet):
for m in rendered:
-
- file_name = "%s/%s.%s" % (dir, m.lower(), extension)
+ file_name = "%s/%s%s" % (dir, m.lower(), suffix)
if not rendered[m]:
if quiet == False:
print "Not saving %s as it is empty" % file_name
@@ -186,7 +185,7 @@
# Validating
if args.write_to_file == 'single' and args.dest_file is None:
raise Exception("[XosGenX] write_to_file option is specified as 'single' but no dest_file is provided")
- if args.write_to_file == 'model' and args.dest_extension is None:
+ if args.write_to_file == 'model' and (args.dest_extension is None):
raise Exception("[XosGenX] write_to_file option is specified as 'model' but no dest_extension is provided")
if args.output is not None and not os.path.isabs(args.output):
@@ -262,7 +261,11 @@
"options": v.options
}
)
- XOSProcessor._write_file_per_model(rendered, args.output, args.dest_extension, args.quiet)
+ if (str(v.options.get("legacy", "false")).strip('"').lower() == "true"):
+ suffix = "_decl." + args.dest_extension
+ else:
+ suffix = "." + args.dest_extension
+ XOSProcessor._write_file_per_model(rendered, args.output, suffix, args.quiet)
else:
rendered = template.render(
{"proto":
diff --git a/lib/xos-genx/xosgenx/jinja2_extensions/base.py b/lib/xos-genx/xosgenx/jinja2_extensions/base.py
index f8224b2..dd19bd8 100644
--- a/lib/xos-genx/xosgenx/jinja2_extensions/base.py
+++ b/lib/xos-genx/xosgenx/jinja2_extensions/base.py
@@ -272,3 +272,9 @@
return list
else:
return False
+
+def xproto_is_true(x):
+ # TODO: Audit xproto and make specification of trueness more uniform
+ if (x==True) or (x=="True") or (x=='"True"'):
+ return True
+ return False
diff --git a/lib/xos-genx/xosgenx/targets/django.xtarget b/lib/xos-genx/xosgenx/targets/django.xtarget
index ca81240..8ef8e5f 100644
--- a/lib/xos-genx/xosgenx/targets/django.xtarget
+++ b/lib/xos-genx/xosgenx/targets/django.xtarget
@@ -1,6 +1,23 @@
+{%- if options.legacy =='"True"' -%}
+{%- set legacy_tag = '_decl' -%}
+{%- set legacy = True -%}
+{%- else -%}
+{%- set legacy_tag = '' -%}
+{%- set legacy = False -%}
+{%- endif -%}
{% for m in proto.messages %}{% if not m.options.skip_django -%}
+{% if legacy %}
+{# handle models that use custom headers rather than deriving from xosbase #}
+{% if m.options.custom_header %}
+from {{ m.options.custom_header|replace('"','') }} import *
+{% else %}
+from core.models.xosbase import *
+{% endif %}
+{% else %}
{% if file_exists(xproto_base_name(m.name)|lower+'_header.py') -%}from {{xproto_base_name(m.name)|lower }}_header import *{%- else -%}from header import *{% endif %}
{% if file_exists(xproto_base_name(m.name)|lower+'_top.py') -%}{{ include_file(xproto_base_name(m.name)|lower+'_top.py') }} {% endif %}
+{% endif %}
+
{%- for l in m.links %}
{% if l.peer.name != m.name %}
@@ -24,7 +41,7 @@
{{ xproto_fol_to_python_validator(policy, proto.policies[policy], m, error) }}
{% endfor %}
-class {{ m.name }}{{ xproto_base_def(m.name, m.bases) }}:
+class {{ m.name }}{{ legacy_tag }}{{ xproto_base_def(m.name, m.bases) }}:
plural_name = "{{ xproto_pluralize(m) }}"
{# {% if m.options.no_sync or m.options.no_policy %}#}
@@ -53,11 +70,16 @@
{%- endfor %}
# Meta
+ class Meta:
{%- set uniques = xproto_field_graph_components(m.fields) %}
{%- if uniques %}
- class Meta:
unique_together = {{ xproto_tuplify(uniques) }}
{%- endif %}
+ {%- if xproto_is_true(m.options.abstract) %}
+ abstract=True
+ {%- endif %}
+ pass
+
{% if file_exists(m.name|lower + '_model.py') -%}{{ include_file(m.name|lower + '_model.py') | indent(width=2)}}{%- endif %}
pass
@@ -75,7 +97,7 @@
{% for policy,error in xproto_validations(m.options) %}
policy_{{policy}}_validator(self, None)
{% endfor %}
- super({{ m.name }}, self).save(*args, **kwds)
+ super({{ m.name }}{{ legacy_tag }}, self).save(*args, **kwds)
def can_access(self, ctx):
{% if m.policy %}