Skip to content

Commit

Permalink
remove changing dir to mydocs and simplify cmd call
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Vincent committed Apr 27, 2011
1 parent 9a78dd0 commit 1a38bba
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions cmd.py
Expand Up @@ -4,23 +4,13 @@
"""Setup cmd with some sane defaults."""

import os
import ctypes
import subprocess
import getpass
import sys
import logging

from urllib.request import getproxies_registry
from urllib.parse import urlparse

def getMyDocs():
"""Return the path to My Documents.
http://stackoverflow.com/questions/3927259/how-do-you-get-the-exact-path-to-my-documents/3927493#3927493"""
dll = ctypes.windll.shell32
buf = ctypes.create_unicode_buffer(300)
dll.SHGetSpecialFolderPathW(None, buf, 0x0005, False)
return buf.value

def setProxies(user, password, host, port):
"""Set proxy variables for the currently running shell."""
schemes = ["http", "https"]
Expand All @@ -34,12 +24,6 @@ def setProxies(user, password, host, port):
"{0}://{1}:{2}@{3}:{4}".format(base, user, password, host, port)
)

def postHook():
"""Perform some platform-specific post operations."""
if sys.platform == "win32":
cmd = ["cmd.exe", "/k", "cd", getMyDocs()]
subprocess.call(cmd)

def getProxyHost():
"""Return the proxy host and port from Windows registry."""
try:
Expand All @@ -60,7 +44,9 @@ def main():
port = input("Port: ")

setProxies(un, pw, host, port)
postHook()

# Start a child shell to inherit the new environment variables
subprocess.call(["cmd.exe"])

if __name__ == "__main__":
main()

0 comments on commit 1a38bba

Please sign in to comment.