Skip to content

Instantly share code, notes, and snippets.

@dekz
Created March 1, 2010 10:42
Show Gist options
  • Save dekz/318264 to your computer and use it in GitHub Desktop.
Save dekz/318264 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os
import sys
import subprocess
import fileinput
#htpasswd -b htaccess <name> <passwd>
count=0
def htaccessimport(file):
global count
for line in fileinput.input(file):
names = line.rsplit(' ')
count += 1
try:
args = ['htpasswd', '-b', 'htaccess', names[0], names[1]]
subprocess.Popen(args)
except:
print "Failed importing: " + line
print "Processed: " + str(count)
#you can get the directory by typing 'pwd' into your shell/console
htaccessimport("/Users/dekz/Projects/python/accounts.txt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment