Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View techtonik's full-sized avatar

anatoly techtonik techtonik

View GitHub Profile
@techtonik
techtonik / get_svn_path_revision.py
Created September 7, 2011 23:12
VCS - Subversion - Get revision number for a given path in local copy
def get_svn_path_revision(path):
"""return latest modification revision of a path inside svn
:raise: EnvironmentError if SVN working copy format is unknown
:return: int
"""
from os.path import basename, dirname, join, isdir
if isdir(path):
entries_path = join(path, ".svn", "entries")
@techtonik
techtonik / get_hg_repo_revision.py
Created September 8, 2011 13:22
VCS - Mercurial - Get revision number for a given repository
def get_hg_repo_revision(path):
"""return current revision of a repository at path
:raise: EnvironmentError if `hg` isn't found or path invalid
:return: string like 'num:hash'
"""
from subprocess import Popen, PIPE
if os.path.isfile(path):
path = os.path.dirname(path)
try:
@techtonik
techtonik / get_hg_path_revision.py
Created September 10, 2011 12:28
VCS - Mercurial - Get revision number for a given path in local checkout
def get_hg_path_revision(path):
"""return latest modification revision of a path inside hg
:raise: EnvironmentError if `hg` isn't found or path invalid
:return: string like 'num:hash'
"""
from subprocess import Popen, PIPE
try:
hgprocess = Popen(
'hg log -l 1 --template "{node|short} {rev}" --cwd "%s" "%s"'
@techtonik
techtonik / inspectlog.py
Created October 16, 2011 16:44
Logging - Automatically get module.class name for log() caller
import inspect
import logging
def log(level, msg, depth=1):
"""Logging function that detects name of appropriate logger for calling
function in 'module.class' format. `depth` allows to specify a higher
frame in a call stack if you want to wrap this function.
"""
name = None
try:
@techtonik
techtonik / README.rst
Created October 17, 2011 15:56
Trac - Bootstrap script to execute Trac with default environment from checkout
@techtonik
techtonik / README.rst
Created October 19, 2011 20:55
Python - Get function trace in Xdebug format - https://bitbucket.org/techtonik/xtrace
@techtonik
techtonik / shrun.py
Last active October 1, 2015 10:57
Python - runout() and runret() functions
""" https://gist.github.com/1978810
shutil.runret() and shutil.runout() functions
runret(command) - run command through shell, return ret code
runout(command) - run command through shell, return output
Public Domain, i.e. free for copy/paste
https://groups.google.com/d/topic/python-ideas/u42aZZnrs8A/discussion
https://bitbucket.org/techtonik/shellrun
@techtonik
techtonik / socket-client-server.py
Created March 17, 2012 08:41
Python - socket - Client/server example in one thread
import socket
if __name__ == '__main__':
# socket read/write testing - client and server in one thread
# (techtonik): the stuff below is placed into public domain
print "-- Testing standard Python socket interface --"
address = ("127.0.0.1", 9999)
@techtonik
techtonik / caller_name.py
Created March 21, 2012 19:29
Python - inspect - Get full caller name (package.module.function)
# Public Domain, i.e. feel free to copy/paste
# Considered a hack in Python 2
import inspect
def caller_name(skip=2):
"""Get a name of a caller in the format module.class.method
`skip` specifies how many levels of stack to skip while getting caller
name. skip=1 means "who calls me", skip=2 "who calls my caller" etc.
@techtonik
techtonik / chef-webui-reset.py
Created July 2, 2012 17:07
Chef - Reset WebUI admin password
"""Reset admin password in Chef Server WebUI by removing admin user from DB"""
# based on http://lists.opscode.com/sympa/arc/chef/2011-08/msg00151.html
import urllib2
import json
COUCHSERV = 'localhost:5984'
COUCHDB = 'http://' + COUCHSERV + '/chef/'