cyrusimap / cyrus-imapd

Cyrus IMAP is an email, contacts and calendar server
http://cyrusimap.org
Other
524 stars 145 forks source link

docsrc/: be more pythonic #2210

Open dilyanpalauzov opened 6 years ago

dilyanpalauzov commented 6 years ago
diff --git a/docsrc/conf.py b/docsrc/conf.py
--- a/docsrc/conf.py
+++ b/docsrc/conf.py
@@ -302,23 +302,20 @@ for tuple in pathset:
     os.chdir(tuple[0])
     for rstfile in glob.glob("*.rst"):
         author = [("The Cyrus Team")]
-        orphan = 'False';
         with io.open(rstfile,'r',encoding="utf8") as f:
             for line in f:
                 if line.startswith(':orphan:'):
-                    orphan = 'True';
-                    break;
+                    break
                 if line.startswith('.. author: '):
                     author.append(line[11: len(line.strip())])
-            f.close()
-        if orphan == 'False':
-            man_pages.append(
-                (os.path.splitext(os.path.join(tuple[0],rstfile))[0],
-                os.path.splitext(rstfile)[0],
-                u'Cyrus IMAP documentation',
-                author,
-                tuple[1])
-                )
+            else:
+                man_pages.append(
+                    (os.path.splitext(os.path.join(tuple[0],rstfile))[0],
+                    os.path.splitext(rstfile)[0],
+                    u'Cyrus IMAP documentation',
+                    author,
+                    tuple[1])
+                    )

     os.chdir(current)

@@ -520,4 +517,4 @@ extlinks = {

 # Change this to whatever your output root is
 # If you're in a local build environment, this might be file://cyrus-imapd/doc/build/imap/admin/$num/$topic/$topic.html
-#cyrus_man_url_regex = "http://www.cyrusimap.org/imap/admin/$num/$topic.html";
+#cyrus_man_url_regex = "http://www.cyrusimap.org/imap/admin/$num/$topic.html"
diff --git a/docsrc/exts/sphinxlocal/builders/gitstamp.py b/docsrc/exts/sphinxlocal/builders/gitstamp.py
--- a/docsrc/exts/sphinxlocal/builders/gitstamp.py
+++ b/docsrc/exts/sphinxlocal/builders/gitstamp.py
@@ -69,7 +69,7 @@ def page_context_handler(app, pagename, templatename, context, doctree):
 def what_build_am_i(app):
     global g
     if (app.builder.format != 'html'):
-        return;
+        return

     try:
         import git
diff --git a/docsrc/exts/sphinxlocal/roles/cyrusman.py b/docsrc/exts/sphinxlocal/roles/cyrusman.py
--- a/docsrc/exts/sphinxlocal/roles/cyrusman.py
+++ b/docsrc/exts/sphinxlocal/roles/cyrusman.py
@@ -23,4 +23,4 @@ def setup(app):
     return

 class CyrusManExtension(SphinxError):
-        category = ':cyrusman: error'
\ No newline at end of file
+    category = ':cyrusman: error'
diff --git a/docsrc/exts/sphinxlocal/sitemap.py b/docsrc/exts/sphinxlocal/sitemap.py
--- a/docsrc/exts/sphinxlocal/sitemap.py
+++ b/docsrc/exts/sphinxlocal/sitemap.py
@@ -59,7 +59,7 @@ def generate_sitemap(app, exception):
 # Only add the sitemap generator if we're generating html
 def what_build_am_i(app):
     if (app.builder.format != 'html'):
-        return;
+        return

     app.connect("build-finished", generate_sitemap)

diff --git a/docsrc/exts/sphinxlocal/writers/manpage.py b/docsrc/exts/sphinxlocal/writers/manpage.py
--- a/docsrc/exts/sphinxlocal/writers/manpage.py
+++ b/docsrc/exts/sphinxlocal/writers/manpage.py
@@ -64,10 +64,7 @@ class CyrusManualPageTranslator(BaseTranslator):

         # docinfo set by other config values
         self._docinfo['title_upper'] = self._docinfo['title'].upper()
-        if builder.config.today:
-            self._docinfo['date'] = builder.config.today
-        else:
-            self._docinfo['date'] = ustrftime(builder.config.today_fmt
+        self._docinfo['date'] = builder.config.today or ustrftime(builder.config.today_fmt
                                               or _('%B %d, %Y'))
         self._docinfo['copyright'] = builder.config.copyright
         self._docinfo['version'] = builder.config.version
diff --git a/docsrc/exts/themes/cyrus/__init__.py b/docsrc/exts/themes/cyrus/__init__.py
--- a/docsrc/exts/themes/cyrus/__init__.py
+++ b/docsrc/exts/themes/cyrus/__init__.py
@@ -13,5 +13,4 @@ __version_full__ = __version__

 def get_html_theme_path():
     """Return list of HTML theme paths."""
-    cur_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
-    return cur_dir
+    return os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
diff --git a/docsrc/exts/themes/sphinx_rtd_theme/__init__.py b/docsrc/exts/themes/sphinx_rtd_theme/__init__.py
--- a/docsrc/exts/themes/sphinx_rtd_theme/__init__.py
+++ b/docsrc/exts/themes/sphinx_rtd_theme/__init__.py
@@ -13,5 +13,4 @@ __version_full__ = __version__

 def get_html_theme_path():
     """Return list of HTML theme paths."""
-    cur_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
-    return cur_dir
+    return os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
nicolan commented 6 years ago

Thanks Dilyan. I'll get some time to look at this next week.

dilyanpalauzov commented 6 years ago

Any progress?

postilion commented 6 years ago

@dilyanpalauzov Could you please submit this as a pull request? The patch pasted above may well be out of date, and the indentation doesn't look right. For example, this else statement doesn't seem to align with anything:

           else:
                man_pages.append(

If you could send a PR, I'll check it out.

Thanks in advance, -nic

dilyanpalauzov commented 6 years ago

for line in f: starts in the 12th column in docsrc/conf.py. In the diff the for line in f: and else: are in the 13th column, so they align to each other.