Monday, November 29, 2010

PyMOTW: hmac - O'Reilly ONLamp Blog

PyMOTW: hmac - O'Reilly ONLamp Blog: "import hmac
import hashlib

digest_maker = hmac.new('secret-shared-key-goes-here', '', hashlib.sha1)

f = open('hmac_sha.py', 'rb')
try:
while True:
block = f.read(1024)
if not block:
break
digest_maker.update(block)
finally:
f.close()

digest = digest_maker.hexdigest()
print digest

- Sent using Google Toolbar"

WorkingWithTime - PythonInfo Wiki

WorkingWithTime - PythonInfo Wiki: "Working with Time

Notably missing from this page are the capabilities of the Python datetime module, which was introduced in 2.3 and is very powerful.

This page gives some basics of working with time in Python. More detail can be found in the time Module Documentation.

Formats

There are several ways to work with time:

format


Python

seconds since the 'Epoch'


time.time()

tuple


time.gmtime()

string


time.ctime()

The Epoch is January 1st, 1970, midnight, on UNIX systems. On other systems, look at the results of time.gmtime(0) to discover the date of the Epoch.

Measuring time in seconds since the Epoch is convenient for storage and comparing dates, because you only have a single number to consider.

The tuple contains several values, arranged the following way: year, month 1-12, day 1-31, hour 0-23, minutes 0-59, seconds 0-61, day 0-6 (Mon-Sun), day 1-366, and DST -1,0,+1. 'DST' means 'daylight savings time.' For more information, see time Module Documentation.

Using a tuple is convenient, because you can access particular numbers by index, and because you can easily compare dates. Remember that Python compares tuple data from front to back. The data is indexed so that comparing tuple times is intuitive.

The string format reads something like 'Mon Feb 16 16:04:25 2004'. You can't really compare these usefully, but they're what you need to display things to the user.

- Sent using Google Toolbar"

1.2 Installing ZenPacks - Open Source Network Monitoring and Systems Management

1.2 Installing ZenPacks - Open Source Network Monitoring and Systems Management: "#2. Installing ZenPacks

ZenPacks are distributed as .egg files. Zenoss also supports .zip files.

You can install ZenPacks from the command line on the Zenoss server, or from the Zenoss user interface.
#2.1. Installing from the Command Line

The following ZenPack command can be used from the command line to install ZenPack files. After installing or updating ZenPacks you need to restart Zenoss:

zenpack --install
zenoss restart

If you have the source code for the ZenPack you can install directly from that rather than from a .egg or .zip file. The command is the same, you just specify the directory containing the source code. This copies the source code into either $ZENHOME/ZenPacks (for newer egg ZenPacks) or $ZENHOME/Products (for older style ZenPacks.)

zenpack --install
zenoss restart

If you are developing a ZenPack you usually will want to maintain your source code outside of $ZENHOME/ZenPacks or $ZENHOME/Products. This is advisable for two reasons. First, if you issue a zenpack --remove command it will delete your code from either of those two locations and you would lose your files unless you had them backed up elsewhere. Second, if you are maintaining your source code in a version control system it is frequently more convenient to have the files reside elsewhere on the file system. Using the --link option you can install the ZenPack but have Zenoss use your code from its current location. Instead of installing your code in $ZENHOME/ZenPacks or $ZENHOME/Products Zenoss will create a link in one of those locations that points to your source code directory.

zenpack --link --install
zenoss restart

- Sent using Google Toolbar"

Tuesday, November 23, 2010

TurboGears "offline" processes (crons, command-line commands, etc) - Plumbing Life's Depths

TurboGears "offline" processes (crons, command-line commands, etc) - Plumbing Life's Depths: "TurboGears 'offline' processes (crons, command-line commands, etc)

TurboGears uses the Paste commands system to create command-line entry points that, for example, set up your database or start your server. When you get to larger projects, however, you will often have other things you need to do 'in the context of your application' from the command line, such as periodic imports of data, or cron'd database management tasks.

Paste's command system is well documented, but it can take quite a bit of poking around to find out how to get SQLAlchemy, and TurboGears configured so that code that looks in tg.config gets the right values, and SQLAlchemy has access to your models.

This little module (tgcommand.py) is my hacked-together attempt to make it easier to create new TG command-line commands. The idea is that for each application you will create a BaseCommand class like this:

from adminhack.commands import tgcommand
class BaseCommand( tgcommand.TGCommand ):
def import_model( self ):
from adminhack import model
return model

This command-class would then serve as the base command for each of your 'real' commands. For example, a command that iterates through all users showing their user_name property:

class Hello(BaseCommand):
def db_command( self, engine ):
from adminhack.model import User,Group, DBSession
for user in DBSession.query( User ):
print 'User',user.user_name

As with regular Paste commands you have to register your TGCommands in your application's setup.py (in the setup() call), like so:

entry_points='''
[paste.paster_command]
hellocommand = adminhack.commands.hello:Hello
''',

(you will need to re-run setup.py develop to get the command to be available). I can't claim that this is the perfect way to set up these commands, but it should work :-) .

[Update] I've done a bit of clean-up work on the base tgcommand module. The updated version is now linked above.

[Update2] A few more tweaks, one of which changes the interface so that you receive an engine pointer, rather than a DBSession pointer in db_command. This allows for the flag 'with_session' to be set on the class to create a command that can do its own DB session management (useful for database-modification and the like).

- Sent using Google Toolbar"

Sunday, November 21, 2010

How to setup Client Scripting in OpenVPN Access Server

How to setup Client Scripting in OpenVPN Access Server: "How to setup Client Scripting in OpenVPN Access Server


Sample Python Scripts
---------------------

Launch a URL:

#!/usr/bin/env python
# On VPN connection initiation, launch a URL in the default browser.
# Works on all client platforms (Windows, Mac, Linux).
# Environmental Variables:
# LAUNCH_URL -- URL to launch
import os, webbrowser
if os.environ['N_RECONNECTS'] == '0':
webbrowser.open_new(os.environ['LAUNCH_URL'])

Download and install an application on Windows:

#!/usr/bin/env python
# Download and install an MSI-based application on Windows. Leave a marker
# file behind, so that we only install the application once per local user.
# Environmental Variables:
# MSI_URL -- URL of MSI file
# MSI_HASH -- sha1 hash of MSI file, for security verification
# MSI_OPT (optional) -- extra MSI arguments, such as /q for quiet install
import os, urllib, scripthelper as sh
url = os.environ['MSI_URL']
local = os.path.basename(url)
hash = os.environ['MSI_HASH']
if not os.path.exists(hash):
urllib.urlretrieve(url, local)
if sh.digest_file(local, 'sha1') != hash:
raise ValueError("downloaded file has incorrect hash")
os.system("msiexec /i %s %s /l* msi.log" % (local, os.environ.get('MSI_OPT', '')))
file(hash, 'w').write('')


- Sent using Google Toolbar"

Wednesday, November 17, 2010

Friday, November 12, 2010

Custom Filters - Zimbra :: Forums

Custom Filters - Zimbra :: Forums: "sieve - you can even convert from procmail:/forums/users/7239-any-way-add-message-filters-command-line.html

very simply it's kinda like:
zmprov modifyAccount user@domain.com zimbraMailSieveScript 'require ['fileinto', 'reject', 'tag', 'flag']

or there's always:
zmmailbox -z -m user@domain.com addFilterRule 'tag special' active any header 'subject' contains 'special' tag 'special' stop
-this should also add it into the user's list of rules to manage from the web interface

- Sent using Google Toolbar"

Friday, November 5, 2010

SQLite Frequently Asked Questions

SQLite Frequently Asked Questions: "(11) How do I add or delete columns from an existing table in SQLite.

SQLite has limited ALTER TABLE support that you can use to add a column to the end of a table or to change the name of a table. If you want to make more complex changes in the structure of a table, you will have to recreate the table. You can save existing data to a temporary table, drop the old table, create the new table, then copy the data back in from the temporary table.

For example, suppose you have a table named 't1' with columns names 'a', 'b', and 'c' and that you want to delete column 'c' from this table. The following steps illustrate how this could be done:

BEGIN TRANSACTION;
CREATE TEMPORARY TABLE t1_backup(a,b);
INSERT INTO t1_backup SELECT a,b FROM t1;
DROP TABLE t1;
CREATE TABLE t1(a,b);
INSERT INTO t1 SELECT a,b FROM t1_backup;
DROP TABLE t1_backup;
COMMIT;


- Sent using Google Toolbar"

Wednesday, November 3, 2010

How-to: Convert mysql to sqlite | JBipNet

How-to: Convert mysql to sqlite | JBipNet: "--compatible=ansi --skip-opt generator > dumpfile

- Sent using Google Toolbar"