~ubuntu-branches/debian/experimental/nuitka/experimental

« back to all changes in this revision

Viewing changes to nuitka/Utils.py

  • Committer: Package Import Robot
  • Author(s): Kay Hayen
  • Date: 2012-01-10 22:21:56 UTC
  • Revision ID: package-import@ubuntu.com-20120110222156-fuyjhnhomqm6609e
Tags: upstream-0.3.18~pre2+ds
ImportĀ upstreamĀ versionĀ 0.3.18~pre2+ds

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#     Copyright 2012, Kay Hayen, mailto:kayhayen@gmx.de
 
2
#
 
3
#     Part of "Nuitka", an optimizing Python compiler that is compatible and
 
4
#     integrates with CPython, but also works on its own.
 
5
#
 
6
#     If you submit patches or make the software available to licensors of
 
7
#     this software in either form, you automatically them grant them a
 
8
#     license for your part of the code under "Apache License 2.0" unless you
 
9
#     choose to remove this notice.
 
10
#
 
11
#     Kay Hayen uses the right to license his code under only GPL version 3,
 
12
#     to discourage a fork of Nuitka before it is "finished". He will later
 
13
#     make a new "Nuitka" release fully under "Apache License 2.0".
 
14
#
 
15
#     This program is free software: you can redistribute it and/or modify
 
16
#     it under the terms of the GNU General Public License as published by
 
17
#     the Free Software Foundation, version 3 of the License.
 
18
#
 
19
#     This program is distributed in the hope that it will be useful,
 
20
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
#     GNU General Public License for more details.
 
23
#
 
24
#     You should have received a copy of the GNU General Public License
 
25
#     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
26
#
 
27
#     Please leave the whole of this copyright notice intact.
 
28
#
 
29
""" Utility module.
 
30
 
 
31
Here the small things for file/dir names, Python version, CPU counting, etc. that
 
32
fit nowhere else and don't deserve their own names.
 
33
 
 
34
"""
 
35
 
 
36
import sys, os
 
37
 
 
38
def getPythonVersion():
 
39
    big, major, minor = sys.version_info[0:3]
 
40
 
 
41
    return big * 100 + major * 10 + minor
 
42
 
 
43
def relpath( path ):
 
44
    return os.path.relpath( path )
 
45
 
 
46
def abspath( path ):
 
47
    return os.path.abspath( path )
 
48
 
 
49
def joinpath( *parts ):
 
50
    return os.path.join( *parts )
 
51
 
 
52
def basename( path ):
 
53
    return os.path.basename( path )
 
54
 
 
55
def dirname( path ):
 
56
    return os.path.dirname( path )
 
57
 
 
58
def getExtension( path ):
 
59
    return os.path.splitext( path )[1]
 
60
 
 
61
def isFile( path ):
 
62
    return os.path.isfile( path )
 
63
 
 
64
def isDir( path ):
 
65
    return os.path.isdir( path )
 
66
 
 
67
def getCoreCount():
 
68
    cpu_count = 0
 
69
 
 
70
    # Try to sum up the CPU cores, if the kernel shows them, pylint: disable=W0702
 
71
    try:
 
72
        # Try to get the number of logical processors
 
73
        cpu_count = open( "/proc/cpuinfo" ).read().count( "processor\t:" )
 
74
    except:
 
75
        pass
 
76
 
 
77
    if not cpu_count:
 
78
        # false alarm, no re-import, just a function level import to avoid it unless it is
 
79
        # absolutely necessary, pylint: disable=W0404
 
80
 
 
81
        import multiprocessing
 
82
        cpu_count = multiprocessing.cpu_count()
 
83
 
 
84
    return cpu_count