4.2. foundations.common

common.py

Platform:
Windows, Linux, Mac Os X.
Description:
Defines Foundations package common utilities objects that don’t fall in any specific category.
Others:
isBinaryFile() from Jorge Orpinel: http://stackoverflow.com/questions/898669/how-can-i-detect-if-a-file-is-binary-non-text-in-python dependencyResolver() from Louis Riviere: http://code.activestate.com/recipes/576570-dependency-resolver/

4.2.1. Module Attributes

foundations.common.LOGGER
foundations.common.CONNECTION_IPS
foundations.common.DEFAULT_HOST_IP

4.2.2. Functions

foundations.common.uniqify(sequence)[source]

Uniqifies the given sequence even if unhashable.

Parameters:sequence (object) – Sequence.
Returns:Uniqified sequence.
Return type:list
Note:The sequence order is not maintained by this definition.
foundations.common.orderedUniqify(sequence)[source]

Uniqifies the given hashable sequence while preserving its order.

Parameters:sequence (object) – Sequence.
Returns:Uniqified sequence.
Return type:list
foundations.common.unpackDefault(iterable, length=3, default=None)[source]

Unpacks given iterable maintaining given length and filling missing entries with given default.

Parameters:
  • iterable (object) – iterable.
  • length (int) – Iterable length.
  • default (object) – Filling default object.
Returns:

Unpacked iterable.

Return type:

object

foundations.common.pathExists(path)[source]

Returns if given path exists.

Parameters:path (unicode) – Path.
Returns:Path existence.
Return type:bool
foundations.common.filterPath(path)[source]

Filters given path.

Parameters:path (unicode) – Path.
Returns:Filtered path.
Return type:unicode
foundations.common.getFirstItem(iterable, default=None)[source]

Returns the first item of given iterable.

Parameters:
  • iterable (object) – Iterable.
  • default (object) – Default value.
Returns:

First iterable item.

Return type:

object

foundations.common.getLastItem(iterable, default=None)[source]

Returns the last item of given iterable.

Parameters:
  • iterable (object) – Iterable.
  • default (object) – Default value.
Returns:

Last iterable item.

Return type:

object

foundations.common.repeat(object, iterations=1)[source]

Repeats given object iterations times.

Parameters:
  • object (object) – Object to repeat.
  • iterations (int) – Repetitions number.
Returns:

Object return values.

Return type:

list

foundations.common.dependencyResolver(dependencies)[source]

Resolves given dependencies.

Parameters:dependencies (dict) – Dependencies to resolve.
Returns:Resolved dependencies.
Return type:list
foundations.common.isInternetAvailable(ips=[u'173.194.34.36', u'173.194.34.55', u'65.55.206.154', u'173.252.110.27', u'199.16.156.230', u'98.139.183.24', u'77.238.178.122', u'198.252.206.16', u'82.94.164.162', u'65.196.127.226', u'www.google.com', u'www.facebook.com', u'www.twitter.com'], timeout=1.0)[source]

Returns if an internet connection is available.

Parameters:
  • ips (list) – Address ips to check against.
  • timeout (int) – Timeout in seconds.
Returns:

Is internet available.

Return type:

bool

foundations.common.getHostAddress(host=None, defaultAddress=u'127.0.0.1')[source]

Returns the given host address.

Parameters:
  • host (unicode) – Host to retrieve the address.
  • defaultAddress (unicode) – Default address if the host is unreachable.
Returns:

Host address.

Return type:

unicode