Skip to content

Commit

Permalink
format code with black
Browse files Browse the repository at this point in the history
  • Loading branch information
tiltingpenguin committed Dec 12, 2022
1 parent bf839cc commit 3b2cf5f
Show file tree
Hide file tree
Showing 12 changed files with 465 additions and 342 deletions.
71 changes: 45 additions & 26 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,57 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('..'))

sys.path.insert(0, os.path.abspath(".."))


# -- Project information -----------------------------------------------------

project = 'libcobblersignatures'
copyright = '2020, The Cobbler Project Authors'
author = 'The Cobbler Project Authors'
project = "libcobblersignatures"
copyright = "2020, The Cobbler Project Authors"
author = "The Cobbler Project Authors"

# The full version, including alpha/beta/rc tags
release = '0.0.1'
release = "0.0.1"


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be extensions coming with Sphinx (named
# 'sphinx.ext.*') or your custom ones.
extensions = [
'sphinx.ext.autosectionlabel',
'sphinx.ext.autodoc'
]
extensions = ["sphinx.ext.autosectionlabel", "sphinx.ext.autodoc"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# List of patterns, relative to source directory, that match files and directories to ignore when looking for source
# files. This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for a list of builtin themes.
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# Add any paths that contain custom static files (such as style sheets) here, relative to this directory. They are
# copied after the builtin static files, so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# -- Options for LaTeX output ------------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
'papersize': 'a4paper',

"papersize": "a4paper",
# The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
# 'preamble': '',

# Latex figure (float) alignment
# 'figure_align': 'htbp',
}
Expand All @@ -76,26 +71,50 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'libcobblersignatures.tex', 'libcobblersignatures Documentation',
'Enno Gotthold', 'manual'),
(
master_doc,
"libcobblersignatures.tex",
"libcobblersignatures Documentation",
"Enno Gotthold",
"manual",
),
]

# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('cli', 'libcobblersignatures', u'libcobblersignatures CLI Documentation', [u'Enno Gotthold'], 1),
('json-specification', 'signatures.json Spec', u'signatures.json Documentation', [u'Enno Gotthold'], 5),
(
"cli",
"libcobblersignatures",
"libcobblersignatures CLI Documentation",
["Enno Gotthold"],
1,
),
(
"json-specification",
"signatures.json Spec",
"signatures.json Documentation",
["Enno Gotthold"],
5,
),
]

# -- Options for Texinfo output ----------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author, dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'libcobblersignatures', 'libcobblersignatures Documentation', author, 'libcobblersignatures',
'Docs for the library which powers the Distro import of Cobbler.', 'Miscellaneous'),
(
master_doc,
"libcobblersignatures",
"libcobblersignatures Documentation",
author,
"libcobblersignatures",
"Docs for the library which powers the Distro import of Cobbler.",
"Miscellaneous",
),
]


Expand All @@ -117,4 +136,4 @@
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']
epub_exclude_files = ["search.html"]
31 changes: 20 additions & 11 deletions libcobblersignatures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def _importsignaturesfile(self, filepath: str):
:param filepath: The relative or absolute path. Additionally this may be all path variations which are accepted
by the Python ``open()`` function.
"""
with open(filepath, 'r') as f:
with open(filepath, "r") as f:
self.signaturesjson = f.read()

def _importsignaturesurl(self, url: str):
Expand All @@ -106,9 +106,11 @@ def _importsignaturesurl(self, url: str):
"""
response = urllib.request.urlopen(url)
data = response.read()
self.signaturesjson = data.decode('utf-8')
self.signaturesjson = data.decode("utf-8")

def __prepare_export_output(self, sort_keys: bool = False, indent: Union[None, int] = None) -> str:
def __prepare_export_output(
self, sort_keys: bool = False, indent: Union[None, int] = None
) -> str:
"""
Convert the internal data to a JSON. Only for internal usage.
Expand All @@ -118,8 +120,13 @@ def __prepare_export_output(self, sort_keys: bool = False, indent: Union[None, i
value = {breed.name: breed.encode() for breed in self.osbreeds}
return json.dumps({self._rootkey: value}, sort_keys=sort_keys, indent=indent)

def exportsignatures(self, export_type: ExportTypes, target: str = "", sort_keys: bool = False,
indent: Union[None, int] = None):
def exportsignatures(
self,
export_type: ExportTypes,
target: str = "",
sort_keys: bool = False,
indent: Union[None, int] = None,
):
"""
This is the main export function.
Expand All @@ -139,13 +146,17 @@ def exportsignatures(self, export_type: ExportTypes, target: str = "", sort_keys

if export_type == ExportTypes.FILE:
if not target:
raise ValueError("Please provide a path if your want to export to a file!")
raise ValueError(
"Please provide a path if your want to export to a file!"
)
with open(target, "w") as f:
f.write(self.__prepare_export_output(sort_keys, indent))
elif export_type == ExportTypes.STRING:
return self.__prepare_export_output(sort_keys, indent)
else:
raise ValueError("Please use on of the two given options for the export type!")
raise ValueError(
"Please use on of the two given options for the export type!"
)

def jsontomodels(self):
"""
Expand All @@ -155,7 +166,7 @@ def jsontomodels(self):
missing_rootkey = object()
breeds = self.signaturesjson.get(self._rootkey, missing_rootkey)
if breeds is missing_rootkey:
raise AttributeError("Missing Rootkey \"" + self._rootkey + "\".")
raise AttributeError('Missing Rootkey "' + self._rootkey + '".')
for key in breeds:
breed = OsBreed(key)
breed.decode(breeds[key])
Expand All @@ -168,7 +179,7 @@ def addosbreed(self, name: str):
:param name: The name of the new breed. Must not exist in the currently loaded models.
"""
if name in [x.name for x in self.osbreeds]:
raise ValueError("Breed \"%s\" already in the list of breeds!" % name)
raise ValueError('Breed "%s" already in the list of breeds!' % name)
self.osbreeds.append(OsBreed(name))

def addosversion(self, breedindex: int, versionname: str, versiondata):
Expand Down Expand Up @@ -217,5 +228,3 @@ def get_breed_index_by_name(self, name: str) -> int:
if name == self.osbreeds[index].name:
return index
return -1


0 comments on commit 3b2cf5f

Please sign in to comment.