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
1=== modified file 'src/maasserver/utils/jsenums.py'
2--- src/maasserver/utils/jsenums.py 2014-07-17 12:32:32 +0000
3+++ src/maasserver/utils/jsenums.py 2014-07-22 07:10:57 +0000
4@@ -34,8 +34,6 @@
5 import sys
6 from textwrap import dedent
7
8-from provisioningserver.utils import map_enum
9-
10 # Header. Will be written on top of the output.
11 header = dedent("""\
12 /*
13@@ -80,6 +78,24 @@
14 return get_enum_classes(namespace)
15
16
17+# This method is duplicated from provisioningserver/utils/__init__.py
18+# because jsenums is used by the packaging to build the JS file and
19+# we don't want to force the packaging to require all the dependencies
20+# that using provisioningserver/utils/__init__.py would imply.
21+def map_enum(enum_class):
22+ """Map out an enumeration class as a "NAME: value" dict."""
23+ # Filter out anything that starts with '_', which covers private and
24+ # special methods. We can make this smarter later if we start using
25+ # a smarter enumeration base class etc. Or if we switch to a proper
26+ # enum mechanism, this function will act as a marker for pieces of
27+ # code that should be updated.
28+ return {
29+ key: value
30+ for key, value in vars(enum_class).items()
31+ if not key.startswith('_')
32+ }
33+
34+
35 def serialize_enum(enum):
36 """Represent a MAAS enum class in JavaScript."""
37 definitions = json.dumps(map_enum(enum), indent=4, sort_keys=True)