File: test.py

package info (click to toggle)
source-highlight 1.11-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,872 kB
  • ctags: 4,699
  • sloc: sh: 3,633; cpp: 2,606; lex: 2,463; ansic: 1,610; makefile: 537; php: 185; perl: 145; yacc: 122; ruby: 63; sed: 53; python: 45; ml: 38; java: 30
file content (28 lines) | stat: -rw-r--r-- 675 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#! /usr/bin/python

import posix
from string import splitfields

def userinfo(filename):
  """
  This function returns the list of users
  and a table containing users and their passwords
  """
  users, table = [], {}
  file = open(filename, 'r')
  for line in file.readlines():
    [name, password] = splitfields(line, ':')[:2]
    users.append(name)
    table[name] = password
  return users, table

def main():
  for filename in ('/etc/passwd', 'etc/passwd.bak'):
    try:
      users, table = userinfo(filename)
      print table.keys()[3:7], table['postgres']
      posix.system('ls -al ' + filename)
    except:
      print 'File "' + filename + '" not found!'

main()