summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrey Hunner <treyhunner@gmail.com>2012-01-16 07:25:37 -0800
committerTrey Hunner <treyhunner@gmail.com>2012-01-16 08:06:38 -0800
commita2053af5bb0f170b3d59f6581ba887dd2765d4a2 (patch)
tree7b0de0d3374e583255d8334d67988db22ea2c8c4
parent2cf13396a48a92d204fb96bc022719920833e53c (diff)
downloadpycco-a2053af5bb0f170b3d59f6581ba887dd2765d4a2.tar.gz
Use consistent coding style for utils and main
-rw-r--r--pycco/main.py17
-rw-r--r--pycco/utils.py75
2 files changed, 43 insertions, 49 deletions
diff --git a/pycco/main.py b/pycco/main.py
index ccb328e..39f62df 100644
--- a/pycco/main.py
+++ b/pycco/main.py
@@ -250,7 +250,7 @@ def generate_html(source, sections, preserve_paths=True, outdir=None):
rendered = pycco_template({
"title" : source.title,
- "sources" : source.relative_paths( SOURCES ),
+ "sources" : source.relative_paths(SOURCES),
"stylesheet" : csspath,
"sections" : sections,
"source" : source.name,
@@ -486,25 +486,24 @@ def main():
parser.add_option('-a', '--all', action='store_true',
help='Get all files from subfolders')
- opts, sources = parser.parse_args()
+ opts, sources = parser.parse_args()
if not sources:
return
- filepath = os.path.dirname( sources[0] )
- start, filetype = os.path.splitext( sources[0] )
+ filepath = os.path.dirname(sources[0])
+ start, filetype = os.path.splitext(sources[0])
- if start.endswith( '*' ):
+ if start.endswith('*'):
return
- start = os.path.dirname( os.path.dirname( os.path.abspath(start) ) )
- #start = os.path.dirname( os.path.dirname( start ) )
+ start = os.path.dirname(os.path.dirname(os.path.abspath(start)))
if opts.all:
- sources = [ i for i in get_all_files( filepath or '.', filetype ) ]
+ sources = [i for i in get_all_files(filepath or '.', filetype)]
global SOURCES
- SOURCES = Sources( sources, start )
+ SOURCES = Sources(sources, start)
process(SOURCES, outdir=opts.outdir, preserve_paths=opts.paths)
diff --git a/pycco/utils.py b/pycco/utils.py
index d110109..3daf5bf 100644
--- a/pycco/utils.py
+++ b/pycco/utils.py
@@ -1,72 +1,70 @@
-#!/usr/bin/env python
-# encoding: utf-8
-
import sys
import os
+
class NoFilesFound(Exception):
def __str__(self):
return "No files were found to be processed by pycco"
-def get_all_files( path, extension ):
-
- def relative( path ):
- relpath = os.path.relpath( path )
- if relpath == '.':
+
+def get_all_files(path, extension):
+ def relative(path):
+ relpath = os.path.relpath(path)
+ if relpath == '.':
return ''
else:
return relpath + "/"
- for path, dirs, files in os.walk( path ):
+ for path, dirs, files in os.walk(path):
for filename in files:
- if filename.endswith( extension ):
- yield "%s%s" %( relative( path ), filename )
+ if filename.endswith(extension):
+ yield "%s%s" % (relative(path), filename)
-
-from os import path
-
-class Source:
+class Source:
def __init__(self, name, start):
self.name = name
- self.title = path.basename( self.name )
- self.dirpath = path.dirname( self.name ) or '.'
- self.dirname = path.relpath(self.dirpath, start)
+ self.title = os.path.basename(self.name)
+ self.dirpath = os.path.dirname(self.name) or '.'
+ self.dirname = os.path.relpath(self.dirpath, start)
self.start = start
-
+
def save_path(self):
- return "docs/%s/%s" %( self.dirname, self.title )
-
+ return "docs/%s/%s" % (self.dirname, self.title)
+
def relative_path(self, source):
- html = lambda x: "%s.html" %path.splitext(x)[0]
- rel = path.relpath( source.dirpath, self.dirpath )
- return "%s/%s" %( rel, html(source.title) )
+ html = lambda x: "%s.html" % os.path.splitext(x)[0]
+ rel = os.path.relpath(source.dirpath, self.dirpath)
+ return "%s/%s" % (rel, html(source.title))
def relative_paths(self, sources):
- root_ = ''; list_ = []; dict_ = {}; id_ = 1
- title = lambda s: { 'title': s.title, 'url': self.relative_path( s ) }
- new_dict = lambda s: { 'id': id_, 'dirname': s.dirname, 'display': 'none', 'titles': [ title( s ) ], }
+ root_ = ''
+ list_ = []
+ dict_ = {}
+ id_ = 1
+ title = lambda s: {'title': s.title, 'url': self.relative_path(s)}
+ new_dict = lambda s: {'id': id_, 'dirname': s.dirname, 'display': 'none', 'titles': [title(s)]}
for source in sources:
if source.dirpath != root_:
- if dict_:
- list_.append( dict_ )
+ if dict_:
+ list_.append(dict_)
root_ = source.dirpath
- dict_ = new_dict( source )
+ dict_ = new_dict(source)
id_ += 1
else:
- dict_[ 'titles' ].append( title( source ) )
-
- list_.append( dict_ )
- if len( list_ ) == 1:
+ dict_['titles'].append(title(source))
+
+ list_.append(dict_)
+ if len(list_) == 1:
list_[0]['display'] = 'block'
- return list_
+ return list_
class Sources:
def __init__(self, sources, start):
- self.list = [ Source( name, start ) for name in sources ]
- self.get = lambda x: self.list[ index ]
+ self.list = [Source(name, start) for name in sources]
+ self.get = lambda x: self.list[index]
def names(self):
return [i.name for i in self.list]
@@ -74,6 +72,3 @@ class Sources:
def __iter__(self):
for i in self.list:
yield i
-
-
-