Thursday, March 3, 2016

Open CSV and TSV Files Correctly and Automatically in *Nix

Opening csv and tsv files automatically in *nix is a pain in the butt as libreoffice (openoffice) prompts the users every time a file is opened and does not automatically set the correct settings. This document is a way to streamline this process so opening them on *nix is very easy as it can be in windows.

In my experience in programming, it is a good idea to stick with strict standards surrounding what a csv file and a tsv file. No abiguity as there exists in RFC4180. It is my view is that csv file is comma separated and has .csv extension. A tsv file is tab separated flat file and has a .tsv extension.

Also tsv or csv files have any special characters escaped using pairs of double quotes. A good reference for such a more strict standard is CSV-1203 which is a valiant effort at creating a real world standard for csv. Updates are pending in CSV-1203 to add tsv to the definitions as per some discussions I have had with the author.

In order to have csv and tsv files open elegantly in *nix, we need to utilize the freedesktop.org Desktop Entry and xdg-mime to create proper association.

For automatically opening a csv file in libreoffice create a file called ~/.local/share/applications/CSV-1203_CSV_open.desktop with the following contents:

#!/usr/bin/env xdg-open

# Instructions on how to deploy
# Get Mime for csv
# $ touch /tmp/dummy.csv
# $ MIME_TYPE=`xdg-mime query filetype /tmp/dummy.csv` && echo $MIME_TYPE
# This returns the mime registered for csv.
# If mime is not returned yet, It will need to get created.
# . This is not covered in these instructions.
# Create Association:
# $ xdg-mime default CSV-1203_CSV_open.desktop $MIME_TYPE
# Verify that mime is properly associated:
# $ xdg-mime query default $MIME_TYPE
# This will should return CSV-1203_CSV_open.desktop

[Desktop Entry]
Encoding=UTF-8
Name=CSV-1203_CSV
Exec=sh -c "libreoffice --calc --infilter=CSV:44,34,UTF8 %f"
#Exec=sh -c "$HOME/.local/share/applications/CSV-1203_CSV_open.sh %f"
Type=Application
Terminal=false
NoDisplay=true



For automatically opening a tsv file in libreoffice create a file called ~/.local/share/applications/CSV-1203_CSV_open.desktop with the following contents:

#!/usr/bin/env xdg-open

# Instructions on how to deploy
# Get Mime for tsv
# $ touch /tmp/dummy.tsv
# $ MIME_TYPE=`xdg-mime query filetype /tmp/dummy.tsv` && echo $MIME_TYPE
# This returns the mime registered for tsv.
# If mime is not returned yet, It will need to get created. 
# . This is not covered in these instructions.
# Create Association:
# $ xdg-mime default CSV-1203_TSV_open.desktop $MIME_TYPE
# Verify that mime is properly associated:
# $ xdg-mime query default $MIME_TYPE
# This will should return CSV-1203_TSV_open.desktop

[Desktop Entry]
Encoding=UTF-8
Name=CSV-1203_TSV
Exec=sh -c "libreoffice --calc --infilter=CSV:9,34,UTF8 %f"
Type=Application
Terminal=false
NoDisplay=true
Name[en_US]=CSV-1203_TSV_open


Notes:

  • These desktop files do not need to be set as executable as they are not menu items.
  • Open office should work for the above. If using openoffice just substitute the executable name above.


By following the instructions in these desktop files, you will have an association to .tsv and .csv files that will automatically launch and open libreoffice.

Good luck!

Tuesday, February 10, 2015

Installing Ecco Pro 4.01 in Linux using Wine

Installing Ecco Pro 4.01 in Linux using Wine

Background

Ecco Pro is a fantastic tool written by for the windows 95 platform in the mid 90's. This tool contains a single pane outliner which I personally feel is the best one available on the windows platform and aside from OSX, I have yet to find one in *nix platforms that comes close.

This document explains how to install Ecco Pro 4.01 on Linux and has instructions to get desktop integration working fluidly as well.

Wine version

The last released version of wine that worked with Ecco pro was 1.7.43. A ticket (40201) was raised with the wine team and a patch has been developed. This patch is confirmed to work with a source build of 1.9.5. I will update this doc once, the patch has been integrated into a stable release.

[Update 2016-03-17] - Patch has been merged into the wine trunk to fix this bug. Fix should show up in next releases.
[Update 2016-03-18] - According to bug fix, Wine 1.9.6+ will now be able to run Ecco Pro

Download Ecco Pro 4.01 32 bit Standalone files

Download both files from this mega folder:
  • stand_alone_ecco_pro_4.01.zip
    • All ecco pro files to be installed
  • stand_alone_ecco_pro_4.01.zip.md5
    • Text document containing the md4sum of the zip file (e3237d025e8d140a87c2e7acdc425731)
    • I will post a link to the ecco_pro forum making note of this blog post and will put the checksum there as well for safe keeping
    • Please verify this checksum as its best practice to do so. 
    • The checksum was generated using md5sum on ubuntu linux. Cygwin on windows should have a similar checksum program.
  • eccopro.sh
    • Shell script for launching program
    • Also prevents launching multiple instances
  • eccopro.desktop
    • desktop launcher
  • eccopro_icon.png
    • Icon for launcher

FYI Only:

The files in this standalone package from mega are based on the free files available from the ecco_pro Yahoo Group and should not be infringing on any copyrights.

You can download the same files if you wish by first registering and then, going to ecco_pro -> Files -> **Ecco Pro v. 4.01** -> Download the files: 
  • Ecco Pro from Netmanage site - Setup32.sfx.part2.rar
  • Ecco Pro from Netmanage site - Setup32.sfx.part1.exe
To finish verification, you will need a 32 bit windows system to install these files which can be a pain for some, which is why I created the standalone files.

The standalone files include ecco-extension version 4.6.7.7.  For this or later versions of ecco-extension, go to http://eccopro.com/ecco-extension/.

This standalone package should also work perfectly on a windows system, just ignore all the wine steps.

Installing Wine

First you must have a modern linux operating system. My reference system is OpenSuse 13.2 which has Wine 1.7.x. To install wine using *Suse do the following:

# su -c 'zypper install wine wine-32bit' 

This will install wine 64bit and wine 32bit. Wine 32bit is required to run Ecco Pro.

For Ubuntu, good instructions are from the Official Ubuntu wine PPA:

  • Notes:
    • I had success installing with the default package 'wine' which resolved to wine-1.6.2
    • Later versions were tested (1.7, 1.8) and they did not work!
  • Instructions:
  • Add the PPA:
    • # sudo add-apt-repository ppa:ubuntu-wine/ppa -y && sudo apt-get update
  • Find versions:
    • # sudo apt-cache search wine
  • Choose appropriate versions to install. On more recent Ubuntu wine versions, 32 bit should automatically get installed with the main installer. Older version may need to install i386 package manually Eg:
    • # sudo apt-get install wine1.8
  • Install gnome keyring:
    • # sudo apt-get install libp11-kit-gnome-keyring:i386

Prepare Terminal for Wine

# export WINEARCH=win32; export WINEPREFIX=$HOME/.wine32_eccopro

Notes:
  • Its best to use the (.) prefix notation. I will use $HOME/.wine32_eccopro for this example
  • Be sure to run this whenever you open a new terminal to operate on your wine instance
  • all subsequent instructions below will assume that WINEARCH and WINEPREFIX have been defined with the command above. Failing to do so will yield unexpected results.

Create a wine 32 bit wineprefix 

# winecfg 

This command will create the 32 bit wine instance in $WINEPREFIX and will launch winecfg GUI for this wine instance. 

When Wine Configuration loads, choose Applications -> Windows Version -> Windows XP (should be already defaulted)-> OK.

Deploy the standalone files:

% mkdir -p $WINEPREFIX/drive_c/apps/eccopro

Manually copy over files from downloaded zip as follows:
  • Put all files from c_apps_eccopro to $WINEPREFIX/drive_c/apps/eccopro
  • Put all files from c_windows_system to $WINEPREFIX/drive_c/windows/system
Desktop Launcher files:
  • Put ecco_pro_icon.png into ~/.icons
  • Put eccopro.sh and eccopro.desktop into ~/.local/share/applications
    • Make both files executable

Install mfc42.dll:

% winetricks mfc42

Running Ecco Pro

Using desktop Launcher (preferred)

EccoPro launcher (put into ~/local/share/applications folder), should now be launchable using the Ubuntu search window. This desktop launched by double clicking. It can also be dragged over to the Ubuntu launcher.

Ecco Extension manually

# export WINEARCH=win32; export WINEPREFIX=$HOME/.wine32_eccopro
# cd $WINEPREFIX/drive_c/apps/eccopro/
# wine eccoext.exe

Ecco32.exe manually (alternative)

# export WINEARCH=win32; export WINEPREFIX=$HOME/.wine32_eccopro
# cd $WINEPREFIX/drive_c/apps/eccopro/
# wine ecco32.exe


Conclusion

Now you have a running version of Ecco Pro 32 4.01 running on your *nix machine.

Update 2016-2-04
As I could no longer get eccopro to install using the source installers in wine, I decided to fall back to the standalone tried and tested method. Its not ideal but it works.