Revision 3727671e

b/lib/utils.py
1338 1338
  return cpu_list
1339 1339

  
1340 1340

  
1341
def AddAuthorizedKey(file_name, key):
1341
def AddAuthorizedKey(file_obj, key):
1342 1342
  """Adds an SSH public key to an authorized_keys file.
1343 1343

  
1344
  @type file_name: str
1345
  @param file_name: path to authorized_keys file
1344
  @type file_obj: str or file handle
1345
  @param file_obj: path to authorized_keys file
1346 1346
  @type key: str
1347 1347
  @param key: string containing key
1348 1348

  
1349 1349
  """
1350 1350
  key_fields = key.split()
1351 1351

  
1352
  f = open(file_name, 'a+')
1352
  if isinstance(file_obj, basestring):
1353
    f = open(file_obj, 'a+')
1354
  else:
1355
    f = file_obj
1356

  
1353 1357
  try:
1354 1358
    nl = True
1355 1359
    for line in f:

Also available in: Unified diff