Revision b774bb10 lib/utils.py

b/lib/utils.py
1383 1383
      raise errors.GenericError("%s is not a directory" % dir_name)
1384 1384

  
1385 1385

  
1386
def ReadFile(file_name, size=-1):
1386
def ReadFile(file_name, size=-1, oneline=False):
1387 1387
  """Reads a file.
1388 1388

  
1389 1389
  @type size: int
1390 1390
  @param size: Read at most size bytes (if negative, entire file)
1391
  @type oneline: bool
1392
  @param oneline: Whether to read only one line (newline char is not included)
1391 1393
  @rtype: str
1392 1394
  @return: the (possibly partial) content of the file
1393 1395

  
1394 1396
  """
1395 1397
  f = open(file_name, "r")
1396 1398
  try:
1397
    return f.read(size)
1399
    if oneline:
1400
      data = f.readline(size).rstrip("\r\n")
1401
    else:
1402
      data = f.read(size)
1398 1403
  finally:
1399 1404
    f.close()
1400 1405

  
1406
  return data
1407

  
1401 1408

  
1402 1409
def WriteFile(file_name, fn=None, data=None,
1403 1410
              mode=None, uid=-1, gid=-1,

Also available in: Unified diff