Skip to content

Instantly share code, notes, and snippets.

@m0smith m0smith/vc.py
Created Feb 2, 2017

Embed
What would you like to do?
VC scripts for unified SVN and GIT
#!/usr/local/bin/python
import os
import subprocess
import sys
commands ={ ".svn" : ["svn","-u","status"],
".git" : ["git", "status"] }
def parent_dirs(f_or_d):
if os.path.isdir(f_or_d) :
current = os.path.abspath(f_or_d)
else:
current=os.path.abspath(os.path.dirname(f_or_d))
parent=os.path.dirname(current)
while( parent != current):
yield current;
current=parent
parent=os.path.dirname(current)
yield current
def find_command (f_or_d):
for p in parent_dirs(f_or_d):
for key, value in commands.iteritems():
if os.path.isdir(p +"/" + key):
return [p,value]
if len(sys.argv) > 1:
d=sys.argv[1]
else:
d=os.getcwd()
wd,command = find_command(d)
if wd:
p = subprocess.Popen(command, cwd=wd)
p.wait()
#!/usr/local/bin/python
import os
import subprocess
import sys
commands ={ ".svn" : ["svn", "commit", "-m"],
".git" : ["git", "commit", "-a", "-m"] }
def parent_dirs(f_or_d):
if os.path.isdir(f_or_d) :
current = os.path.abspath(f_or_d)
else:
current=os.path.abspath(os.path.dirname(f_or_d))
parent=os.path.dirname(current)
while( parent != current):
yield current;
current=parent
parent=os.path.dirname(current)
yield current
def find_command (f_or_d):
for p in parent_dirs(f_or_d):
for key, value in commands.iteritems():
if os.path.isdir(p +"/" + key):
return [p,value]
d=os.getcwd()
wd,command = find_command(d)
if wd:
p = subprocess.Popen(['vci'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, err = p.communicate();
print command + [(output.rstrip() + " " + ' '.join(sys.argv[1:])).rstrip()]
p = subprocess.Popen(command + [(output.rstrip() + " " + ' '.join(sys.argv[1:])).rstrip()], cwd=wd)
p.wait()
#!/bin/bash
vc | egrep "On branch [^ ]*[A-Z][A-Z][A-Z]-[0-9]{1,7}" | egrep -o "[A-Z]{1,5}-[0-9]{1,7}"
#!/usr/local/bin/planck
(ns m0smith.vcp
(:require [planck.shell :refer [sh]]
[planck.io :refer [file-attributes]]
[clojure.string :refer [trimr]]))
(def commands {".git" ["git" "status"]
".svn" ["svn" "-u" "status"] })
(defn dirname [d]
(trimr (:out (sh "dirname" d))))
(defn parent-dir [d]
(when d
(let [rtnval (dirname d)]
(when (not= d rtnval)
rtnval))))
(defn cwd [] (trimr (:out (sh "pwd"))))
(let [[path command] (first (for [path (take-while identity (iterate parent-dir (cwd)))
[ext exe] commands
:when(file-attributes (str path "/" ext))]
[path exe]))]
(print (:out (apply sh (concat command [:dir path])))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.