Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed OptionParser import error.

Some pep8 cleaning.
  • Loading branch information...
commit 3aeee8245e160eefdb1c21f38b60ffc336361a52 1 parent 6516435
Sébastien Fievet authored February 04, 2011

Showing 1 changed file with 21 additions and 19 deletions. Show diff stats Hide diff stats

  1. 40  doc/sphinxtogithub.py
40  doc/sphinxtogithub.py
... ...
@@ -1,5 +1,5 @@
1 1
 #! /usr/bin/env python
2  
- 
  2
+
3 3
 import optparse as op
4 4
 import os
5 5
 import sys
@@ -9,6 +9,7 @@
9 9
 class NoDirectoriesError(Exception):
10 10
     "Error thrown when no directories starting with an underscore are found"
11 11
 
  12
+
12 13
 class DirHelper(object):
13 14
 
14 15
     def __init__(self, is_dir, list_dir, walk, rmtree):
@@ -18,6 +19,7 @@ def __init__(self, is_dir, list_dir, walk, rmtree):
18 19
         self.walk = walk
19 20
         self.rmtree = rmtree
20 21
 
  22
+
21 23
 class FileSystemHelper(object):
22 24
 
23 25
     def __init__(self, open_, path_join, move, exists):
@@ -27,6 +29,7 @@ def __init__(self, open_, path_join, move, exists):
27 29
         self.move = move
28 30
         self.exists = exists
29 31
 
  32
+
30 33
 class Replacer(object):
31 34
     "Encapsulates a simple text replace"
32 35
 
@@ -37,7 +40,8 @@ def __init__(self, from_, to):
37 40
 
38 41
     def process(self, text):
39 42
 
40  
-        return text.replace( self.from_, self.to )
  43
+        return text.replace(self.from_, self.to)
  44
+
41 45
 
42 46
 class FileHandler(object):
43 47
     "Applies a series of replacements the contents of a file inplace"
@@ -53,10 +57,11 @@ def process(self):
53 57
         text = self.opener(self.name).read()
54 58
 
55 59
         for replacer in self.replacers:
56  
-            text = replacer.process( text )
  60
+            text = replacer.process(text)
57 61
 
58 62
         self.opener(self.name, "w").write(text)
59 63
 
  64
+
60 65
 class Remover(object):
61 66
 
62 67
     def __init__(self, exists, remove):
@@ -68,6 +73,7 @@ def __call__(self, name):
68 73
         if self.exists(name):
69 74
             self.remove(name)
70 75
 
  76
+
71 77
 class ForceRename(object):
72 78
 
73 79
     def __init__(self, renamer, remove):
@@ -80,6 +86,7 @@ def __call__(self, from_, to):
80 86
         self.remove(to)
81 87
         self.renamer(from_, to)
82 88
 
  89
+
83 90
 class VerboseRename(object):
84 91
 
85 92
     def __init__(self, renamer, stream):
@@ -108,7 +115,7 @@ def __init__(self, name, root, renamer):
108 115
         self.renamer = renamer
109 116
 
110 117
     def path(self):
111  
-        
  118
+
112 119
         return os.path.join(self.root, self.name)
113 120
 
114 121
     def relative_path(self, directory, filename):
@@ -181,7 +188,8 @@ def process(self):
181 188
 class LayoutFactory(object):
182 189
     "Creates a layout object"
183 190
 
184  
-    def __init__(self, operations_factory, handler_factory, file_helper, dir_helper, verbose, stream, force):
  191
+    def __init__(self, operations_factory, handler_factory, file_helper,
  192
+                 dir_helper, verbose, stream, force):
185 193
 
186 194
         self.operations_factory = operations_factory
187 195
         self.handler_factory = handler_factory
@@ -201,10 +209,10 @@ def create_layout(self, path):
201 209
 
202 210
         if self.force:
203 211
             remove = self.operations_factory.create_remover(self.file_helper.exists, self.dir_helper.rmtree)
204  
-            renamer = self.operations_factory.create_force_rename(renamer, remove) 
  212
+            renamer = self.operations_factory.create_force_rename(renamer, remove)
205 213
 
206 214
         if self.verbose:
207  
-            renamer = self.operations_factory.create_verbose_rename(renamer, self.output_stream) 
  215
+            renamer = self.operations_factory.create_verbose_rename(renamer, self.output_stream)
208 216
 
209 217
         # Build list of directories to process
210 218
         directories = [d for d in contents if self.is_underscore_dir(path, d)]
@@ -256,16 +264,15 @@ def is_underscore_dir(self, path, directory):
256 264
             and directory.startswith("_"))
257 265
 
258 266
 
259  
-
260 267
 def sphinx_extension(app, exception):
261 268
     "Wrapped up as a Sphinx Extension"
262 269
 
263 270
     # This code is sadly untestable in its current state
264 271
     # It would be helped if there was some function for loading extension
265  
-    # specific data on to the app object and the app object providing 
  272
+    # specific data on to the app object and the app object providing
266 273
     # a file-like object for writing to standard out.
267 274
     # The former is doable, but not officially supported (as far as I know)
268  
-    # so I wouldn't know where to stash the data. 
  275
+    # so I wouldn't know where to stash the data.
269 276
 
270 277
     if app.builder.name != "html":
271 278
         return
@@ -293,7 +300,7 @@ def sphinx_extension(app, exception):
293 300
             shutil.move,
294 301
             os.path.exists
295 302
             )
296  
-    
  303
+
297 304
     operations_factory = OperationsFactory()
298 305
     handler_factory = HandlerFactory()
299 306
 
@@ -323,8 +330,8 @@ def setup(app):
323 330
 def main(args):
324 331
 
325 332
     usage = "usage: %prog [options] <html directory>"
326  
-    parser = OptionParser(usage=usage)
327  
-    parser.add_option("-v","--verbose", action="store_true",
  333
+    parser = op.OptionParser(usage=usage)
  334
+    parser.add_option("-v", "--verbose", action="store_true",
328 335
             dest="verbose", default=False, help="Provides verbose output")
329 336
     opts, args = parser.parse_args(args)
330 337
 
@@ -350,7 +357,7 @@ def main(args):
350 357
             shutil.move,
351 358
             os.path.exists
352 359
             )
353  
-    
  360
+
354 361
     operations_factory = OperationsFactory()
355 362
     handler_factory = HandlerFactory()
356 363
 
@@ -374,11 +381,6 @@ def main(args):
374 381
         return
375 382
 
376 383
     layout.process()
377  
-    
378  
-
379 384
 
380 385
 if __name__ == "__main__":
381 386
     main(sys.argv[1:])
382  
-
383  
-
384  
-

0 notes on commit 3aeee82

Please sign in to comment.
Something went wrong with that request. Please try again.