Skip to content

Commit e06e02f

Browse files
committed
run black
1 parent cb948af commit e06e02f

File tree

8 files changed

+53
-63
lines changed

8 files changed

+53
-63
lines changed

netbox_changelog_diff_plugin/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ChangeLogDiffConfig(PluginConfig):
1515
version = "version"
1616
base_url = "netbox_changelog_diff_plugin"
1717
default_settings = {
18-
'change_log_format': 'yaml',
18+
"change_log_format": "yaml",
1919
}
2020

2121

netbox_changelog_diff_plugin/forms.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
11
from django import forms
2-
3-
4-
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
from django.db import models
22
from django.urls import reverse
33
from netbox.models import NetBoxModel
4-
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
import django_tables2 as tables
22
from netbox.tables import NetBoxTable, ChoiceFieldColumn
3-
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
from netbox.plugins import PluginTemplateExtension
22
from .utilities.html_differ import styled_diff
33

4-
class ChangeLogDiffTemplateExtension(PluginTemplateExtension):
5-
model = 'extras.objectchange'
64

5+
class ChangeLogDiffTemplateExtension(PluginTemplateExtension):
6+
model = "extras.objectchange"
77

88
def full_width_page(self):
9-
prechange_data = self.context['object'].prechange_data
10-
postchange_data = self.context['object'].postchange_data
9+
prechange_data = self.context["object"].prechange_data
10+
postchange_data = self.context["object"].postchange_data
1111

1212
leftrightdiffhtml = styled_diff(
13-
prechange_data or dict(),
13+
prechange_data or dict(),
1414
postchange_data or dict(),
1515
)
16-
return self.render('netbox_changelog_diff_plugin/changelogdiff.html',
17-
extra_context={
18-
'leftrightdiffhtml': leftrightdiffhtml
19-
})
16+
return self.render(
17+
"netbox_changelog_diff_plugin/changelogdiff.html", extra_context={"leftrightdiffhtml": leftrightdiffhtml}
18+
)
19+
2020

2121
template_extensions = [ChangeLogDiffTemplateExtension]

netbox_changelog_diff_plugin/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
from netbox.views.generic import ObjectChangeLogView
33

44

5-
urlpatterns = []
5+
urlpatterns = []

netbox_changelog_diff_plugin/utilities/html_differ.py

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,23 @@ class DefaultLexer(RegexLexer):
1717
Simply lex each line as a token.
1818
"""
1919

20-
name = 'Default'
21-
aliases = ['default']
22-
filenames = ['*']
20+
name = "Default"
21+
aliases = ["default"]
22+
filenames = ["*"]
2323

2424
tokens = {
25-
'root': [
26-
(r'.*\n', Text),
25+
"root": [
26+
(r".*\n", Text),
2727
]
2828
}
2929

3030

3131
class DiffHtmlFormatter(HtmlFormatter):
3232
"""
33-
Formats a single source file with pygments and adds diff highlights based on the
33+
Formats a single source file with pygments and adds diff highlights based on the
3434
diff details given.
3535
"""
36+
3637
isLeft = False
3738
diffs = None
3839

@@ -51,25 +52,21 @@ def getDiffLineNos(self):
5152
if self.isLeft:
5253
if change:
5354
if isinstance(left_no, int) and isinstance(right_no, int):
54-
no = '<span class="lineno_q lineno_leftchange">' + \
55-
str(left_no) + "</span>"
55+
no = '<span class="lineno_q lineno_leftchange">' + str(left_no) + "</span>"
5656
elif isinstance(left_no, int) and not isinstance(right_no, int):
57-
no = '<span class="lineno_q lineno_leftdel">' + \
58-
str(left_no) + "</span>"
57+
no = '<span class="lineno_q lineno_leftdel">' + str(left_no) + "</span>"
5958
elif not isinstance(left_no, int) and isinstance(right_no, int):
6059
no = '<span class="lineno_q lineno_leftadd"> </span>'
6160
else:
6261
no = '<span class="lineno_q">' + str(left_no) + "</span>"
6362
else:
6463
if change:
6564
if isinstance(left_no, int) and isinstance(right_no, int):
66-
no = '<span class="lineno_q lineno_rightchange">' + \
67-
str(right_no) + "</span>"
65+
no = '<span class="lineno_q lineno_rightchange">' + str(right_no) + "</span>"
6866
elif isinstance(left_no, int) and not isinstance(right_no, int):
6967
no = '<span class="lineno_q lineno_rightdel"> </span>'
7068
elif not isinstance(left_no, int) and isinstance(right_no, int):
71-
no = '<span class="lineno_q lineno_rightadd">' + \
72-
str(right_no) + "</span>"
69+
no = '<span class="lineno_q lineno_rightadd">' + str(right_no) + "</span>"
7370
else:
7471
no = '<span class="lineno_q">' + str(right_no) + "</span>"
7572

@@ -79,7 +76,7 @@ def getDiffLineNos(self):
7976

8077
def _wrap_code(self, source):
8178
source = list(source)
82-
yield 0, ''
79+
yield 0, ""
8380

8481
for idx, ((left_no, left_line), (right_no, right_line), change) in enumerate(self.diffs):
8582
# print idx, ((left_no, left_line),(right_no, right_line),change)
@@ -132,7 +129,7 @@ def _wrap_code(self, source):
132129
except:
133130
# print "WARNING! failed to enumerate diffs fully!"
134131
pass # this is expected sometimes
135-
yield 0, '\n'
132+
yield 0, "\n"
136133

137134
def _wrap_tablelinenos(self, inner):
138135
dummyoutfile = io.StringIO()
@@ -150,11 +147,9 @@ def _wrap_tablelinenos(self, inner):
150147
aln = self.anchorlinenos
151148
nocls = self.noclasses
152149

153-
154-
155150
yield 0, (f'<table width="100%" class="{self.cssclass}"><tr></div></td><td class="code">')
156151
yield 0, dummyoutfile.getvalue()
157-
yield 0, '</td></tr></table>'
152+
yield 0, "</td></tr></table>"
158153

159154

160155
class CodeDiff(object):
@@ -164,26 +159,24 @@ class CodeDiff(object):
164159
"""
165160

166161
def __init__(self, fromtxt, totxt, name=None):
167-
168162
self.fromlines = [n + "\n" for n in fromtxt.split("\n")]
169163
self.leftcode = "".join(self.fromlines)
170164

171-
172165
self.tolines = [n + "\n" for n in totxt.split("\n")]
173166
self.rightcode = "".join(self.tolines)
174167

175-
def getDiffDetails(self, fromdesc='', todesc='', context=False, numlines=5, tabSize=8):
168+
def getDiffDetails(self, fromdesc="", todesc="", context=False, numlines=5, tabSize=8):
176169
# change tabs to spaces before it gets more difficult after we insert
177170
# markkup
178171
def expand_tabs(line):
179172
# hide real spaces
180-
line = line.replace(' ', '\0')
173+
line = line.replace(" ", "\0")
181174
# expand tabs into spaces
182175
line = line.expandtabs(tabSize)
183176
# replace spaces from expanded tabs back into tab characters
184177
# (we'll replace them with markup after we do differencing)
185-
line = line.replace(' ', '\t')
186-
return line.replace('\0', ' ').rstrip('\n')
178+
line = line.replace(" ", "\t")
179+
return line.replace("\0", " ").rstrip("\n")
187180

188181
self.fromlines = [expand_tabs(line) for line in self.fromlines]
189182
self.tolines = [expand_tabs(line) for line in self.tolines]
@@ -194,29 +187,29 @@ def expand_tabs(line):
194187
else:
195188
context_lines = None
196189

197-
diffs = difflib._mdiff(self.fromlines, self.tolines, context_lines,
198-
linejunk=None, charjunk=difflib.IS_CHARACTER_JUNK)
190+
diffs = difflib._mdiff(
191+
self.fromlines, self.tolines, context_lines, linejunk=None, charjunk=difflib.IS_CHARACTER_JUNK
192+
)
199193
return list(diffs)
200194

201195
def format(self, verbose=False):
202-
self.diffs = self.getDiffDetails('a', 'b')
196+
self.diffs = self.getDiffDetails("a", "b")
203197

204198
if verbose:
205199
for diff in self.diffs:
206200
print("%-6s %-80s %-80s" % (diff[2], diff[0], diff[1]))
207201

208-
fields = ((self.leftcode, True),
209-
(self.rightcode, False))
202+
fields = ((self.leftcode, True), (self.rightcode, False))
210203

211204
codeContents = []
212-
for (code, isLeft) in fields:
213-
214-
inst = DiffHtmlFormatter(isLeft,
215-
self.diffs,
216-
nobackground=False,
217-
linenos=True,
218-
#style=options.syntax_css
219-
)
205+
for code, isLeft in fields:
206+
inst = DiffHtmlFormatter(
207+
isLeft,
208+
self.diffs,
209+
nobackground=False,
210+
linenos=True,
211+
# style=options.syntax_css
212+
)
220213

221214
self.lexer = DefaultLexer()
222215

@@ -225,27 +218,28 @@ def format(self, verbose=False):
225218
codeContents.append(formatted)
226219

227220
answers = {
228-
"left": codeContents[0],
229-
"right": codeContents[1],
221+
"left": codeContents[0],
222+
"right": codeContents[1],
230223
}
231224

232225
return answers
233226

227+
234228
def styled_diff(old, new):
235229
"""
236230
returns styled output
237231
"""
238232

239233
if "last_updated" in old:
240-
old.pop("last_updated")
234+
old.pop("last_updated")
241235
if "last_updated" in new:
242236
new.pop("last_updated")
243237

244-
if get_plugin_setting('change_log_format') == 'yaml':
238+
if get_plugin_setting("change_log_format") == "yaml":
245239
# old['output_format'] = 'yaml'
246240
old = yaml.dump(old, sort_keys=False)
247241
new = yaml.dump(new, sort_keys=False)
248-
elif get_plugin_setting('change_log_format') == 'json':
242+
elif get_plugin_setting("change_log_format") == "json":
249243
# old['output_format'] = 'json'
250244
old = json.dumps(old, indent=2)
251245
new = json.dumps(new, indent=2)
@@ -255,4 +249,4 @@ def styled_diff(old, new):
255249
new = yaml.dump(new, sort_keys=False)
256250

257251
codeDiff = CodeDiff(old, new)
258-
return codeDiff.format()
252+
return codeDiff.format()

netbox_changelog_diff_plugin/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django.conf import settings
22

3+
34
def get_plugin_setting(setting_name):
4-
plugin_settings = settings.PLUGINS_CONFIG['netbox_changelog_diff_plugin']
5-
assert setting_name in plugin_settings, f'Setting {setting_name} not supported'
6-
return plugin_settings[setting_name]
5+
plugin_settings = settings.PLUGINS_CONFIG["netbox_changelog_diff_plugin"]
6+
assert setting_name in plugin_settings, f"Setting {setting_name} not supported"
7+
return plugin_settings[setting_name]

0 commit comments

Comments
 (0)