Not so useful

Saturday, June 16, 2007

Picasa Web Albums upload script

Recently I was searching for some simple way to upload a bunch of photos
to Picasa Web Albums. After some searches I found this post:
http://wanted.eu.org/en/computers/linux/uploading_photos_to_picasaweb

The script provided there did the thing for me, but it was creating a new
album every time it was used. Looking through code give me some ideas on
how to implement some more features. So I installed gdata-python-client
from Google and write some code from the scratch.

Here's what I've got:


Usage: upload2picasa.py [options] albumname filename1.jpg filename2.jpg
...

Uploads jpeg files to Google's Picasa Web Albums service.
Running for the first time will ask for login/password and save them
to ~/.google_auth (be sure to check its access rights, password is
stored as plain text).

Options:
-h, --help show this help message and exit
-i, --init call in init mode, asking login/password
-l, --list list user's albums
-p, --public create album as public (private by default)
-n, --new create new album (even if the album w/same name exists)

This is a script for uploading photos to Picasa Web Albums, with some
handy features. For more information including some examples, visit it's
page at Google Code: http://code.google.com/p/upload2picasa

Sunday, June 10, 2007

per-user language settings in Gnome

To have per-user default language settings in Gnome (to have not always
select preferred language in "Language" GDM option) the following file
should be in users' homedirs:

~/.dmrc

[Desktop]
Session=gnome
Language=en_US.UTF-8

Where in Language you should set language for each user.

Thursday, June 7, 2007

Massive doc/xls to PDF conversion with OpenOffice

Today we've got another problem. Someone from the head needs to make a
good PDFs from a bunch of MS .doc and .xls files. Company's business is
built around MS and MS-like products, and all internal documents are in
MS formats. So, the first obvious for my chief solution was buying
something like Adobe Acrobat/Distiller, but that was a bad way to spend
company's money.

Here goes I, in shiny blue suit with purple coak and letter 'S' on my
chest. It was like:
I: - Hey, boss, you look upset, what's up?
B: - I need to convert a heaps of those docs and spreadsheets to PDF,
and I dunno how to do it without spending a lot uf bucks.
I: - No problem! Try OpenOffice 2, it got a pretty nice 'save to PDF'
feature.
While IT-chief was installing and probing OOo2, I searched for the
possibility of batch conversion, and here what I've found:

1. open www.google.com
2. type "openoffice batch command line"
3. push "I'm feeling lucky"
4. follow the instructions

By doing this, you find yourself at
http://www.xml.com/pub/a/2006/01/11/from-microsoft-to-openoffice.html
which contain a pretty good example of using macroses in OpenOffice to
convert documents from one supported format to another. Create
conversion macros, save it, call OpenOffice binary from console with the
proper command line parameters telling which macros should be used
against which file -- and you get a nice PDF from your .doc or .xls!

Combined with Windows cmd's "for" call the above done the thing.

Some caveats about the code posted at the link below: using it to
convert .xls to PDF could (or could not) throw an error - that's because
a "writer_pdf_Export" filter is used. Change it to "calc_pdf_Export" for
.xls files and all should goes fine.

-- Update:

Here's the code:

Macros code

' Based on code from http://www.oooforum.org/forum/viewtopic.phtml?t=3772

' Save document as an Acrobat PDF file.
Sub SaveAsPDF( cFile )
cURL = ConvertToURL( cFile )
' Open the document. Just blindly assume that the document
' is of a type that OOo will correctly recognize and open
' without specifying an import filter.
' MsgBox(cFile)
' MsgBox(cURL)
oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, _
Array(MakePropertyValue( "Hidden", True ) _
,MakePropertyValue( "ReadOnly", True )))

cFile = Left( cFile, Len( cFile ) - 4 ) + ".pdf"
cURL = ConvertToURL( cFile )

Select Case LCase(Right(cFile,3))
Case "xls" ' Excel file.
oDoc.storeToURL( cURL, Array(_
MakePropertyValue( "FilterName", "calc_pdf_Export" ) _
,MakePropertyValue( "CompressMode", "0")))
Case Else
oDoc.storeToURL( cURL, Array(_
MakePropertyValue( "FilterName", "writer_pdf_Export" ) _
,MakePropertyValue( "CompressMode", "0")))
End Select

oDoc.close( True )
End Sub

' ------ unneeded save options skipped -------

Function MakePropertyValue( Optional cName As String, Optional uValue ) _
As com.sun.star.beans.PropertyValue
Dim oPropertyValue As New com.sun.star.beans.PropertyValue
If Not IsMissing( cName ) Then
oPropertyValue.Name = cName
EndIf
If Not IsMissing( uValue ) Then
oPropertyValue.Value = uValue
EndIf
MakePropertyValue() = oPropertyValue
End Function

Bat-file code

@echo off
for /r . %%f in (*.doc *.xls) do call :convert "%%f"
exit /b
:convert
echo converting %1
set ooobinary="C:\Program Files\OpenOffice.org 2.2\program\soffice.exe"
if exist "%temp%\convertme.pdf" del /q "%temp%\convertme.pdf"
copy /y %1 "%temp%\convertme%~x1">nul || echo Error copying %1 to %temp%! && pause && exit /b 1
%ooobinary% -invisible macro:///Standard.MyConversions.SaveAsPDF("%temp%\convertme%~x1")
if exist "%temp%\convertme.pdf" copy /y "%temp%\convertme.pdf" "%~p1\%~n1.pdf">nul && del /q "%temp%\convertme.pdf" "%temp%\convertme%~x1"

Codepage fun

Imagine a big organization, with a complex IT-infrastructure, great
financial flows, etc. That's where I am work.

Yesterday's we've got an update of one-of-many software products for
one of those obligatory reportings. After applying this (required)
update a problem occurs: files created by this software had incorrect
encoding! Users were panicking, tech.support was trying to explain an
'average user' how to change file encoding (from windows oem to ansi or
backwards). That was not so fun.

Some ancient programmers were almost ready to write a one-button
solution in delphi, until I offered them to just use a suitable tool --
and demonstrated win32 port of GNU iconv utility. Three-liner-bat-file
frontend for iconv saves a lot of man-hours. :-)

Finally, I was really surprised, that noone knew about such tool. Seems
like I'm the only who have that unix-based experience (where tools are
small and effecient).