Tuesday, October 23, 2012

Python CSV to XLS conversion script using openpyxl

Q. How to convert CSV file with ( : ) colon delimiter to Excel sheet?

A. Required - Python2.6 version with Openpyxl module


#!/usr/bin/python2.6
import csv
from openpyxl import Workbook
from openpyxl.cell import get_column_letter

f = open('/tmp/csvfile.txt', "rU")

csv.register_dialect('colons', delimiter=':')

reader = csv.reader(f, dialect='colons')

wb = Workbook()
dest_filename = r"/tmp/xls_out.xlsx"

ws = wb.worksheets[0]
ws.title = "A Snazzy Title"

for row_index, row in enumerate(reader):
    for column_index, cell in enumerate(row):
        column_letter = get_column_letter((column_index + 1))
        ws.cell('%s%s'%(column_letter, (row_index + 1))).value = cell

wb.save(filename = dest_filename)

Monday, October 22, 2012

How to mount LVM partitions from rescue mode (Fedora/CentOS/RedHat)

Boot from your rescue media and "skip" filesystem mount.

1. scan for volume groups:

#lvm vgscan -v

2. Activate all volume groups:

#lvm vgchange -a y

3. List logical volume

#lvm lvscan

4. Mount your filesystem and do your work :)