Skip to content

Commit

Permalink
Dev: Remove crmsh/ordereddict.py (#1485)
Browse files Browse the repository at this point in the history
It's sufficient to use built-in dict under python 3.7+ as it maintains
insertion order.
  • Loading branch information
liangxin1300 authored Jul 11, 2024
2 parents ae5fff2 + 5fc6e77 commit 72c64e6
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 161 deletions.
9 changes: 4 additions & 5 deletions crmsh/cibconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from . import utils
from . import cibverify
from . import parse
from . import ordereddict
from . import orderedset
from . import cibstatus
from . import crm_gv
Expand Down Expand Up @@ -1352,7 +1351,7 @@ class Op(object):
def __init__(self, op_name, prim, node=None):
self.prim = prim
self.node = node
self.attr_d = ordereddict.odict()
self.attr_d = {}
self.attr_d["name"] = op_name
if self.node is not None:
self.xml2dict()
Expand Down Expand Up @@ -2080,7 +2079,7 @@ def can_be_renamed(self):

def _repr_cli_head(self, format_mode):
s = clidisplay.keyword(self.obj_type)
d = ordereddict.odict()
d = {}
for c in self.node.iterchildren("fencing-level"):
if "target-pattern" in c.attrib:
target = (None, c.get("target-pattern"))
Expand All @@ -2091,7 +2090,7 @@ def _repr_cli_head(self, format_mode):
if target not in d:
d[target] = {}
d[target][c.get("index")] = c.get("devices")
dd = ordereddict.odict()
dd = {}
for target in list(d.keys()):
sorted_keys = sorted([int(i) for i in list(d[target].keys())])
dd[target] = [d[target][str(x)] for x in sorted_keys]
Expand Down Expand Up @@ -2284,7 +2283,7 @@ def get_default_timeout():


# generate a translation cli -> tag
backtrans = ordereddict.odict((item[0], key) for key, item in cib_object_map.items())
backtrans = dict((item[0], key) for key, item in cib_object_map.items())


def default_id_for_tag(tag):
Expand Down
12 changes: 4 additions & 8 deletions crmsh/constants.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Copyright (C) 2008-2011 Dejan Muhamedagic <[email protected]>
# See COPYING for license information.

from .ordereddict import odict


cib_cli_map = {
"node": "node",
"primitive": "primitive",
Expand Down Expand Up @@ -64,23 +60,23 @@
"deny": "deny",
}
acl_rule_names = ("read", "write", "deny")
acl_spec_map = odict({
acl_spec_map = {
"xpath": "xpath",
"ref": "ref",
"tag": "tag",
"attribute": "attribute",
})
}
# ACLs were rewritten in pacemaker 1.1.12
# this is the new acl syntax
acl_spec_map_2 = odict({
acl_spec_map_2 = {
"xpath": "xpath",
"ref": "reference",
"reference": "reference",
"tag": "object-type",
"type": "object-type",
"attr": "attribute",
"attribute": "attribute"
})
}

acl_spec_map_2_rev = (('xpath', 'xpath'),
('reference', 'ref'),
Expand Down
11 changes: 5 additions & 6 deletions crmsh/crm_gv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from . import config
from . import tmpfiles
from . import utils
from .ordereddict import odict
from . import log


Expand Down Expand Up @@ -38,9 +37,9 @@ def __init__(self, ident=None):
self.nodes = {}
self.edges = []
self.subgraphs = []
self.node_attrs = odict()
self.attrs = odict()
self.graph_attrs = odict()
self.node_attrs = {}
self.attrs = {}
self.graph_attrs = {}
self.edge_attrs = []
self.top_nodes = []
self.norank_nodes = []
Expand All @@ -54,7 +53,7 @@ def new_graph_attr(self, attr, v):
def new_attr(self, n, attr_n, attr_v):
ident = self.gv_id(n)
if ident not in self.attrs:
self.attrs[ident] = odict()
self.attrs[ident] = {}
self.attrs[ident][attr_n] = attr_v

def new_node(self, n, top_node=False, norank=False):
Expand All @@ -81,7 +80,7 @@ def new_edge(self, e):
continue
self.nodes[node] = i
self.edges.append(ne)
self.edge_attrs.append(odict())
self.edge_attrs.append({})
return len(self.edges)-1

def new_edge_attr(self, e_id, attr_n, attr_v):
Expand Down
11 changes: 5 additions & 6 deletions crmsh/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from .utils import page_string
from . import config
from . import clidisplay
from .ordereddict import odict
from . import log


Expand Down Expand Up @@ -139,9 +138,9 @@ def __repr__(self):
# _LOADED is set to True when an attempt
# has been made (so it won't be tried again)
_LOADED = False
_TOPICS = odict()
_LEVELS = odict()
_COMMANDS = odict()
_TOPICS = {}
_LEVELS = {}
_COMMANDS = {}

_TOPICS["Overview"] = HelpEntry("Available help topics and commands", generated=True)
_TOPICS["Topics"] = HelpEntry("Available help topics", generated=True)
Expand Down Expand Up @@ -300,7 +299,7 @@ def add_help(entry, topic=None, level=None, command=None):
if level not in _LEVELS:
_LEVELS[level] = HelpEntry("No description available", generated=True)
if level not in _COMMANDS:
_COMMANDS[level] = odict()
_COMMANDS[level] = {}
lvl = _COMMANDS[level]
if command not in lvl or lvl[command] is _DEFAULT:
lvl[command] = entry
Expand Down Expand Up @@ -360,7 +359,7 @@ def process(entry):
elif entry['type'] == 'command':
lvl = entry['level']
if lvl not in _COMMANDS:
_COMMANDS[lvl] = odict()
_COMMANDS[lvl] = {}
helpobj.set_long_lazy_load_source(entry['level'], entry['name'], entry['from_cli'])
_COMMANDS[lvl][name] = helpobj

Expand Down
133 changes: 0 additions & 133 deletions crmsh/ordereddict.py

This file was deleted.

5 changes: 2 additions & 3 deletions crmsh/ui_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ def do_convert(self, context, workflow, outdir=".", category="basic"):
"""
import yaml
import os
from .ordereddict import OrderedDict

def flatten(script):
if not isinstance(script, dict):
Expand All @@ -373,7 +372,7 @@ def scriptsorter(item):
order = ["version", "name", "category", "shortdesc", "longdesc", "include", "parameters", "steps", "actions"]
return order.index(item[0])

yaml.add_representer(OrderedDict, order_rep)
yaml.add_representer(dict, order_rep)
fromscript = os.path.abspath(workflow)
tgtdir = outdir

Expand All @@ -386,7 +385,7 @@ def scriptsorter(item):
del script["dir"]
script["actions"] = [{"cib": "\n\n".join([action["cib"] for action in script["actions"]])}]

script = OrderedDict(sorted(list(script.items()), key=scriptsorter))
script = dict(sorted(list(script.items()), key=scriptsorter))
if script is not None:
try:
os.mkdir(os.path.join(tgtdir, name))
Expand Down

0 comments on commit 72c64e6

Please sign in to comment.