def partitions(n, m=None, k=None, size=False):
 if ((n <= 0) or ((m is not None) and (m < 1)) or ((k is not None) and (k < 1)) or (m and k and ((m * k) < n))):
  if size:
   (yield (0, {}))
  else:
   (yield {})
  return
 if (m is None):
  m = n
 else:
  m = min(m, n)
 if (n == 0):
  if size:
   (yield (1, {0: 1}))
  else:
   (yield {0: 1})
  return
 k = min((k or n), n)
 (n, m, k) = (as_int(n), as_int(m), as_int(k))
 (q, r) = divmod(n, k)
 ms = {k: q}
 keys = [k]
 if r:
  ms[r] = 1
  keys.append(r)
 room = ((m - q) - bool(r))
 if size:
  (yield (sum(ms.values()), ms))
 else:
  (yield ms)
 while (keys != [1]):
  if (keys[(-1)] == 1):
   del keys[(-1)]
   reuse = ms.pop(1)
   room += reuse
  else:
   reuse = 0
  while 1:
   i = keys[(-1)]
   newcount = ms[i] = (ms[i] - 1)
   reuse += i
   if (newcount == 0):
    del keys[(-1)], ms[i]
   room += 1
   i -= 1
   (q, r) = divmod(reuse, i)
   need = (q + bool(r))
   if (need > room):
    if (not keys):
     return
    continue
   ms[i] = q
   keys.append(i)
   if r:
    ms[r] = 1
    keys.append(r)
   break
  room -= need
  if size:
   (yield (sum(ms.values()), ms))
  else:
   (yield ms)

def partitions ( n , m = None , k = None , size = False ) : if ( ( n <= 0 ) or ( ( m is not None ) and ( m < 1 ) ) or ( ( k is not None ) and ( k < 1 ) ) or ( m and k and ( ( m * k ) < n ) ) ) : if size : ( yield ( 0 , { } ) ) else : ( yield { } ) return if ( m is None ) : m = n else : m = min ( m , n ) if ( n == 0 ) : if size : ( yield ( 1 , { 0 : 1 } ) ) else : ( yield { 0 : 1 } ) return k = min ( ( k or n ) , n ) ( n , m , k ) = ( as_int ( n ) , as_int ( m ) , as_int ( k ) ) ( q , r ) = divmod ( n , k ) ms = { k : q } keys = [ k ] if r : ms [ r ] = 1 keys . append ( r ) room = ( ( m - q ) - bool ( r ) ) if size : ( yield ( sum ( ms . values ( ) ) , ms ) ) else : ( yield ms ) while ( keys != [ 1 ] ) : if ( keys [ ( - 1 ) ] == 1 ) : del keys [ ( - 1 ) ] reuse = ms . pop ( 1 ) room += reuse else : reuse = 0 while 1 : i = keys [ ( - 1 ) ] newcount = ms [ i ] = ( ms [ i ] - 1 ) reuse += i if ( newcount == 0 ) : del keys [ ( - 1 ) ] , ms [ i ] room += 1 i -= 1 ( q , r ) = divmod ( reuse , i ) need = ( q + bool ( r ) ) if ( need > room ) : if ( not keys ) : return continue ms [ i ] = q keys . append ( i ) if r : ms [ r ] = 1 keys . append ( r ) break room -= need if size : ( yield ( sum ( ms . values ( ) ) , ms ) ) else : ( yield ms )
get a partition list for all disk or for selected device only example:: from fabtools .