def jenkins_server(): runcmd.run(["wget", "-O", "jenkins-ci.org.key", "http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key"]) runcmd.check_sudo(["apt-key", "add", "jenkins-ci.org.key"]) runcmd.install_files("/etc/apt/sources.list.d", ["jenkins.list"]) runcmd.apt_get(["update"]) runcmd.apt_get(["install", "openjdk-6-jdk", "jenkins", "libcobertura-java"]) runcmd.install_files("/etc/default", ["jenkins"])
def mysql_secure_db(): with open(runcmd.rsrc_path("mysql_securedb.sql.in")) as sql_in: with open(runcmd.rsrc_path("mysql_secure_db.sql"), "w") as sql_out: sql_out.write(sql_in.read()) with open(runcmd.rsrc_path("mysql_secure_db.sql")) as sql_cmd: runcmd.run(["/usr/local/mysql/bin/mysql", "--user=root", "--batch"], stdin=sql_cmd)
def checkout_site(): setup_known_hosts() if not opath.exists(opath.expanduser("~/memrise")): os.mkdir(opath.expanduser("~/memrise")) log.info("Checking out memrise site from unfuddle") rc.run(["git", "clone", "[email protected]:memrise/memrise-django.git", "memrise"], cwd=opath.expanduser("~/memrise"))
def update(path, image): """update icon""" if not image: return rm(path) if sys.version_info[0] == 2: _cocoa_seticon(path, image) else: args = ["osascript", "-e", APPLESCRIPT, path, image] runcmd.run(args).exc() os.utime(path, None) if os.path.isdir(path): subprocess.Popen( ["chflags", "hidden", "%s/Icon\r" % path], stderr=subprocess.PIPE).communicate()
def get(path=None): """return `git status` string""" if not path: path = os.getcwd() cmd = ["git", "status", "-s"] r = runcmd.run(cmd, cwd=path)._raise() return r.out
def run(applescript, background=False): path = applescript if not os.path.exists(applescript): # source code path = temp.tempfile() open(path, "w").write(applescript) args = ["osascript", path] return runcmd.run(args, background=background)
def app(appname, applescript, background=False): code = """tell application "%s" %s end tell """ % (appname, applescript) path = _tempfile(code) args = ["osascript", path] return runcmd.run(args, background=background)
def voices(lang=None): """return a list of installed voices (name, lang, description)""" cmd = ["/usr/bin/say", "-v", "?"] out = runcmd.run(cmd).out for l in out.splitlines(): _name, _lang, _description = _voice_info(l) if not lang or (lang and lang in _lang): yield _name, _lang, _description
def _run(args): if not os.path.exists("/usr/local/bin/tag"): raise OSError("""/usr/local/bin/tag NOT INSTALLED https://github.com/jdberry/tag brew install tag """) args = ["/usr/local/bin/tag"] + list(args) return runcmd.run(args)._raise().out
def run(applescript, background=False): """run applescript file/code""" if os.path.exists(applescript): path = applescript else: path = temp.tempfile() open(path, "w").write(applescript) cmd = ["osascript", path] r = runcmd.run(cmd, background=background) return r.code, r.out, r.err
def install_mysql(): log.info("Downloading MySQL 5.5.19 Source") runcmd.run(["wget", "-O", "mysql-5.5.19.tar.gz", "http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.19.tar.gz/from/http://mysql.he.net/"]) log.info("Unpacking MySQL 5.5.19 Source") runcmd.run(["tar", "xzf", "mysql-5.5.19.tar.gz"]) log.info("Configuring MySQL 5.5.19 Source") runcmd.run(["cmake", "."], cwd="mysql-5.5.19") log.info("Building MySQL 5.5.19 Source") runcmd.run(["make", "-j", "4"], cwd="mysql-5.5.19") log.info("Installing MySQL 5.5.19 Source to /usr/local/mysql") runcmd.check_sudo(["make" ,"install"], cwd="mysql-5.5.19") runcmd.install_files("/etc/profile.d", ["mysql.sh"]) runcmd.install_files("/etc/ld.so.conf.d", ["mysql-ld.so.conf"]) runcmd.check_sudo(['ldconfig'])
def mkalias(src, dst): """make MacOS Finder alias""" cmd = ["mkalias", _fullpath(src), _fullpath(dst)] runcmd.run(cmd)._raise() """refresh icon""" os.utime(os.path.dirname(_fullpath(dst)), None)
#!/usr/bin/env python import runcmd runcmd.run(["ls"]).exc() # ok try: runcmd.run(["mkdir", "/"]).exc() except OSError: # mkdir: /: Is a directory pass
#!/usr/bin/env python import runcmd r = runcmd.run(["echo", "hello world"]) print(r) print("code = %s" % r.code) print("out = %s" % r.out) print("err = %s" % r.err) out = runcmd.run(["echo", "hello world"]).exc().out
def setup_venv(): rc.run(["pip", "install", "-E", "../venv", "-r", "requirements.txt"], cwd=opath.expanduser("~/memrise/memrise")) os.chmod('/home/memrise/memrise/', 0755) os.chmod('/home/memrise/', 0755)
def get_weather(): w = runcmd.run(["weather", "80007"]) if (w.code == 0): return w.out return "Unable to connect to weather report"
#!/usr/bin/env python import time import runcmd r = runcmd.run(["sleep", "5"], background=True) print("pid: %s" % r.pid) counter = 0 while r.running: print("running %s" % counter) counter += 1 time.sleep(1) if counter > 2: r.kill()
def run(args): """run `open` with arguments""" runcmd.run(["open"] + args)._raise()
def rm(): """`git remote rm name`""" _name = name() if _name: runcmd.run(["git", "remote", "rm", _name])
def update(path, image): """update icon""" if sys.version_info[0] == 2: return _cocoa_seticon(path, image) args = ["osascript", "-e", APPLESCRIPT, path, image] runcmd.run(args)._raise()
def sleep(): """put your display to sleep""" cmd = ["/usr/bin/pmset", "displaysleepnow"] runcmd.run(cmd)
def run(args): """run `git remote` with args and return output""" return runcmd.run(["git", "remote"] + list(args))._raise().out
def say(args, background=False): """run `say` with given args""" r = runcmd.run(["say"] + values.get(args), background=background) if not background: r._raise() return r
def sleeping(): """return True if display is sleeping""" out = runcmd.run(["/usr/sbin/ioreg", "-n", "IODisplayWrangler"])._raise().out state = int(out.split('"DevicePowerState"=')[1][0]) # 0-4 return state in [0, 1]
def wake(): """wake from sleep""" cmd = ["/usr/bin/caffeinate", "-u", "-t", "1"] runcmd.run(cmd)
def chmod(args): """run chmod with arguments""" cmd = ["chmod"] + list(args) return runcmd.run(cmd)._raise().out
def _rm_file_icon(path): args = ["xattr", "-d", "com.apple.ResourceFork", path] runcmd.run(args)
def run(args): """run `/usr/local/bin/tag` with arguments and return output""" if not os.path.exists(bin): raise OSError("%s NOT EXISTS\nrun `brew install tag`" % bin) return runcmd.run([bin] + values.get(args))._raise().out
def add(name, url): """`git remote add name url`""" runcmd.run(["git", "remote", "add", name, url])._raise()
def mdfind(args): """execute mdfind with arguments""" cmd = ["mdfind"] + list(args) return runcmd.run(cmd).exc().out
def read(): """return string with `hwmonitor` output""" return runcmd.run([BIN])._raise().out
def _run(args): return runcmd.run(["google-chrome"] + list(args))._raise().out
def setup_jenkins_as_memrise(): setup_known_hosts() rc.run(["git", "clone", "[email protected]:Memrise/jenkins.git"], cwd=opath.expanduser("~"))