Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

Saturday, 31 March 2012

Windows Command Line History in CMD.EXE

I just found out about these!



  • F1: Pastes the last executed command (character by character)
  • F2: Pastes the last executed command (up to the entered character)
  • F3: Pastes the last executed command
  • F4: Deletes current prompt text up to the entered character
  • F5: Pastes recently executed commands (does not cycle)
  • F6: Pastes ^Z to the prompt
  • F7: Displays a selectable list of previously executed commands
  • F8: Pastes recently executed commands (cycles)
  • F9: Asks for the number of the command from the F7 list to paste

Installing Python nicely on Windows box

At the time of writing despite x64 Windows use Python 2.7 (not 3.0) and x86 (not x64).
The Windows virtualenv wrapper notes are here: https://github.com/davidmarble/virtualenvwrapper-win

At this point ready to use VirtualEnv, along with requirements files etc. I suppose the process might look something like this:

  • make project folder new_proj
  • cd into new_proj
  • make requirements.txt
  • edit requirements.txt add say "flask"
  • mkvirtualenv new_proj_env
  • pip install -r requirements.txt
Additionally the postgres database driver might be required. This is in combination with a local installation of Postgres.

Tuesday, 24 August 2010

COM / DCOM In Python : The comtypes library

There 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:


For more hardcore COM stuff you need to use the much lower level and partly undocumented comtypes library. The following bullets define "hardcore":
  • Subscribing to a COM event notification sink.
  • Building your own COM server (are you mad?)
  • Sending and receiving more complex datatypes.
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.

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.

Download it and give it a try. Python 3.0 is unsupported afaik.
Do read the existing documentation. Carefully, what exists is of good quality.
Use the mailing list archive. Seriously, its the only way forward.
Have the IDL handy. 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.

Turn on logging. If you're having issues you can turn on comtypes logging.


Read the source of comtypes. 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:
  • C:\Python26\Lib\site-packages\comtypes
Files which I found of interest were __init__.py, automation.py (types) and client._events.py (for events stuff).

Understand the type coercion. 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):
Keep your Sink in scope. 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().

Understand the domain. 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:
  • Interface
  • VARIANT
  • Pointer
  • Structure
  • Array
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).

Built on ctypes. Be mindful the comtypes is build upon ctypes, especially when you get into type based confusion the docs there can be very enlightening.

Friday, 16 April 2010

Putty Colours Config

Just pop this here - for setup on Windows machine:

dag.wieers.com/blog/content/improving-putty-settings-on-windows

Don't forget to save this as your "default settings".

Another nice touch is turning font anti-aliasing on and selecting a funkier font.

Saturday, 24 October 2009

Run CENTOS VM in background on Windows for Free with VMware

A developer at work wanted to do this and here are the pointers I gave him.
  1. Download VMware Server for free from VMware. [http://www.vmware.com/products/server/]
  2. Download the ISO for CENTOS and put it in your "C:\Virtual Machines" folder, then mount it from within VMware from the "Datastore". [I get them from http://www.kernel.org]
  3. Make sure the Intel VM Extensions are enabled in your BIOS if you have them.
  4. Install CENTOS on VM as you would for a Physical PC.
  5. Setup SSH and SCP and then interact with your box via PuTTY, WinSCP and HTTP.
He seemed pretty pleased with the outcome.