tag:blogger.com,1999:blog-53723318111995728142024-02-19T15:44:41.527-08:00Things I've Learned About I.T.More of a paste-bin than a monologue.Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.comBlogger70125tag:blogger.com,1999:blog-5372331811199572814.post-66282098131520076102012-04-28T01:53:00.000-07:002012-04-29T04:10:20.539-07:00Creating a Python App on HerokuNeed a requirements file containing all items plus:<br />
<br />
<blockquote class="tr_bq">
distribute<br/>
gunicorn==0.13.4
</blockquote>
<br />
Plus a Procfile:
<blockquote class="tr_bq">
web: gunicorn app:app -b 0.0.0.0:$PORT -w 3
</blockquote>
<br />
Then you just go:
<blockquote class="tr_bq">
heroku login<br />
heroku create --stack cedar<br />
git push heroku master<br />
heroku ps:scale web=1</blockquote>
<br />Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com0tag:blogger.com,1999:blog-5372331811199572814.post-71349917769103194242012-03-31T04:05:00.003-07:002012-03-31T04:05:29.260-07:00Windows Command Line History in CMD.EXEI just found out about these!<br />
<br />
<br />
<br />
<ul>
<li>F1: Pastes the last executed command (character by character)</li>
<li>F2: Pastes the last executed command (up to the entered character)</li>
<li>F3: Pastes the last executed command</li>
<li>F4: Deletes current prompt text up to the entered character</li>
<li>F5: Pastes recently executed commands (does not cycle)</li>
<li>F6: Pastes ^Z to the prompt</li>
<li>F7: Displays a selectable list of previously executed commands</li>
<li>F8: Pastes recently executed commands (cycles)</li>
<li>F9: Asks for the number of the command from the F7 list to paste</li>
</ul>
<br />Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com0tag:blogger.com,1999:blog-5372331811199572814.post-70648204222327272572012-03-31T01:54:00.001-07:002012-03-31T03:29:49.276-07:00Installing Python nicely on Windows boxAt the time of writing despite x64 Windows use Python 2.7 (not 3.0) and x86 (not x64).<br />
<ul>
<li>Install Python latest 2.7 from msi <a href="http://www.python.org/download/">http://www.python.org/download/</a></li>
<li>Install Setuptools from msi <a href="http://pypi.python.org/pypi/setuptools#windows">http://pypi.python.org/pypi/setuptools#windows</a>
</li>
<li>Add C:\Python27\Scripts to %PATH% environment variable.</li>
<li>cmd, run 'easy_install pip'</li>
<li>cmd, run 'pip install virtualenv'</li>
<li>cmd. run 'pip install virtualenvwrapper-win'</li>
</ul>
<div>
The Windows virtualenv wrapper notes are here: <a href="https://github.com/davidmarble/virtualenvwrapper-win">https://github.com/davidmarble/virtualenvwrapper-win</a><br />
<br />
At this point ready to use VirtualEnv, along with requirements files etc. I suppose the process might look something like this:<br />
<br />
<ul>
<li>make project folder new_proj</li>
<li>cd into new_proj</li>
<li>make requirements.txt</li>
<li>edit requirements.txt add say "flask"</li>
<li>mkvirtualenv new_proj_env</li>
<li>pip install -r requirements.txt</li>
</ul>
<div>
Additionally the postgres database driver might be required. This is in combination with a local installation of Postgres.<br />
<br />
<ul>
<li>This can be downloaded from : <a href="http://www.stickpeople.com/projects/python/win-psycopg/">http://www.stickpeople.com/projects/python/win-psycopg/</a></li>
<li>I like installing it as a global package.</li>
<li>This does involve enabling pass through to global packages per:
<a href="http://stackoverflow.com/questions/3371136/revert-the-no-site-packages-option-with-virtualenv">http://stackoverflow.com/questions/3371136/revert-the-no-site-packages-option-with-virtualenv</a></li>
</ul>
</div>
</div>Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com0tag:blogger.com,1999:blog-5372331811199572814.post-60957963706012128382012-03-30T02:00:00.005-07:002012-04-04T00:21:33.035-07:00Useful Windows utilities and tools for Java and Python developmentNew SSD drive on laptop, new install of Windows 7. Recording tools as I install them:<br />
<br />
General<br />
<br />
<ul>
<li>Rapid Environment Editor <a href="http://www.rapidee.com/en/about">http://www.rapidee.com/en/about</a></li>
<li>Paint.Net <a href="http://www.getpaint.net/download.html">http://www.getpaint.net/download.html</a></li>
<li>Notepad++
<a href="http://notepad-plus-plus.org/download/v6.0.html">http://notepad-plus-plus.org/download/v6.0.html</a></li>
<li>Agent Ransack
<a href="http://www.mythicsoft.com/page.aspx?page=download&type=agentransack">http://www.mythicsoft.com/page.aspx?page=download&type=agentransack</a></li>
</ul>
<br />
Development [General]<br />
<br />
<ul>
<li>IntelliJ <a href="http://www.jetbrains.com/idea/download/index.html">http://www.jetbrains.com/idea/download/index.htm</a></li>
<li>Git for Windows </li>
<ul>
<li>Install <a href="http://code.google.com/p/msysgit/downloads/list?can=1&q=">http://code.google.com/p/msysgit/downloads/list?can=1&q=</a></li>
<li>Add public key <a href="http://help.github.com/win-set-up-git/">http://help.github.com/win-set-up-git</a></li>
</ul>
<li>TortoiseHg <a href="http://tortoisehg.bitbucket.org/download/index.html">http://tortoisehg.bitbucket.org/download/index.html</a></li>
</ul>
<br />
Development [Java]<br />
<br />
<ul>
<li>Java SDK <a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html">http://www.oracle.com/technetwork/java/javase/downloads/index.html</a></li>
<li>Ant <a href="http://ant.apache.org/bindownload.cgi">http://ant.apache.org/bindownload.cgi</a></li>
</ul>
<br />
Development [Python]<br />
<ul>
<li>Python
<a href="http://www.python.org/download/">http://www.python.org/download/</a></li>
<ul>
<li><a href="http://things-ive-learned-about-it.blogspot.co.uk/2012/03/installing-python-nicely-on-windows-box.html">http://things-ive-learned-about-it.blogspot.co.uk/2012/03/installing-python-nicely-on-windows-box.html</a>
</li>
</ul>
<li>Postgres
<a href="http://www.postgresql.org/download/windows/">http://www.postgresql.org/download/windows/</a></li>
</ul>
<div>
<br /></div>Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com0tag:blogger.com,1999:blog-5372331811199572814.post-85311457721935049212011-10-28T02:04:00.000-07:002011-10-28T02:04:44.489-07:00Network settings from Run box in Windows 7On XP and Server 2003 it was only a few clicks, Start > Network Connections, to get at the config screens for IP/DNS/DHCP etc.<br />
<br />
In Windows 7 its hidden a million layers down behind all kind of user friendly fluff.<br />
<br />
Luckily you can simply type this into the search box (the Windows 7 version of the Run box...):<br />
<br />
<blockquote class="tr_bq">
ncpa.cpl</blockquote>
<br />
Much better!Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com0tag:blogger.com,1999:blog-5372331811199572814.post-47139619220730071522011-09-22T02:04:00.001-07:002011-09-22T02:05:01.113-07:00Avoid Sharepoint Authentication PopupOne of the most galling things about Sharepoint in the configuration we have at my place of work is that you end up retyping your credentials all the time.<div>
<br /></div>
<div>
I've previously posted some ways around this by editing security settings in IE to ensure your AD credentials are always posted through.</div>
<div>
<br /></div>
<div>
However I've found a much better solution! Use Google Chrome. Type in your credentials and the experience is seamless.</div>
Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com0tag:blogger.com,1999:blog-5372331811199572814.post-9415179995821599412011-09-22T02:02:00.000-07:002011-09-22T02:06:21.898-07:00Cannot pin Netsupport Manager to taskbar in Windows 7I access some Windows Server boxes via Netsupport Manager at work. I'd like to pin this app to the taskbar, but as it has the word "Support" in the title Microsoft have explicitly excluded this.<br />
<br />
I would have enjoyed attending the product management meeting at Microsoft where the decision to exclude any apps with "Support" in the name was made. I hope they had tea and nice biscuits!<br />
<br />
To lift this slightly baffling restriction, you can amend the following registry key:<br />
<br />
<span class="Apple-style-span" style="font-size: 13px;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileAssociation\AddRemoveNames</span></span><br />
<span class="Apple-style-span" style="background-color: white; font-family: verdana, sans-serif; font-size: 13px;"><br /></span><br />
It will probably look like this:<br />
<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">SETUP.EXE;INSTALL.EXE;ISUNINST.EXE;UNWISE.EXE;UNWISE32.EXE;ST5UNST.EXE;MSOOBE.EXE;LNKSTUB.EXE;CONTROL.EXE;SUPPORT;WERFAULT.EXE;WLRMDR.EXE;GUESTMODEMSG.EXE;MSIEXEC.EXE;DFSVC.EXE;WUAPP.EXE;</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br /></span><br />
Mine now looks like this:<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="font-family: 'Times New Roman';"><br /></span></span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">SETUP.EXE;INSTALL.EXE;ISUNINST.EXE;UNWISE.EXE;UNWISE32.EXE;ST5UNST.EXE;MSOOBE.EXE;LNKSTUB.EXE;CONTROL.EXE;WERFAULT.EXE;WLRMDR.EXE;GUESTMODEMSG.EXE;MSIEXEC.EXE;DFSVC.EXE;WUAPP.EXE</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br /></span><br />
And I can now pin NetSupport.Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com0tag:blogger.com,1999:blog-5372331811199572814.post-1145926230383578132011-04-21T13:34:00.001-07:002011-04-24T12:12:46.772-07:00SYSDATE in PostgresThe equivalent of Oracle's SYSDATE in Postgres is CURRENT_TIMESTAMP.<br />
<br />
At least in the context I needed it in!<br />
<br />
I learnt about timestamp arithmetic in Postgres from here: <a href="http://wiki.postgresql.org/wiki/Working_with_Dates_and_Times_in_PostgreSQL#WORKING_with_DATETIME.2C_DATE.2C_and_INTERVAL_VALUES">http://wiki.postgresql.org/wiki/Working_with_Dates_and_Times_in_PostgreSQL#WORKING_with_DATETIME.2C_DATE.2C_and_INTERVAL_VALUES</a>Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com3tag:blogger.com,1999:blog-5372331811199572814.post-17353374407840225512011-04-07T05:28:00.001-07:002011-04-07T05:28:08.847-07:00IntelliJ hangIf you find IntellJ just hangs and you have the kill the process, then you restart and it hangs again, its probably an issue with your JDK. I followed the steps here marked workaround:<br />
<br />
<a href="http://devnet.jetbrains.net/docs/DOC-1193">http://devnet.jetbrains.net/docs/DOC-1193</a><br />
<br />
Basically this involved editing the JVM startup properties to disable cardmarking or some such. The details are all contained in the link.<br />
<br />
IntelliJ worked perfectly afterward. Its quite ironic as I was thinking how much I liked IntelliJ just before it happened. At least it was an easy fix. I am using the version 10 Community edition.Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com0tag:blogger.com,1999:blog-5372331811199572814.post-41361045532617379832011-04-06T10:49:00.000-07:002011-04-06T10:50:49.747-07:00Windows 7 RDP SlowIf your RDP connections in Windows 7 are slow, over a VPN or whatever then go:<br />
<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">netsh interface tcp set global autotuninglevel=highlyrestricted</span><br />
<br />
From an administrator command shell on the machine initiating the RDP connection.Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com0tag:blogger.com,1999:blog-5372331811199572814.post-36331646883008608532011-03-21T09:52:00.000-07:002011-03-21T09:52:48.474-07:00Automating VMWare ESX* <a href="http://ben.neise.co.uk/index.php/2009/03/intro-to-powercli/">http://ben.neise.co.uk/index.php/2009/03/intro-to-powercli/</a>Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com0tag:blogger.com,1999:blog-5372331811199572814.post-30784146505978387352011-03-12T01:01:00.000-08:002011-03-12T01:01:08.839-08:00Various Thoughts on PuppetFor: <a href="http://lsimons.wordpress.com/2011/01/04/fusion-puppet-gitolite/">http://lsimons.wordpress.com/2011/01/04/fusion-puppet-gitolite/</a><br />
<br />
Against: <a href="http://blog.ianbicking.org/2010/03/10/configuration-management-push-vs-pull/">http://blog.ianbicking.org/2010/03/10/configuration-management-push-vs-pull/</a>Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com0tag:blogger.com,1999:blog-5372331811199572814.post-45536539987115046452011-03-06T05:59:00.001-08:002011-03-06T05:59:50.227-08:00Behaviour Driven Development<a href="http://dannorth.net/introducing-bdd/">http://dannorth.net/introducing-bdd/</a>Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com0tag:blogger.com,1999:blog-5372331811199572814.post-46664546627008869532011-02-14T13:41:00.000-08:002011-02-14T14:08:53.932-08:00WebLogic silent.xml for Centos / RHEL 5.5 Production<div>Oracle do provide a sample, and there are links on the Web but after much frustration, this one actually works.</div><br />
<script src="https://gist.github.com/826606.js?file=silent.xml">
</script><br />
<br />
<div>Assuming the bin file has been downloaded from Oracle, then:<br />
<br />
<ul><li>Create the Middleware directory beforehand.</li>
<li>Specify <code>-mode=silent -silent_xml=/full/path/to/silent.xml </code>on the command line.</li>
<li>This will install everything required, but not the Server examples domain, which is dangerous on a production server.</li>
</ul></div>Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com0tag:blogger.com,1999:blog-5372331811199572814.post-16055657006532442952011-01-17T13:27:00.001-08:002011-01-17T13:30:56.614-08:00Postgresql Repo for CENTOS<a href="http://yum.pgrpms.org/rpmchart.php">http://yum.pgrpms.org/rpmchart.php</a>Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com0tag:blogger.com,1999:blog-5372331811199572814.post-38870344876298429022011-01-15T01:32:00.001-08:002011-01-15T01:32:17.132-08:00Install EPEL Repository on CENTOSJust putting this here:<br />
<br />
<blockquote><span class="Apple-style-span" style="font-family: sans-serif; font-size: 12px; line-height: 18px;"><pre style="background-color: #f9f9f9; border-bottom-color: rgb(47, 111, 171); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(47, 111, 171); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(47, 111, 171); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(47, 111, 171); border-top-style: dashed; border-top-width: 1px; color: black; font-size: 2.6ex; line-height: 1.1em; margin-bottom: 1.5ex; margin-left: 0px; margin-right: 0px; margin-top: 0.5ex; overflow-x: auto; overflow-y: auto; padding-bottom: 1em; padding-left: 1em; padding-right: 1em; padding-top: 1em;">rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm</pre></span></blockquote>Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com0tag:blogger.com,1999:blog-5372331811199572814.post-48681073571821417602011-01-12T14:30:00.000-08:002011-01-12T14:30:29.889-08:00Install latest Python on CentosThis script will download, compile and install a newer version of Python on CENTOS / RedHat 5.* in a way which respects the underlying Python 2.4 used by Yum etc.<br />
<br />
Based on <a href="http://www.venkysblog.com/install-python264-modwsgi-and-django-on-cento#more">http://www.venkysblog.com/install-python264-modwsgi-and-django-on-cento</a> and <a href="http://binarysushi.com/blog/2009/aug/19/CentOS-5-3-python-2-5-virtualevn-mod-wsgi-and-mod-rpaf/">http://binarysushi.com/blog/2009/aug/19/CentOS-5-3-python-2-5-virtualevn-mod-wsgi-and-mod-rpaf/</a>.<br />
<br />
<script src="https://gist.github.com/777001.js?file=install_python.sh">
</script>Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com1tag:blogger.com,1999:blog-5372331811199572814.post-57740148670452827972011-01-12T11:10:00.000-08:002011-01-15T04:53:12.217-08:00ZSH and .zshrcApparently ZSH is quite good so I'm going to try it out. On most Linux distros this is going to be installed anyway, but the steps are:<br />
<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">yum install zsh</span><br />
<span class="Apple-style-span" style="line-height: 19px;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">chsh -s /bin/zsh</span></span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="line-height: 19px;"><br />
</span></span><br />
<span class="Apple-style-span" style="line-height: 19px;"><span class="Apple-style-span" style="font-family: 'Times New Roman'; line-height: normal;">Here are some links about customizing it:</span></span><br />
<ul><li><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><a href="http://grml.org/zsh/zsh-lovers.pdf">http://grml.org/zsh/zsh-lovers.pdf</a></span></li>
<li><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><a href="http://stackoverflow.com/questions/171563/whats-in-your-zshrc">http://stackoverflow.com/questions/171563/whats-in-your-zshrc</a></span></li>
<li><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; line-height: 19px;"><a href="http://pthree.org/2008/11/23/727/">http://pthree.org/2008/11/23/727/</a></span></span></li>
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">
<li><a href="http://aperiodic.net/phil/prompt/"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">http://aperiodic.net/phil/prompt/</span></a></li>
<li><a href="http://jeff.robbins.ws/reference/my-zshrc-file"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">http://jeff.robbins.ws/reference/my-zshrc-file</span></a></li>
<li><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><a href="http://my.opera.com/blackbelt_jones/blog/2007/06/05/zsh-prompt-configuration-issue-solved">http://my.opera.com/blackbelt_jones/blog/2007/06/05/zsh-prompt-configuration-issue-solved</a></span></li>
</span></ul>Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com0tag:blogger.com,1999:blog-5372331811199572814.post-28697690296117575232011-01-02T07:51:00.001-08:002011-01-02T08:12:38.662-08:00UnicodeSeems like a good article, this has always seemed a little mysterious.<br />
<ul><li><a href="http://www.joelonsoftware.com/articles/Unicode.html">http://www.joelonsoftware.com/articles/Unicode.html</a></li>
</ul><div>I especially found the part about http-equiv content type useful. It had always bothered me how you could specify the character encoding after the start of the file. As it turns out it is a compromise and I am not the only person who had wondered about it.</div>Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com0tag:blogger.com,1999:blog-5372331811199572814.post-66398822695913020052010-11-30T03:50:00.000-08:002010-11-30T03:50:23.679-08:00Unit Testing In Python<ul><li><a href="http://docs.pylonshq.com/community/testing.html">http://docs.pylonshq.com/community/testing.html</a></li>
</ul><div>Worth making a note of. Also this link to the "Art of Unix Programming".</div><div><ul><li><a href="http://www.faqs.org/docs/artu/ch01s07.html">http://www.faqs.org/docs/artu/ch01s07.html</a></li>
</ul></div>Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com0tag:blogger.com,1999:blog-5372331811199572814.post-44669597889032906822010-11-02T05:36:00.000-07:002010-11-02T05:36:33.272-07:00Bug ReportsIts really important to keeping things simple and clear. This article struck me as excellent, and so I'm posting it here, so I don't forget about it.<br />
<br />
<a href="http://blogs.msdn.com/b/eric_brechner/archive/2010/11/01/am-i-bugging-you-bug-reports.aspx">http://blogs.msdn.com/b/eric_brechner/archive/2010/11/01/am-i-bugging-you-bug-reports.aspx</a>Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com0tag:blogger.com,1999:blog-5372331811199572814.post-19008467418967558572010-08-30T01:56:00.001-07:002010-10-27T04:13:04.094-07:00Seven pointers for editing in Vi / Vim<ul><li><a href="http://www.moolenaar.net/habits.html">http://www.moolenaar.net/habits.html</a></li>
<li><a href="http://www.oualline.com/vim-cook.html">http://www.oualline.com/vim-cook.html</a></li>
<li><a href="http://lucumr.pocoo.org/2010/7/29/sharing-vim-tricks">http://lucumr.pocoo.org/2010/7/29/sharing-vim-tricks</a></li>
<li><a href="http://tnerual.eriogerg.free.fr/vimqrc.html">http://tnerual.eriogerg.free.fr/vimqrc.html</a></li>
<li><a href="http://jeetworks.org/node/89">http://jeetworks.org/node/89</a></li>
<li><a href="http://jmcpherson.org/editing.html">http://jmcpherson.org/editing.html</a></li>
<li><a href="http://amix.dk/blog/post/19486#The-ultimate-vim-configuration-vimrc">http://amix.dk/blog/post/19486#The-ultimate-vim-configuration-vimrc</a></li>
</ul>Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com0tag:blogger.com,1999:blog-5372331811199572814.post-53117883764569016412010-08-29T07:09:00.001-07:002010-08-29T07:09:05.653-07:00Remote Desktop Keyboard ShortcutsHandy: <a href="http://www.codinghorror.com/blog/2006/04/remote-desktop-tips-and-tricks.html">http://www.codinghorror.com/blog/2006/04/remote-desktop-tips-and-tricks.html</a>Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com0tag:blogger.com,1999:blog-5372331811199572814.post-36446454087860688352010-08-27T03:57:00.000-07:002010-08-27T03:57:07.392-07:00Hidden Features of PythonSpotted this on StackOverflow.<br />
<br />
<a href="http://stackoverflow.com/questions/101268/hidden-features-of-python/111176#111176">http://stackoverflow.com/questions/101268/hidden-features-of-python/111176#111176</a>Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com0tag:blogger.com,1999:blog-5372331811199572814.post-15971922744443415462010-08-24T08:02:00.000-07:002010-08-27T00:41:58.169-07:00COM / DCOM In Python : The comtypes libraryThere are all kinds of crazy reasons you might want to use COM in Python. There are two main libraries for doing so. If you can use pywin32, then do- its high level, Pythonic and relatively functional. If you want to instantiate Word, or Excel, call a few methods, pass some simple data in, get some simple data back, fill your boots:<br />
<br />
<ul><li>(part of) <a href="http://sourceforge.net/projects/pywin32/files/">http://sourceforge.net/projects/pywin32/files/</a></li>
<li><a href="http://www.boddie.org.uk/python/COM.html">http://www.boddie.org.uk/python/COM.html</a> (seems a good howto)</li>
<li><a href="http://oreilly.com/catalog/pythonwin32/chapter/ch12.html">http://oreilly.com/catalog/pythonwin32/chapter/ch12.html</a> (maybe too indepth)</li>
</ul><br />
For more hardcore COM stuff you need to use the much lower level and partly undocumented comtypes library. The following bullets define "hardcore":<br />
<ul><li>Subscribing to a COM event notification sink.</li>
<li>Building your own COM server (are you mad?)</li>
<li>Sending and receiving more complex datatypes.</li>
</ul><div>It was my strong desire to automate certain tasks my group is responsible for by creating a DCOM client to hook into our management agents on the several hundred servers in our datacenter. This required an event sink.</div><div><br />
</div><div>I don't want to be unfair to comtypes, it is a great library, and when it works is very satisfying and robust. The main problems are the gaps in documentation. So without further ado, here's my pointers on using comtypes.</div><div><br />
</div><div><b>Download it and give it a try. </b>Python 3.0 is unsupported afaik.</div><div><ul><li><a href="http://sourceforge.net/projects/comtypes/">http://sourceforge.net/projects/comtypes/</a></li>
</ul><div><b>Do read the existing documentation. </b>Carefully, what exists is of good quality.</div></div><div><ul><li><a href="http://starship.python.net/crew/theller/comtypes/">http://starship.python.net/crew/theller/comtypes/</a></li>
<li><a href="http://starship.python.net/crew/theller/comtypes/server.html">http://starship.python.net/crew/theller/comtypes/server.html</a></li>
<li><a href="http://www.codeproject.com/KB/COM/python-comtypes-interop.aspx">http://www.codeproject.com/KB/COM/python-comtypes-interop.aspx</a></li>
</ul></div><div><b>Use the mailing list archive. </b>Seriously, its the only way forward.</div><div><ul><li><a href="http://sourceforge.net/search/?group_id=115265&type_of_search=mlists">http://sourceforge.net/search/?group_id=115265&type_of_search=mlists</a></li>
<li><a href="https://lists.sourceforge.net/lists/listinfo/comtypes-users/">https://lists.sourceforge.net/lists/listinfo/comtypes-users/</a></li>
</ul></div><div><b><span class="Apple-style-span" style="font-weight: normal;"><b>Have the IDL handy. </b>The IDL is the file which defines the COM interfaces for your object, which the TypeLib is generated from. Most likely, if you need to use comtypes this file will be available to you, and will be a vital reference.</span></b></div><div><b><br />
</b></div><div><b>Turn on logging. </b>If you're having issues you can turn on comtypes logging.</div><div><b><br />
</b></div><div><script src="http://gist.github.com/547656.js?file=logging%20comtypesh.py">
</script></div><div><br />
</div><div><b>Read the source of comtypes. </b>Once nice thing about Python is the source code is very readable. There are some useful comments in there also. On my machine the source can be found:</div><div><ul><li>C:\Python26\Lib\site-packages\comtypes</li>
</ul><div>Files which I found of interest were __init__.py, automation.py (types) and client._events.py (for events stuff).</div></div><div><br />
</div><div><b>Understand the type coercion. </b>Much of the work that comtypes does for you is in the type coercion. If you get stuck wondering why your specific type of VARIANT is not getting coerced quite how you expected then take a look in automation.py, and read the following Mailing list post (which should really be in the docs):</div><div><ul><li><a href="http://sourceforge.net/mailarchive/message.php?msg_id=loom.20080709T011456-715%40post.gmane.org">http://sourceforge.net/mailarchive/message.php?msg_id=loom.20080709T011456-715%40post.gmane.org</a></li>
<li><a href="http://sourceforge.net/mailarchive/message.php?msg_id=fv947v$bfm$1%40ger.gmane.org">http://sourceforge.net/mailarchive/message.php?msg_id=fv947v$bfm$1%40ger.gmane.org</a></li>
<li><a href="http://sourceforge.net/mailarchive/message.php?msg_id=g8fa1i$fjb$1%40ger.gmane.org">http://sourceforge.net/mailarchive/message.php?msg_id=g8fa1i$fjb$1%40ger.gmane.org</a></li>
</ul></div><div><b>Keep your Sink in scope. </b>This may be because I'm an idiot, but I was declaring my "advise" object in a constructor and then not keeping it. Make sure your advise object is still in scope when you call PumpEvents().</div><div><br />
</div><div><div><b>Understand the domain.</b> Chances are you are going to have to learn about the bizarre world of C++ and COM. Frankly COM could only ever have seemed to make sense to a C++ programmer. Make sure you at least have a hazy notion of the following concepts, ideally in their C++ sense:</div><div><ul><li>Interface</li>
<li>VARIANT</li>
<li>Pointer</li>
<li>Structure</li>
<li>Array</li>
</ul></div><div>Also, realize why COM came about. Back in the day Windows had "dll hell" so Microsoft wanted a "code registry" which allowed for multiple versions and implementations, rather than just a system folder full of DLLs. Java was on the horizon with the idea of the "component model" and "code reuse", and Microsoft needed to compete. RAD languages such as Delphi were getting big too - so Visual Basic compatibility was another talking point. Server side Software Engineering problems which Windows Server was being utilized to solve were getting larger than a single machine: so it made sense to whack a bit of RPC in the mix (DCOM).<br />
<br />
<b>Built on ctypes. </b>Be mindful the comtypes is build upon ctypes, especially when you get into type based confusion the docs there can be very enlightening.<br />
<br />
<ul><li><a href="http://docs.python.org/library/ctypes.html#structures-and-unions">http://docs.python.org/library/ctypes.html#structures-and-unions</a></li>
</ul></div></div>Leonig Mighttp://www.blogger.com/profile/12570823683366887121noreply@blogger.com4