Merge lp:~rvb/maas/fixjsenum into lp:~maas-committers/maas/trunk

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 2584
Proposed branch: lp:~rvb/maas/fixjsenum
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 37 lines (+18/-2)
1 file modified
src/maasserver/utils/jsenums.py (+18/-2)
To merge this branch: bzr merge lp:~rvb/maas/fixjsenum
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Review via email: mp+227673@code.launchpad.net

Commit message

Add a copy of map_enum in jsenum so that the packaging (which uses jsenum) doesn't have the need to install all the dependencies required by importing from the provisioningserver code.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/maasserver/utils/jsenums.py'
--- src/maasserver/utils/jsenums.py 2014-07-17 12:32:32 +0000
+++ src/maasserver/utils/jsenums.py 2014-07-22 07:10:57 +0000
@@ -34,8 +34,6 @@
34import sys34import sys
35from textwrap import dedent35from textwrap import dedent
3636
37from provisioningserver.utils import map_enum
38
39# Header. Will be written on top of the output.37# Header. Will be written on top of the output.
40header = dedent("""\38header = dedent("""\
41/*39/*
@@ -80,6 +78,24 @@
80 return get_enum_classes(namespace)78 return get_enum_classes(namespace)
8179
8280
81# This method is duplicated from provisioningserver/utils/__init__.py
82# because jsenums is used by the packaging to build the JS file and
83# we don't want to force the packaging to require all the dependencies
84# that using provisioningserver/utils/__init__.py would imply.
85def map_enum(enum_class):
86 """Map out an enumeration class as a "NAME: value" dict."""
87 # Filter out anything that starts with '_', which covers private and
88 # special methods. We can make this smarter later if we start using
89 # a smarter enumeration base class etc. Or if we switch to a proper
90 # enum mechanism, this function will act as a marker for pieces of
91 # code that should be updated.
92 return {
93 key: value
94 for key, value in vars(enum_class).items()
95 if not key.startswith('_')
96 }
97
98
83def serialize_enum(enum):99def serialize_enum(enum):
84 """Represent a MAAS enum class in JavaScript."""100 """Represent a MAAS enum class in JavaScript."""
85 definitions = json.dumps(map_enum(enum), indent=4, sort_keys=True)101 definitions = json.dumps(map_enum(enum), indent=4, sort_keys=True)