summaryrefslogtreecommitdiffstats
authorRaghavendra D Prabhu <[email protected]>2011-07-23 19:18:00 (GMT)
committer Raghavendra D Prabhu <[email protected]>2011-07-23 19:18:00 (GMT)
commitd4f519ffe7c7e9bdae704fcdc30d3e2a1cfb49dc (patch) (side-by-side diff)
treefa537d54aed6083c8de9d6f64b89bb35a4fb90e1
parent56d848c248199f02521e293f0568dbeac5185097 (diff)
downloadScripts-d4f519ffe7c7e9bdae704fcdc30d3e2a1cfb49dc.zip
Scripts-d4f519ffe7c7e9bdae704fcdc30d3e2a1cfb49dc.tar.gz
Scripts-d4f519ffe7c7e9bdae704fcdc30d3e2a1cfb49dc.tar.bz2
Scripts update
Diffstat (more/less context) (ignore whitespace changes)
-rwxr-xr-xarchievm29
-rwxr-xr-xbldins26
-rw-r--r--functions45
-rwxr-xr-xgetimap9
-rwxr-xr-xmuxone7
-rwxr-xr-xpwclient463
6 files changed, 558 insertions, 21 deletions
diff --git a/archievm b/archievm
index 1a4d3a6..c20b6c2 100755
--- a/archievm
+++ b/archievm
@@ -1,3 +1,2 @@
#!/bin/zsh
-# Virtio somehow broken
@@ -6,9 +5,12 @@
#sudo modprobe -a -v kvm kvm_intel nbd
-sudo modprobe -a -v kvm kvm_intel
-
+lsmod | grep -q kvm_intel || {
+ sudo modprobe -a -v kvm kvm_intel
+}
debugk=0
nographic=1
-huge=1
+mem=512
+huge=0
test=0
ksm=0
+console=0
runas="raghavendra"
@@ -21,3 +23,3 @@ soutput=1
typeset -A args
-args=(d debugk n nographic g huge I bzImage t test)
+args=(d debugk c console n nographic g huge I bzImage t test s soutput)
@@ -38,2 +40,3 @@ while getopts ':gn:dI:th' opt;do
g: huge
+ c: qemu console
t: test
@@ -61,4 +64,4 @@ fi
-if [[ $huge == 1 ]];then
- echo 296 | sudo tee /proc/sys/vm/nr_hugepages
+if [[ $huge == 1 && $test == 0 ]];then
+ echo 148 | sudo tee /proc/sys/vm/nr_hugepages
#hugearg=" -mem-path /media/hugepages -mem-prealloc "
@@ -85,3 +88,3 @@ fi
cmdline="qemu-kvm -name Archie -enable-kvm -s -monitor unix:$DIR/archie.sock,server,nowait \
- -m 512 $hugearg $snap -smp 2,cores=2 -balloon virtio \
+ -m $mem $hugearg $snap -smp 2,cores=2 -balloon virtio \
-net nic,model=virtio,vlan=1 -net user,vlan=1,hostfwd=tcp:127.0.0.1:2222-:22 $=graph \
@@ -99,3 +102,3 @@ if [[ $ksm == 1 ]];then
fi
-sleep 10
+#sleep 5
#sudo -u $runas sshfs -p 2222 [email protected]:/ /mnt-qemu
@@ -103,3 +106,9 @@ sshfs -p 2222 [email protected]:/home/raghu/gcov /media/Corona/bldit/.gcov
#rlwrap -pgreen socat - $DIR/archie.sock
-rlwrap socat - $DIR/archie.sock
+if [[ $console == 1 ]];then
+ rlwrap socat - $DIR/archie.sock
+else
+ if [[ $nographic == 1 ]];then
+ ssh -p 2222 [email protected]
+ fi
+fi
#qemu-kvm -name Archie -enable-kvm -m 512 -snapshot -drive file=/media/Inkq/Virt/Archie.img,if=virtio -vga std -kernel ~/Arch/qemu/kvmImage -initrd /boot/kernel26.img -append root=/dev/vda3
diff --git a/bldins b/bldins
index bd7650a..752f10a 100755
--- a/bldins
+++ b/bldins
@@ -16,2 +16,3 @@ pushd $HOME/Arch/Build/torvalds-git
install=${INSTALL:-0}
+QEMU_DEBUG="$HOME/Arch/qemu/images"
@@ -42,2 +43,3 @@ export KCFLAGS=" -march=native -O2 -pipe "
#export INSTALL_MOD_STRIP="-s"
+[[ ! -f $QEMU_DEBUG/.id ]] && echo -n 1 >| $QEMU_DEBUG/.id
@@ -55,5 +57,5 @@ if [[ $install == 0 ]];then
unset INSTALL_MOD_STRIP
- if [[ $conf == 1 ]];then
- make localyesconfig || exit 1
- fi
+ #if [[ $conf == 1 ]];then
+ make localyesconfig || exit 1
+ #fi
else
@@ -92,8 +94,14 @@ if [[ $debug == 0 ]];then
else
- cp -v System.map ~/Arch/qemu/System.map26
- cp arch/x86/boot/bzImage ~/Arch/qemu/kvmImage || exit 1
- cp vmlinux ~/Arch/qemu/vmlinux || exit 1
- #make modules_install INSTALL_MOD_PATH=~/Arch/qemu/modules || exit 1
- #make modules_install MODLIB=~/Arch/qemu/module || exit 1
- #make headers_install INSTALL_HDR_PATH=~/Arch/qemu/header || exit 1
+ rm ~/Arch/qemu/kvmImage 2>/dev/null
+ num=$(< $QEMU_DEBUG/.id)
+ num=$(( num+1 ))
+ branch=$(git symbolic-ref HEAD)
+ imgsuf="${branch##*/}-$num"
+ echo -n $num >| $QEMU_DEBUG/.id
+ cp -v System.map $QEMU_DEBUG/System.map26-$imgsuf
+ cp -v arch/x86/boot/bzImage $QEMU_DEBUG/image-$imgsuf || exit 1
+ #cp -v vmlinux $QEMU_DEBUG/vmlinux-$imgsuf || exit 1
+ cp -v vmlinux $QEMU_DEBUG/../vmlinux || exit 1
+ ln -sf $QEMU_DEBUG/image-$imgsuf ~/Arch/qemu/kvmImage
+ ln -sf $QEMU_DEBUG/System.map26-$imgsuf ~/Arch/qemu/System.map26
exit
diff --git a/functions b/functions
index ed4904d..92ff5e6 100644
--- a/functions
+++ b/functions
@@ -649,2 +649,3 @@ function btime(){
function {reboot,sdown} {
+ timeout=$2
typeset -A map
@@ -652,3 +653,8 @@ function {reboot,sdown} {
command=$0
- echo "Sure y/N"
+ if [[ -z $timeout ]];then
+ echo "Sure y/N"
+ else
+ echo "Sleeping $timeout"
+ sleep $timeout || return 22
+ fi
if read -q;then
@@ -663,2 +669,17 @@ viewjson(){
+#vim(){
+ #files=()
+ #opts=()
+ #for x in [email protected];do
+ #if [[ $x == /* ]];then
+ #files+=$x
+ #elif [[ $x == -* ]];then
+ #opts+="$x"
+ #else
+ #files+="$HOME/"$x
+ #fi
+ #done
+ #/usr/bin/vim $opts $files
+#}
+
pacsync(){
@@ -671,2 +692,24 @@ pacupdate(){
+rubit(){
+ source ~/.rvm/scripts/rvm
+ rvm use 1.9.2
+}
+
+ktrace(){
+ prdevice="/dev/ttyprintk"
+ trdevice="/proc/sysrq-trigger"
+ secho "==============KTRACE============" $prdevice
+ secho "1. ============show-backtrace-all-active-cpus===================" $prdevice
+ secho l $trdevice
+ secho "2. ============Memory usage===================" $prdevice
+ secho m $trdevice
+ secho "3. ============Registers ===================" $prdevice
+ secho p $trdevice
+ secho "4. ============Task states===================" $prdevice
+ secho t $trdevice
+ secho "5. ============Blocked Tasks ===================" $prdevice
+ secho w $trdevice
+}
+
+
slob(){
diff --git a/getimap b/getimap
index cb87ec0..dc837ca 100755
--- a/getimap
+++ b/getimap
@@ -1,2 +1,5 @@
#!/bin/bash
+typeset -A provider
+provider=(g gmail g2 gmail2 y yahoo w wnohang)
+
pidof X || exit 13
@@ -27,3 +30,7 @@ DURATION=6 notify-send "Mailman" "....Fetching mails."
#setlock -X -n /tmp/locks/getmail getmail -n -q --rcfile=getmailrc.gmail --rcfile=getmailrc.yahoo --rcfile=getmailrc.wnohang --rcfile=getmailrc.gmail2
-/usr/sbin/setlock -X -n /tmp/locks/getmail getmail -n -v --rcfile=getmailrc.gmail --rcfile=getmailrc.yahoo --rcfile=getmailrc.wnohang --rcfile=getmailrc.gmail2
+if [[ -n $1 ]];then
+ /usr/sbin/setlock -X -n /tmp/locks/getmail getmail -n -v --rcfile=getmailrc.$provider[$1]
+else
+ /usr/sbin/setlock -X -n /tmp/locks/getmail getmail -n -v --rcfile=getmailrc.gmail --rcfile=getmailrc.yahoo --rcfile=getmailrc.wnohang --rcfile=getmailrc.gmail2
+fi
exitcode=$?
diff --git a/muxone b/muxone
new file mode 100755
index 0000000..4359cde
--- a/dev/null
+++ b/muxone
@@ -0,0 +1,7 @@
+#!/bin/zsh
+[[ -z $1 ]] && return 1
+base=$1
+sessid=`date +%Y%m%d%H%M%S`
+tmux new-session -d -s $sessid -t $base
+tmux attach -t $sessid
+tmux kill-session -t $sessid
diff --git a/pwclient b/pwclient
new file mode 100755
index 0000000..a496e3f
--- a/dev/null
+++ b/pwclient
@@ -0,0 +1,463 @@
+#!/usr/bin/env python2
+#
+# Patchwork command line client
+# Copyright (C) 2008 Nate Case <[email protected]>
+#
+# This file is part of the Patchwork package.
+#
+# Patchwork is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Patchwork is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Patchwork; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+import os
+import sys
+import xmlrpclib
+import getopt
+import string
+import tempfile
+import subprocess
+import base64
+import ConfigParser
+
+# Default Patchwork remote XML-RPC server URL
+# This script will check the PW_XMLRPC_URL environment variable
+# for the URL to access. If that is unspecified, it will fallback to
+# the hardcoded default value specified here.
+DEFAULT_URL = "http://patchwork/xmlrpc/"
+CONFIG_FILES = [os.path.expanduser('~/.pwclientrc')]
+
+class Filter:
+ """Filter for selecting patches."""
+ def __init__(self):
+ # These fields refer to specific objects, so they are special
+ # because we have to resolve them to IDs before passing the
+ # filter to the server
+ self.state = ""
+ self.project = ""
+
+ # The dictionary that gets passed to via XML-RPC
+ self.d = {}
+
+ def add(self, field, value):
+ if field == 'state':
+ self.state = value
+ elif field == 'project':
+ self.project = value
+ else:
+ # OK to add directly
+ self.d[field] = value
+
+ def resolve_ids(self, rpc):
+ """Resolve State, Project, and Person IDs based on filter strings."""
+ if self.state != "":
+ id = state_id_by_name(rpc, self.state)
+ if id == 0:
+ sys.stderr.write("Note: No State found matching %s*, " \
+ "ignoring filter\n" % self.state)
+ else:
+ self.d['state_id'] = id
+
+ if self.project != "":
+ id = project_id_by_name(rpc, self.project)
+ if id == 0:
+ sys.stderr.write("Note: No Project found matching %s, " \
+ "ignoring filter\n" % self.project)
+ else:
+ self.d['project_id'] = id
+
+ def __str__(self):
+ """Return human-readable description of the filter."""
+ return str(self.d)
+
+class BasicHTTPAuthTransport(xmlrpclib.SafeTransport):
+
+ def __init__(self, username = None, password = None, use_https = False):
+ self.username = username
+ self.password = password
+ self.use_https = use_https
+ xmlrpclib.SafeTransport.__init__(self)
+
+ def authenticated(self):
+ return self.username != None and self.password != None
+
+ def send_host(self, connection, host):
+ xmlrpclib.Transport.send_host(self, connection, host)
+ if not self.authenticated():
+ return
+ credentials = '%s:%s' % (self.username, self.password)
+ auth = 'Basic ' + base64.encodestring(credentials).strip()
+ connection.putheader('Authorization', auth)
+
+ def make_connection(self, host):
+ if self.use_https:
+ fn = xmlrpclib.SafeTransport.make_connection
+ else:
+ fn = xmlrpclib.Transport.make_connection
+ return fn(self, host)
+
+def usage():
+ sys.stderr.write("Usage: %s <action> [options]\n\n" % \
+ (os.path.basename(sys.argv[0])))
+ sys.stderr.write("Where <action> is one of:\n")
+ sys.stderr.write(
+""" apply <ID> : Apply a patch (in the current dir, using -p1)
+ get <ID> : Download a patch and save it locally
+ projects : List all projects
+ states : Show list of potential patch states
+ list [str] : List patches, using the optional filters specified
+ below and an optional substring to search for patches
+ by name
+ search [str] : Same as 'list'
+ view <ID> : View a patch
+ update [-s state] [-c commit-ref] <ID>
+ : Update patch\n""")
+ sys.stderr.write("""\nFilter options for 'list' and 'search':
+ -s <state> : Filter by patch state (e.g., 'New', 'Accepted', etc.)
+ -p <project> : Filter by project name (see 'projects' for list)
+ -w <who> : Filter by submitter (name, e-mail substring search)
+ -d <who> : Filter by delegate (name, e-mail substring search)
+ -n <max #> : Restrict number of results\n""")
+ sys.stderr.write("""\nActions that take an ID argument can also be \
+invoked with:
+ -h <hash> : Lookup by patch hash\n""")
+ sys.exit(1)
+
+def project_id_by_name(rpc, linkname):
+ """Given a project short name, look up the Project ID."""
+ if len(linkname) == 0:
+ return 0
+ projects = rpc.project_list(linkname, 0)
+ for project in projects:
+ if project['linkname'] == linkname:
+ return project['id']
+ return 0
+
+def state_id_by_name(rpc, name):
+ """Given a partial state name, look up the state ID."""
+ if len(name) == 0:
+ return 0
+ states = rpc.state_list(name, 0)
+ for state in states:
+ if state['name'].lower().startswith(name.lower()):
+ return state['id']
+ return 0
+
+def person_ids_by_name(rpc, name):
+ """Given a partial name or email address, return a list of the
+ person IDs that match."""
+ if len(name) == 0:
+ return []
+ people = rpc.person_list(name, 0)
+ return map(lambda x: x['id'], people)
+
+def list_patches(patches):
+ """Dump a list of patches to stdout."""
+ print("%-5s %-12s %s" % ("ID", "State", "Name"))
+ print("%-5s %-12s %s" % ("--", "-----", "----"))
+ for patch in patches:
+ print("%-5d %-12s %s" % (patch['id'], patch['state'], patch['name']))
+
+def action_list(rpc, filter, submitter_str, delegate_str):
+ filter.resolve_ids(rpc)
+
+ if submitter_str != "":
+ ids = person_ids_by_name(rpc, submitter_str)
+ if len(ids) == 0:
+ sys.stderr.write("Note: Nobody found matching *%s*\n", \
+ submitter_str)
+ else:
+ for id in ids:
+ person = rpc.person_get(id)
+ print "Patches submitted by %s <%s>:" % \
+ (person['name'], person['email'])
+ f = filter
+ f.add("submitter_id", id)
+ patches = rpc.patch_list(f.d)
+ list_patches(patches)
+ return
+
+ if delegate_str != "":
+ ids = person_ids_by_name(rpc, delegate_str)
+ if len(ids) == 0:
+ sys.stderr.write("Note: Nobody found matching *%s*\n", \
+ delegate_str)
+ else:
+ for id in ids:
+ person = rpc.person_get(id)
+ print "Patches delegated to %s <%s>:" % \
+ (person['name'], person['email'])
+ f = filter
+ f.add("delegate_id", id)
+ patches = rpc.patch_list(f.d)
+ list_patches(patches)
+ return
+
+ patches = rpc.patch_list(filter.d)
+ list_patches(patches)
+
+def action_projects(rpc):
+ projects = rpc.project_list("", 0)
+ print("%-5s %-24s %s" % ("ID", "Name", "Description"))
+ print("%-5s %-24s %s" % ("--", "----", "-----------"))
+ for project in projects:
+ print("%-5d %-24s %s" % (project['id'], \
+ project['linkname'], \
+ project['name']))
+
+def action_states(rpc):
+ states = rpc.state_list("", 0)
+ print("%-5s %s" % ("ID", "Name"))
+ print("%-5s %s" % ("--", "----"))
+ for state in states:
+ print("%-5d %s" % (state['id'], state['name']))
+
+def action_get(rpc, patch_id):
+ patch = rpc.patch_get(patch_id)
+ s = rpc.patch_get_mbox(patch_id)
+
+ if patch == {} or len(s) == 0:
+ sys.stderr.write("Unable to get patch %d\n" % patch_id)
+ sys.exit(1)
+
+ base_fname = fname = os.path.basename(patch['filename'])
+ i = 0
+ while os.path.exists(fname):
+ fname = "%s.%d" % (base_fname, i)
+ i += 1
+
+ try:
+ f = open(fname, "w")
+ except:
+ sys.stderr.write("Unable to open %s for writing\n" % fname)
+ sys.exit(1)
+
+ try:
+ f.write(unicode(s).encode("utf-8"))
+ f.close()
+ print "Saved patch to %s" % fname
+ except:
+ sys.stderr.write("Failed to write to %s\n" % fname)
+ sys.exit(1)
+
+def action_apply(rpc, patch_id):
+ patch = rpc.patch_get(patch_id)
+ if patch == {}:
+ sys.stderr.write("Error getting information on patch ID %d\n" % \
+ patch_id)
+ sys.exit(1)
+ print "Applying patch #%d to current directory" % patch_id
+ print "Description: %s" % patch['name']
+ s = rpc.patch_get_mbox(patch_id)
+ if len(s) > 0:
+ proc = subprocess.Popen(['patch', '-p1'], stdin = subprocess.PIPE)
+ proc.communicate(s)
+ else:
+ sys.stderr.write("Error: No patch content found\n")
+ sys.exit(1)
+
+def action_update_patch(rpc, patch_id, state = None, commit = None):
+ patch = rpc.patch_get(patch_id)
+ if patch == {}:
+ sys.stderr.write("Error getting information on patch ID %d\n" % \
+ patch_id)
+ sys.exit(1)
+
+ params = {}
+
+ if state:
+ state_id = state_id_by_name(rpc, state)
+ if state_id == 0:
+ sys.stderr.write("Error: No State found matching %s*\n" % state)
+ sys.exit(1)
+ params['state'] = state_id
+
+ if commit:
+ params['commit_ref'] = commit
+
+ success = False
+ try:
+ success = rpc.patch_set(patch_id, params)
+ except xmlrpclib.Fault, f:
+ sys.stderr.write("Error updating patch: %s\n" % f.faultString)
+
+ if not success:
+ sys.stderr.write("Patch not updated\n")
+
+def patch_id_from_hash(rpc, project, hash):
+ try:
+ patch = rpc.patch_get_by_project_hash(project, hash)
+ except xmlrpclib.Fault:
+ # the server may not have the newer patch_get_by_project_hash function,
+ # so fall back to hash-only.
+ patch = rpc.patch_get_by_hash(hash)
+
+ if patch == {}:
+ return None
+
+ return patch['id']
+
+auth_actions = ['update']
+
+def main():
+ try:
+ opts, args = getopt.getopt(sys.argv[2:], 's:p:w:d:n:c:h:')
+ except getopt.GetoptError, err:
+ print str(err)
+ usage()
+
+ if len(sys.argv) < 2:
+ usage()
+
+ action = sys.argv[1].lower()
+
+ # set defaults
+ filt = Filter()
+ submitter_str = ""
+ delegate_str = ""
+ project_str = ""
+ commit_str = ""
+ state_str = ""
+ hash_str = ""
+ url = DEFAULT_URL
+
+ config = ConfigParser.ConfigParser()
+ config.read(CONFIG_FILES)
+
+ # grab settings from config files
+ if config.has_option('base', 'url'):
+ url = config.get('base', 'url')
+
+ if config.has_option('base', 'project'):
+ project_str = config.get('base', 'project')
+
+ for name, value in opts:
+ if name == '-s':
+ state_str = value
+ elif name == '-p':
+ project_str = value
+ elif name == '-w':
+ submitter_str = value
+ elif name == '-d':
+ delegate_str = value
+ elif name == '-c':
+ commit_str = value
+ elif name == '-h':
+ hash_str = value
+ elif name == '-n':
+ try:
+ filt.add("max_count", int(value))
+ except:
+ sys.stderr.write("Invalid maximum count '%s'\n" % value)
+ usage()
+ else:
+ sys.stderr.write("Unknown option '%s'\n" % name)
+ usage()
+
+ if len(args) > 1:
+ sys.stderr.write("Too many arguments specified\n")
+ usage()
+
+ (username, password) = (None, None)
+ transport = None
+ if action in auth_actions:
+ if config.has_option('auth', 'username') and \
+ config.has_option('auth', 'password'):
+
+ use_https = url.startswith('https')
+
+ transport = BasicHTTPAuthTransport( \
+ config.get('auth', 'username'),
+ config.get('auth', 'password'),
+ use_https)
+
+ else:
+ sys.stderr.write(("The %s action requires authentication, "
+ "but no username or password\nis configured\n") % action)
+ sys.exit(1)
+
+ if project_str:
+ filt.add("project", project_str)
+
+ if state_str:
+ filt.add("state", state_str)
+
+ try:
+ rpc = xmlrpclib.Server(url, transport = transport)
+ except:
+ sys.stderr.write("Unable to connect to %s\n" % url)
+ sys.exit(1)
+
+ patch_id = None
+ if hash_str:
+ patch_id = patch_id_from_hash(rpc, project_str, hash_str)
+ if patch_id is None:
+ sys.stderr.write("No patch has the hash provided\n")
+ sys.exit(1)
+
+
+ if action == 'list' or action == 'search':
+ if len(args) > 0:
+ filt.add("name__icontains", args[0])
+ action_list(rpc, filt, submitter_str, delegate_str)
+
+ elif action.startswith('project'):
+ action_projects(rpc)
+
+ elif action.startswith('state'):
+ action_states(rpc)
+
+ elif action == 'view':
+ try:
+ patch_id = patch_id or int(args[0])
+ except:
+ sys.stderr.write("Invalid patch ID given\n")
+ sys.exit(1)
+
+ s = rpc.patch_get_mbox(patch_id)
+ if len(s) > 0:
+ print unicode(s).encode("utf-8")
+
+ elif action == 'get' or action == 'save':
+ try:
+ patch_id = patch_id or int(args[0])
+ except:
+ sys.stderr.write("Invalid patch ID given\n")
+ sys.exit(1)
+
+ action_get(rpc, patch_id)
+
+ elif action == 'apply':
+ try:
+ patch_id = patch_id or int(args[0])
+ except:
+ sys.stderr.write("Invalid patch ID given\n")
+ sys.exit(1)
+
+ action_apply(rpc, patch_id)
+
+ elif action == 'update':
+ try:
+ patch_id = patch_id or int(args[0])
+ except:
+ sys.stderr.write("Invalid patch ID given\n")
+ sys.exit(1)
+
+ action_update_patch(rpc, patch_id, state = state_str,
+ commit = commit_str)
+
+ else:
+ sys.stderr.write("Unknown action '%s'\n" % action)
+ usage()
+
+if __name__ == "__main__":
+ main()