Skip to content

Instantly share code, notes, and snippets.

@bensternthal
Last active December 19, 2015 02:49
Show Gist options
  • Save bensternthal/5885501 to your computer and use it in GitHub Desktop.
Save bensternthal/5885501 to your computer and use it in GitHub Desktop.
Re-writing a bash script Justin wrote in python.
import csv
import os
from os.path import join, getsize
ROOTURL = 'http://www.mozilla.org'
ROOTSVN = 'http://viewvc.svn.mozilla.org/vc/projects/mozilla.org/trunk'
with open('test.csv', 'wb') as csvfile:
csvwriter = csv.writer(csvfile, delimiter=',',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
csvwriter.writerow(['URL', 'SVN Path', 'File In Dir'])
for root, dirs, files in os.walk('/Users/bsternthal/Documents/Dev/mozilla-legacy/mozilla.org', topdown=True):
if '.svn' in dirs:
dirs.remove('.svn')
files_in_current_directory = len(files)
filePath, path = root.split("mozilla.org",1)
url = ROOTURL + path
svn = ROOTSVN + path
csvwriter.writerow([url, svn, files_in_current_directory])
@Osmose
Copy link

Osmose commented Jun 28, 2013

csvwriter = csv.writer(
    csvfile, delimiter=',', quotechar='|', 
    quoting=csv.QUOTE_MINIMAL)

@bensternthal
Copy link
Author

make path to svn a var

@Osmose
Copy link

Osmose commented Jun 28, 2013

try:
    dirs.remove('.svn')
except ValueError:
    pass

@bensternthal
Copy link
Author

shorten files_in_current_directory or just use this directly

@bensternthal
Copy link
Author

comment split -- what am i doing here

@bensternthal
Copy link
Author

string concatination - maybe .join ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment