Created
March 5, 2013 03:18
-
-
Save romanofski/5087721 to your computer and use it in GitHub Desktop.
link a project folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Manages links to a project directory | |
import optparse | |
import os.path | |
import sys | |
DEFAULTHOME = os.path.join(os.environ['HOME'], 'projects') | |
def main(): | |
parser = optparse.OptionParser() | |
parser.add_option( | |
"-c", "--create", dest="create", | |
type='string', | |
help="Create a link") | |
(options, args) = parser.parse_args() | |
if not os.path.exists(DEFAULTHOME): | |
parser.error("Directory to create links does not exist: {}".format( | |
DEFAULTHOME)) | |
if options.create: | |
path = os.path.join(DEFAULTHOME, options.create) | |
projectname = os.path.basename(options.create) | |
if projectname in os.listdir(DEFAULTHOME): | |
print("Provided path already exists: {}".format(path)) | |
sys.exit(1) | |
linkname = os.path.join(os.getcwd(), projectname) | |
os.symlink(linkname, path) | |
print("{} created.".format(path)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment