<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>nazham.com &#187; Programming</title>
	<atom:link href="http://nazham.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://nazham.com</link>
	<description>Jarvis, sometimes you gotta run before you can walk.</description>
	<lastBuildDate>Tue, 01 Jun 2010 06:07:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Extend Transmission Torrent with Scripts</title>
		<link>http://nazham.com/2009/04/19/extend-transmission-torrent-with-scripts/</link>
		<comments>http://nazham.com/2009/04/19/extend-transmission-torrent-with-scripts/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 13:10:03 +0000</pubDate>
		<dc:creator>nazham</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://nazham.com/?p=893</guid>
		<description><![CDATA[Transmission is one of my favourite bittorrent client. However, it&#8217;s lack the feature of running command(s) before or after you have finished downloading. Luckily we can improvise this with the help of transmission-remote, a command based client for transmission, and along with some Linux bash scripting.
Below I have created a simple bash script. What it [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.transmissionbt.com/">Transmission</a> is one of my favourite bittorrent client. However, it&#8217;s lack the feature of running command(s) before or after you have finished downloading. Luckily we can improvise this with the help of <strong>transmission-remote</strong>, a command based client for transmission, and along with some Linux bash scripting.</p>
<p>Below I have created a simple bash script. What it does is, converting all of the finished avi&#8217;s to wmv. The conversion is via <a href="http://www.ffmpeg.org/">ffmpeg</a>. The script below is easily modified to suit your needs, such as:<br />
i &#8211; Copying the finished torrent to another location.<br />
ii &#8211; Doing any conversion to your media.<br />
iii &#8211; Send you mail notifying the torrent have finished downloading.<br />
iv &#8211; etc, etc.</p>
<p>So, let&#8217;s get started.<br />
<span id="more-893"></span></p>
<p>1. Install transmission-remote<br />
<code>sudo apt-get install transmission-remote</code></p>
<p>2. Copy the script below, and save as my_script_name.sh , (or whatever name you prefer, but note the .sh extension).<br />
This is among my early attempts of shell script programming, so go easy on me and feel free to give feedbacks. <img src='http://nazham.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre>
#!/bin/sh

# The absolute path where your torrents are downloaded
# For example: /tmp/download
BASEDIR=/home/myuser/mytorrentpath
LOGPATH=/home/myuser/mywmv.log

# The absolute path to and including the transmission-remote binary
# For example: /usr/bin/transmission-remote
TRANSREMOTE=/usr/bin/transmission-remote
TRANSOPTS=" 127.0.0.1:my_port_number -n my_username:my_password "

DoConvert ()
{
  _AVINAME=$1
  WMVNAME=${_AVINAME%.*}".wmv"
  if [ ! -f "$WMVNAME" ]; then
    #Do conversion here
    echo "converting $_AVINAME" >> $LOGPATH
    ffmpeg -sameq -i "$_AVINAME" -vcodec wmv2 -acodec wmav2 "$WMVNAME" \
    < /dev/null 2> /dev/null
  fi
}

cd $BASEDIR

echo "Starting at `date`" >> $LOGPATH

# Find the first completed torrent
$TRANSREMOTE $TRANSOPTS -l | grep "100%" | grep "Done  " | cut -b71- | while read LINE
do
  if [ -e "$LINE" ]; then
    if [ -h "$LINE" ]; then
      echo "$LINE is already moved" >> $LOGPATH
    else
      if [ -d "$LINE" ]; then
        cd "${LINE}"
        ls -1f *.avi 2>/dev/null | while read AVINAME
	  do
	    DoConvert "$AVINAME"
	  done
        cd -
      else
	DoConvert "$LINE"
      fi
    fi
  else
    echo "torrent $LINE is removed" >> $LOGPATH
  fi
done

echo "-----------------" >> $LOGPATH
</pre>
<p>Save the script on any location you prefer.</p>
<p>3. Create a cron job to run the script. Open the entry to crontab:<br />
<code>crontab -e</code></p>
<p>4. Let say you want to run the script every hour, by the hour, the entry on your cron job should be as below:<br />
<code>0 * * * * sh /home/myuser/my_script_name.sh</code></p>
<p>You can also test the script you&#8217;ve created by executing the command:<br />
<code>sh /home/myuser/my_script_name.sh</code></p>
<p>Enjoy.</p>
<iframe id="basic_facebook_social_plugins_likebutton" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fnazham.com%2F2009%2F04%2F19%2Fextend-transmission-torrent-with-scripts%2F&amp;layout=standard&amp;show_faces=true&amp;width=&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:px; height:px"></iframe>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://nazham.com/2009/04/19/extend-transmission-torrent-with-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python: Executing a Program on a Remote 64-bit Windows Machine</title>
		<link>http://nazham.com/2008/12/17/python-executing-a-program-on-a-remote-64-bit-windows-machine/</link>
		<comments>http://nazham.com/2008/12/17/python-executing-a-program-on-a-remote-64-bit-windows-machine/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 07:52:43 +0000</pubDate>
		<dc:creator>nazham</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://nazham.com/?p=628</guid>
		<description><![CDATA[Executing a program, exe&#8217;s, services on a remote Windows machine can be accomplished very easily, with a very few lines of code in Python. The task is similar to Psexec. However, in Python, one of the ways is using Windows Management Instrumentation (WMI).
From Tim Golden&#8217;s Python Stuff:
Windows Management Instrumentation (WMI) is Microsoft&#8217;s implementation of Web-Based Enterprise Management [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>Executing a program, exe&#8217;s, services on a remote Windows machine can be accomplished very easily, with a very few lines of code in Python. The task is similar to <a href="http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx" target="_blank">Psexec</a>. However, in Python, one of the ways is using Windows Management Instrumentation (WMI).</p>
<p>From <a href="http://timgolden.me.uk/python/wmi.html" target="_blank">Tim Golden&#8217;s Python Stuff</a>:</p>
<blockquote><p>Windows Management Instrumentation (WMI) is Microsoft&#8217;s implementation of Web-Based Enterprise Management (WBEM), an industry initiative to provide a Common Information Model (CIM) for pretty much any information about a computer system.</p></blockquote>
<p>Executing remote program using WMI needs the <a href="http://starship.python.net/crew/mhammond/" target="_blank">win32 extensions from Mark Hammond</a>. Below are one of the sample code that I&#8217;ve used on a 32-bit target machine:</p>
<pre>c = wmi.WMI ('my_remote_windows_machine')
process_id, result = c.Win32_Process.Create (CommandLine="Notepad.exe")
    for process in c.Win32_Process (ProcessId=process_id):
        returnvalue = str(process.ProcessId) + " " + str(process.Name)

    if result == 0:
        returnvalue = "Process started successfully: %s" % returnvalue
    else:
        raise RuntimeError, "Problem creating process: %s" % str(result)
    print returnvalue</pre>
<p> </p>
<p>However, when it comes to 64-bit target machines, I&#8217;m getting errors below:</p>
<pre>  File "C:\Python26\lib\wmi.py", line 1181, in connect
    return _wmi_namespace (obj, find_classes)
  File "C:\Python26\lib\wmi.py", line 821, in __init__
    self.classes.update (self.subclasses_of ())
  File "C:\Python26\lib\wmi.py", line 843, in subclasses_of
    for c in self._namespace.SubclassesOf (root):
  File "C:\Python26\Lib\site-packages\win32com\client\util.py", line 84, in next

    return _get_good_object_(self._iter_.next(), resultCLSID = self.resultCLSID)</pre>
<p> </p>
<p><strong>The solution:</strong></p>
<pre>c = wmi.WMI ('my_remote_windows_machine', find_classes=False)
process_id, result = c.Win32_Process.Create (CommandLine="Notepad.exe")
    for process in c.Win32_Process (ProcessId=process_id):
        returnvalue = str(process.ProcessId) + " " + str(process.Name)

    if result == 0:
        returnvalue = "Process started successfully: %s" % returnvalue
    else:
        raise RuntimeError, "Problem creating process: %s" % str(result)
    print returnvalue</pre>
<p>Notice the extra parameter <strong>find_classes=False</strong> when instantiating the WMI object.<br />
Some of the good examples on WMI in Python:<br />
<a href="http://timgolden.me.uk/python/wmi.html" target="_blank">Tim Golden&#8217;s Python Stuff</a><br />
<a href="http://timgolden.me.uk/python/wmi_cookbook.html" target="_blank">WMI Cookbook</a></p>
<iframe id="basic_facebook_social_plugins_likebutton" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fnazham.com%2F2008%2F12%2F17%2Fpython-executing-a-program-on-a-remote-64-bit-windows-machine%2F&amp;layout=standard&amp;show_faces=true&amp;width=&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:px; height:px"></iframe>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://nazham.com/2008/12/17/python-executing-a-program-on-a-remote-64-bit-windows-machine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python Programming Language</title>
		<link>http://nazham.com/2008/11/28/nazham-python-the-programming-language/</link>
		<comments>http://nazham.com/2008/11/28/nazham-python-the-programming-language/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 14:44:00 +0000</pubDate>
		<dc:creator>nazham</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://nazham.com/?p=553</guid>
		<description><![CDATA[It has been almost a month now since I&#8217;ve started application development in Python. Before this, I&#8217;ve already started playing with it in my spare time. (Yeah, instead of doing important stuff like mowing the lawn, fixing the light bulb, or playing with my children, I&#8217;ve decided to learn a new programming language! I really [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>It has been almost a month now since I&#8217;ve started application development in <a href="http://www.python.org/" target="_blank">Python</a>. Before this, I&#8217;ve already started playing with it in my spare time. (Yeah, instead of doing important stuff like mowing the lawn, fixing the light bulb, or playing with my children, I&#8217;ve decided to learn a new programming language! I really need to set my priorities straight).</p>
<p>Before this my encounter with Python is merely just a few samples, consists of some web forms and web pages, using <a href="http://www.modpython.org/" target="_blank">mod_python</a> configured on <a href="http://www.apache.org/" target="_blank">Apache</a> running on my headless <a href="http://www.centos.org/" target="_blank">CentOS</a> box (VM actually). Run a few queries against <a href="http://www.mysql.com/" target="_blank">MySQL</a> using <a href="http://sourceforge.net/projects/mysql-python" target="_blank">MySQLdb</a> module, returns a few results, display it on the web apps, and that&#8217;s it! The experience is limited, but enough to learn it&#8217;s syntax and flow.</p>
<p>Now I&#8217;m developing actual program in Python at work. (Finally, something to add to my resume <img src='http://nazham.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ). It&#8217;s more of a client-server application, but involves a lot of components and API&#8217;s to get around with. I&#8217;ve been using win32api&#8217;s, win32net, Windows Services, WMI for remote execution, etc, etc. At times I felt my head is going to explode. But, it&#8217;s fun! At least I have something to wake up every morning to.</p>
<p><a href="http://en.wikipedia.org/wiki/Python_(programming_language)" target="_blank">Wiki</a>:</p>
<blockquote><p>Python is a general-purpose, high-level programming language. Its design philosophy emphasizes programmer productivity and code readability. Python&#8217;s core syntax and semantics are minimalistic, while the standard library is large and comprehensive. Its use of whitespace as block delimiters is unusual among popular programming languages.</p>
<p>Python supports multiple programming paradigms (primarily object oriented, imperative, and functional) and features a fully dynamic type system and automatic memory management, similar to Perl, Ruby, Scheme, and Tcl. Like other dynamic languages, Python is often used as a scripting language.</p></blockquote>
<p>Useful Links For Python:<br />
<a href="http://www.awaretek.com/tutorials.html" target="_blank">Python Tutorials</a> (Lots of tutorial, from beginners to advanced)<br />
<a href="http://code.activestate.com/recipes/langs/python/" target="_blank">code.activestate.com</a> (My favorite. Lots of actual running source codes)<br />
<a href="http://www-128.ibm.com/developerworks/library/l-cheatsheet3.html" target="_blank">Python 101 Cheat Sheet</a></p>
<p>IDE of Choice:<br />
<a href="http://www.activestate.com/index.mhtml" target="_blank">Komodo IDE</a><br />
<a href="http://www.activestate.com/Products/komodo_ide/komodo_edit.mhtml" target="_blank">Komodo Edit</a> (Free)<br />
<a href="http://www.aptana.com/python" target="_blank">Aptana Pydev</a> (Free)</p>
<p><a href="http://wiki.python.org/moin/OrganizationsUsingPython" target="_blank">Organizations using Python</a>: Yahoo Maps, Yahoo Groups, <a href="http://highscalability.com/google-architecture" target="_blank">Google</a>, <a href="http://highscalability.com/youtube-architecture" target="_blank">YouTube</a></p>
<p>Any experience or opinions on Python? What your IDE of choice? For those who&#8217;re interested, expect more post regarding Python soon. Source codes, samples and more.</p>
<iframe id="basic_facebook_social_plugins_likebutton" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fnazham.com%2F2008%2F11%2F28%2Fnazham-python-the-programming-language%2F&amp;layout=standard&amp;show_faces=true&amp;width=&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:px; height:px"></iframe>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://nazham.com/2008/11/28/nazham-python-the-programming-language/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
