[csw-devel] [PATCH] Add support for reading password from a file by default

Maciej Bliziński maciej at opencsw.org
Fri Apr 22 08:03:34 CEST 2011


2011/4/22 Ben Walton <bwalton at opencsw.org>:
> +  try:
> +    af = open(authfile, 'r')
> +    password = af.readline().rstrip()

Try using the 'with' syntax:

try:
  with open(authfile, 'r') as af:
    password = af...

To get the password, you can:

password = af.read() # reads the whole file

and with stripping:

password = af.read().strip()

(strips ws from both sides)

> +  except:

Add an exception class, I suppose it'll be an IOError; let other
exceptions propagate.  Add a warning that the file couldn't be found
(logging.warning(...)).

> +    password = getpass.getpass("{0}'s pkg release password> ".format(username))
> +
>   uploader = Srv4Uploader(args,
>                           options.rest_url,
>                           os_release=os_release,


More information about the devel mailing list