Beispiel #1
0
    def info( cls, path ):
        if not path:
            raise cls.Error("No working copy path specified for calling svnversion with.")

        url        = None
        repository = None
        branch     = None
        remote     = None
        revision   = None

        try:
            command = "{svn} info {path}".format( svn=cls.binary(), path=path )
            svn_info = as_str( subprocess.check_output( shlex.split( command ), stderr=subprocess.STDOUT ) )
            url        = re.search( r'URL: ([^\s]+)', svn_info ).expand(r'\1')
            repository = re.search( r'Repository Root: ([^\s]+)', svn_info ).expand(r'\1')
            branch     = re.search( r'Relative URL: \^/([^\s]+)', svn_info ).expand(r'\1')
            revision   = re.search( r'Revision: (\d+)', svn_info ).expand(r'\1')
        except subprocess.CalledProcessError:
            raise cls.Error("Not a Subversion working copy")
        except OSError:
            raise cls.Error("Subversion binary [{svn}] is not available".format(
                    svn=as_warning( cls.binary() )
            ) )

        try:
            command = "svnversion -n {path}".format( path=path )
            revision = as_str( subprocess.check_output( shlex.split( command ), stderr=subprocess.STDOUT ) )
        except subprocess.CalledProcessError:
            pass
        except OSError:
            logger.warn( "The {svnversion} binary is not available. Consider installing it.".format( svnversion=as_warning("svnversion") ) )

        return url, repository, branch, remote, revision
Beispiel #2
0
    def info(cls, path):
        if not path:
            raise cls.Error(
                "No working copy path specified for calling bzr commands with."
            )

        url = None
        repository = None
        branch = None
        remote = None
        revision = None

        if not os.path.exists(os.path.join(path, ".bzr")):
            raise cls.Error("Not a Bazaar working copy")

        try:
            command = "{bzr} nick".format(bzr=cls.binary())
            branch = as_str(
                subprocess.check_output(shlex.split(command),
                                        stderr=subprocess.STDOUT,
                                        cwd=path).strip())

            command = "{bzr} revno".format(bzr=cls.binary())
            revision = as_str(
                subprocess.check_output(shlex.split(command),
                                        stderr=subprocess.STDOUT,
                                        cwd=path).strip())

            command = "{bzr} info".format(bzr=cls.binary())
            bzr_info = as_str(
                subprocess.check_output(shlex.split(command),
                                        stderr=subprocess.STDOUT,
                                        cwd=path).strip())
            repository_match = re.search(
                r'shared repository: (?P<repository>.*)\n', bzr_info)
            if repository_match:
                repository = repository_match.group('repository')

            url_match = re.search(r'checkout of branch: (?P<url>.*)\n',
                                  bzr_info)
            if url_match:
                url = url_match.group('url')

        except subprocess.CalledProcessError:
            raise cls.Error("Not a Bazaar working copy")

        except OSError:
            raise cls.Error("Bazaar binary [{bzr}] is not available".format(
                bzr=cls.binary()))

        return url, repository, branch, remote, revision
Beispiel #3
0
    def info(cls, path):
        if not path:
            raise cls.Error(
                "No working copy path specified for calling hg commands with.")

        url = None
        repository = None
        branch = None
        remote = None
        revision = None

        if not os.path.exists(os.path.join(path, ".hg")):
            raise cls.Error("Not a Mercurial working copy")

        try:
            command = "{hg} summary".format(hg=cls.binary())
            summary = as_str(
                subprocess.check_output(shlex.split(command),
                                        stderr=subprocess.STDOUT,
                                        cwd=path).strip()).split('\n')

            revision = ""
            branch = ""
            for line in summary:
                if not revision and line.startswith('parent: '):
                    revision = line.replace('parent: ', '')
                    if branch:
                        break
                elif not branch and line.startswith('branch: '):
                    branch = line.replace('branch: ', '')
                    if revision:
                        break

            command = "{hg} path".format(hg=cls.binary())
            repository = as_str(
                subprocess.check_output(shlex.split(command),
                                        stderr=subprocess.STDOUT,
                                        cwd=path).strip()).split('=')[1]
            url = repository

        except subprocess.CalledProcessError:
            raise cls.Error("Not a Mercurial working copy")

        except OSError:
            raise cls.Error("Mercurial binary [{hg}] is not available".format(
                hg=cls.binary()))

        return url, repository, branch, remote, revision
Beispiel #4
0
    def get_branch(cls, path):
        branch = None
        remote = None

        # In case we have a detached head we use this
        result = as_str(
            cls.execute_command(
                "{git} show -s --pretty=\%d HEAD".format(git=cls.binary()),
                path))
        match = re.search(r'[(]HEAD[^,]*[,] (?P<branches>[^)]+)[)]', result)
        if match:
            branches = [b.strip() for b in match.group("branches").split(',')]
            logger.trace("Branches (using show) for [{}] are [{}]".format(
                as_notice(path), colour_items(branches)))
            if len(branches) == 1:
                # If this returns a tag: tag_name replace the ": " with "/" and then extract the tag_name
                # otherwise this will simply extract the branch_name as expected
                if not branches[0].startswith('tag:'):
                    remote = branches[0]
                branch = branches[0].replace(': ', '/').split('/')[1]
            else:
                remote = branches[-2]
                branch = remote.split('/')[1]
            logger.trace("Branch (using show) for [{}] is [{}]".format(
                as_notice(path), as_info(branch)))
        else:
            logger.warn("No branch found from [{}]".format(result))

        return branch, remote
Beispiel #5
0
 def version_from_command(cls, cxx):
     command = "{} --version".format(cxx)
     if command_available(command):
         reported_version = None
         version_string = as_str(
             Popen(shlex.split(command), stdout=PIPE).communicate()[0])
         matches = re.search(r'based on LLVM (?P<major>\d+)\.(?P<minor>\d)',
                             version_string)
         if not matches:
             matches = re.search(
                 r'Apple LLVM version (?P<major>\d+)\.(?P<minor>\d)',
                 version_string)
             if not matches:
                 matches = re.search(
                     r'clang version (?P<major>\d+)\.(?P<minor>\d)',
                     version_string)
         if matches:
             major = matches.group('major')
             minor = matches.group('minor')
             reported_version = {}
             reported_version['toolchain'] = 'clang'
             reported_version['name'] = 'clang' + major + minor
             reported_version['major'] = int(major)
             reported_version['minor'] = int(minor)
             reported_version['version'] = major + "." + minor
             reported_version['short_version'] = major + minor
         return reported_version
     return None
Beispiel #6
0
 def version_from_command(cls, cxx, prefix):
     command = "{} --version".format(cxx)
     if command_available(command):
         reported_version = as_str(
             Popen(shlex.split(command), stdout=PIPE).communicate()[0])
         reported_version = prefix + re.search(
             r'(\d)\.(\d)', reported_version).expand(r'\1\2')
         return reported_version
     return None
Beispiel #7
0
 def __call__(self):
     for line in iter(self.call_readline, self._empty_str):
         line = as_str(line)
         if line:
             if self.processor:
                 line = self.processor(line)
                 if line:
                     sys.stdout.write(line)
             else:
                 sys.stdout.write(line)
Beispiel #8
0
 def llvm_version_from(cls, llvm_tool):
     command = "{} --version".format(llvm_tool)
     if command_available(command):
         reported_version = as_str(
             Popen(shlex.split(command), stdout=PIPE).communicate()[0])
         version = re.search(r'LLVM version (\d)\.(\d)\.(\d)',
                             reported_version)
         reported_version = version.expand(r'\1')
         return reported_version
     return None
Beispiel #9
0
 def _get_qt5_version(self):
     command = "pkg-config --modversion Qt5Core"
     try:
         return as_str(
             subprocess.check_output(shlex.split(command),
                                     stderr=subprocess.STDOUT).strip())
     except:
         logger.debug(
             "In _get_qt5_version() failed to execute [{}]".format(command))
         return None
Beispiel #10
0
 def __call__(self):
     for line in iter(self.call_readline, ""):
         line = as_str(line.rstrip())
         if line:
             if self.processor:
                 line = self.processor(line)
                 if line:
                     print(line)
             else:
                 print(line)
Beispiel #11
0
    def info(cls, path):
        if not path:
            raise cls.Error(
                "No working copy path specified for calling git commands with."
            )

        url = None
        repository = None
        branch = None
        remote = None
        revision = None

        if not os.path.exists(os.path.join(path, ".git")):
            raise cls.Error("Not a Git working copy")

        command = None
        try:
            command = "{git} describe --always".format(git=cls.binary())
            revision = as_str(
                subprocess.check_output(shlex.split(command),
                                        stderr=subprocess.STDOUT,
                                        cwd=path).strip())

            branch, remote = cls.get_branch(path)

            command = "{git} config --get remote.origin.url".format(
                git=cls.binary())
            repository = as_str(
                subprocess.check_output(shlex.split(command),
                                        stderr=subprocess.STDOUT,
                                        cwd=path).strip())
            url = repository

        except subprocess.CalledProcessError:
            raise cls.Error(
                "Git command [{command}] failed".format(command=str(command)))

        except OSError:
            raise cls.Error(
                "Git binary [{git}] is not available".format(git=cls.binary()))

        return url, repository, branch, remote, revision
Beispiel #12
0
    def get_flags(cls, location):

        flags = {}
        flags['INCPATH'] = [os.path.join(location.local(), "include")]

        pg_config = "pg_config"
        if platform.system() == "Windows":
            pg_config = pg_config + ".exe"
            if not cuppa.output_processor.command_available(pg_config):
                # try to find the Postgresql install
                program_files = os.environ.get("ProgramW6432")
                postgresql_base = os.path.join(program_files, "PostgreSQL")
                if os.path.exists(postgresql_base):
                    paths = glob.glob(postgresql_base + '\\*')
                    if len(paths):
                        paths.sort()
                        latest = paths[-1]
                        pg_config = '\"' + os.path.join(
                            latest, "bin", pg_config) + '\"'

        if cuppa.output_processor.command_available(pg_config):
            command = "{pg_config} --includedir".format(pg_config=pg_config)
            libpq_include = as_str(
                subprocess.check_output(shlex.split(command),
                                        stderr=subprocess.STDOUT).strip())
            flags['INCPATH'].append(libpq_include)

            command = "{pg_config} --libdir".format(pg_config=pg_config)
            libpq_libpath = as_str(
                subprocess.check_output(shlex.split(command),
                                        stderr=subprocess.STDOUT).strip())
            flags['LIBPATH'] = [libpq_libpath]
        else:
            logger.error(
                "postgresql: pg_config not available so cannot determine LIBPATH for postgres libraries"
            )
            raise QuinceException("pg_config not available")

        flags['DYNAMICLIBS'] = ['pq']

        return flags
Beispiel #13
0
    def get_info( cls, location, local_directory, full_url, expected_vc_type = None ):

        vcs_info = cls.detect_vcs_info( local_directory, expected_vc_type )
        if vcs_info:
            return tuple( as_str(t) for t in vcs_info )

        url         = location
        repository  = urlunparse( ( full_url.scheme, full_url.netloc, '',  '',  '',  '' ) )
        branch_path = unquote( full_url.path )
        remote      = None
        revision    = None

        return ( url, repository, branch_path, remote, revision )
Beispiel #14
0
 def __call__( self ):
     try:
         for line in iter( self.call_readline, "" ):
             line = as_str( line.rstrip() )
             if line:
                 if self.processor:
                     line = self.processor( line )
                     if line:
                         print( line )
                 else:
                     print( line )
     except UnicodeDecodeError as error:
         print( "WARNING: Ignoring unicode error {}".format( error ) )
Beispiel #15
0
    def _libc_version( self, machine, system ):

        libc_file = "libc.so.6"
        libc_path = "/lib/" + libc_file

        if not path.exists( libc_path ):
            multiarch_lib_path = '-'.join( [ machine, system.lower(), 'gnu' ] )
            libc_path = "/lib/" + multiarch_lib_path + "/" + libc_file

        try:
            libc_version = Popen([libc_path], stdout=PIPE).communicate()[0]
            return 'libc' + search( r'^GNU C Library [()a-zA-Z ]*([0-9][.0-9]+)', as_str( libc_version ), MULTILINE ).expand(r'\1').replace('.','')
        except:
            logger.warn( "Could not detect the version of libc installed. You might be missing some development libraries!" )
            return None
Beispiel #16
0
 def version_from_command(cls, cxx):
     command = "{} --version".format(cxx)
     if command_available(command):
         reported_version = as_str(
             Popen(shlex.split(command), stdout=PIPE).communicate()[0])
         version = re.search(r'based on LLVM (\d)\.(\d)', reported_version)
         if not version:
             version = re.search(r'Apple LLVM version (\d)\.(\d)',
                                 reported_version)
             if not version:
                 version = re.search(r'clang version (\d)\.(\d+)',
                                     reported_version)
         reported_version = 'clang' + version.expand(r'\1\2')
         return reported_version
     return None
Beispiel #17
0
 def _set_qt5_dir(self, env):
     command = "pkg-config --cflags Qt5Core"
     try:
         cflags = as_str(
             subprocess.check_output(shlex.split(command),
                                     stderr=subprocess.STDOUT).strip())
         if cflags:
             flags = env.ParseFlags(cflags)
             if 'CPPPATH' in flags:
                 shortest_path = flags['CPPPATH'][0]
                 for include in flags['CPPPATH']:
                     if len(include) < len(shortest_path):
                         shortest_path = include
                 env['QT5DIR'] = shortest_path
     except:
         logger.debug(
             "In _set_qt5_dir() failed to execute [{}]".format(command))
Beispiel #18
0
 def execute_command(cls, command, path=None):
     try:
         logger.trace("Executing command [{command}]...".format(
             command=as_info(command)))
         result = as_str(
             subprocess.check_output(shlex.split(command),
                                     stderr=subprocess.STDOUT,
                                     cwd=path)).strip()
         logger.trace("Result of calling [{command}] was [{result}]".format(
             command=as_info(command), result=as_notice(result)))
         return result
     except subprocess.CalledProcessError as error:
         logger.trace(
             "Command [{command}] failed with exit code [{exit_code}]".
             format(command=as_warning(str(command)),
                    exit_code=as_warning(str(error.returncode))))
         raise cls.Error(
             "Command [{command}] failed".format(command=str(command)))
     except OSError:
         logger.trace("Binary [{git}] is not available".format(
             git=as_warning(cls.binary())))
         raise cls.Error(
             "Binary [{git}] is not available".format(git=cls.binary()))
Beispiel #19
0
 def __init__(self):
     secret_regex = re.compile(r'.*TOKEN.*')
     self.secrets = {}
     for key, val in six.iteritems(os.environ):
         if re.match(secret_regex, key):
             self.secrets[as_str(val)] = key