From: Eric S. Raymond Date: Thu, 6 Nov 2014 16:39:39 +0000 (-0500) Subject: src init. X-Git-Tag: 0.1~34 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=99b7fdeab49b1c5f1e1226efabc7d66de25c4fa4;p=src.git src init. --- diff --git a/src b/src index 6ac8ca3..cb270be 100755 --- a/src +++ b/src @@ -2,11 +2,15 @@ # # src - simple revision control. # -import sys +import sys, os version = 0.1 +def complain(msg): + sys.stderr.write("src: " + msg + "\n") + def help(*args): + "Summarize src commands, or (with argument) show help for a single command." print""" src help [command] Displays help for commands. @@ -36,9 +40,25 @@ src fast-export ['file'...] Export one or more projects as a git fast-import stream. """ +def init(*args): + "Create a .src directory if none already exists." + if not os.path.exists(".src"): + try: + os.mkdir(".src") + except OSError: + complain(".src/ creation failed, check directory permissions.") + elif os.path.isdir(".src"): + complain(".src/ already exists.") + else: + complain(".src/ exists but is not a directory.") + if __name__ == "__main__": command = sys.argv[1:] if not command: help() else: - eval(command[0])(*command[1:]) + try: + eval(command[0])(*command[1:]) + except NameError: + sys.stderr.write("src: no such command as '%s'. Try 'src help'\n" \ + % command[0])