passwd-as-ods.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Copyright (C) 2007 Søren Roug, European Environment Agency
  4. #
  5. # This is free software. You may redistribute it under the terms
  6. # of the Apache license and the GNU General Public License Version
  7. # 2 or at your option any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public
  15. # License along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. #
  18. # Contributor(s):
  19. #
  20. from odf.opendocument import OpenDocumentSpreadsheet
  21. from odf.style import (ParagraphProperties, Style, TableColumnProperties,
  22. TextProperties)
  23. from odf.table import Table, TableCell, TableColumn, TableRow
  24. from odf.text import P
  25. textdoc = OpenDocumentSpreadsheet()
  26. # Create a style for the table content. One we can modify
  27. # later in the word processor.
  28. tablecontents = Style(parent=textdoc.styles,
  29. name='Table Contents', family='paragraph')
  30. ParagraphProperties(parent=tablecontents, numberlines='false', linenumber='0')
  31. TextProperties(parent=tablecontents, fontweight='bold')
  32. # Create automatic styles for the column widths.
  33. # We want two different widths, one in inches, the other one in metric.
  34. # ODF Standard section 15.9.1
  35. widthshort = Style(parent=textdoc.automaticstyles,
  36. name='Wshort', family='table-column')
  37. TableColumnProperties(parent=widthshort, columnwidth='1.7cm')
  38. widthwide = Style(parent=textdoc.automaticstyles,
  39. name='Wwide', family='table-column')
  40. TableColumnProperties(parent=widthwide, columnwidth='1.5in')
  41. # Start the table, and describe the columns
  42. table = Table(parent=textdoc.spreadsheet, name='Password')
  43. TableColumn(parent=table, numbercolumnsrepeated=4, stylename=widthshort)
  44. TableColumn(parent=table, numbercolumnsrepeated=3, stylename=widthwide)
  45. with open('/etc/passwd') as f:
  46. for line in f:
  47. rec = line.strip().split(':')
  48. tr = TableRow(parent=table)
  49. for val in rec:
  50. tc = TableCell(parent=tr)
  51. p = P(parent=tc, stylename=tablecontents, text=val)
  52. textdoc.save('passwd.ods')