<commit_before>#!/usr/bin/python
#
# This script creates a Mac OS X NorduGrid ARC client package.
# The following environment variables can be used to control the outcome:
# ARC_BUILD_CHANNEL (nightlies, releases, testing, experimental, svn)
# ARC_BUILD_VERSION (e.g. 1970-01-01, 1.0.0...)
# ARC_BUILD_RELEASEVERSION (ARC_BUILD_VERSION)
# ARC_BUILD_MAKECHECK (no, yes)
# ARC_BUILD_INTERACTIVE (no, yes)
# ARC_BUILD_LFC (no, yes)
# ARC_BUILD_CLEANONSUCCESS (yes, no)
#
# TODO:
# - Support building different architectures, currently only x86_64 is
#   supported.
#   ARC_BUILD_ARCHITECTURE (x86_64, i386)


import os, sys, stat
from os.path import join as pj
import tempfile
import shutil
import datetime, time
import subprocess
import urllib
import re
import tarfile
import glob
import gzip


def otool(patterns):
    '''Returns a dictionary with key vs value pairs as files vs list of linked
    libraries.'''
    files = []
    for pattern in patterns:
        files += glob.glob(pattern)
    proc_otool = subprocess.Popen(["otool", "-L"] + files, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
    stdout, stderr = proc_otool.communicate()

    paths_links = {}
    current_file = ''
    for line in stdout.splitlines():
        if re.search('is not an object file', line):
            continue
        if line[-1] == ":":
            current_file = line[:-1]
            paths_links[current_file] = []
            continue
        paths_links[current_file].append(line.split()[0])
    return paths_links

def changeinstallnames(pattern, paths):
    linked_libraries = otool([pattern])
    for exec_lib in linked_libraries:
        chginstname_arg = []
        for lib in linked_libraries[exec_lib]:
            for frompath in paths:
                if lib[:len(frompath)] == frompath:
                    chginstname_arg += ["-change", lib, pj(paths[frompath], os.path.basename(lib))]
        chginstname = subprocess.Popen(["install_name_tool", "-id", "@loader_path/"+os.path.basename(exec_lib)] + chginstname_arg + [exec_lib], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
        chginstname.wait()
    return True

def hdiutil(args):
    proc_hdiutil = subprocess.Popen(["hdiutil"] + args, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
    stdout, stderr = proc_hdiutil.communicate()
    return { "success" : proc_hdiutil.returncode == 0, "stdout" : stdout, "stderr" : stderr}



class ARCPackageTool:
    ## DEFAULT VALUES.
    name = "nordugrid-arc"

    # Currently only used for naming
    architecture = "x86_64"

    # Where to store ARC globus modules/libraries in order to separate globus dependency. Relative to nordugrid working directory.
    arcglobusdir = "globus/lib"

    # The following packages must be installed before building ARC.
    # Order matters!
    deppackages =  ['pkgconfig', 'libiconv', 'gettext', 'libsigcxx2',
                    'glib2', 'glibmm', 'libtool', 'grid-packaging-tools']

    # The following globus packages are needed by the ARC globus modules.
    # Order matters!
    deppackages += [ 'globus-'+x for x in
                      ['core', 'libtool', 'common', 'callout', 'openssl',
                       'gsi-openssl-error', 'gsi-proxy-ssl', 'openssl-module',
                       'gsi-cert-utils', 'gsi-sysconfig', 'gsi-callback',
                       'gsi-credential', 'gsi-proxy-core', 'gssapi-gsi',
                       'gss-assist', 'gssapi-error', 'xio', 'xio-gsi-driver',
                       'io', 'xio-popen-driver', 'ftp-control', 'ftp-client',
                       'rls-client']
                    ]

    def mypj(self, path1, path2 = '', path3 = '', path4 = ''):
        if path1[:len(self.workdir)] == self.workdir:<commit_msg>Changing build order: pkgconfig now depends on glib2.<commit_after>#!/usr/bin/python
#
# This script creates a Mac OS X NorduGrid ARC client package.
# The following environment variables can be used to control the outcome:
# ARC_BUILD_CHANNEL (nightlies, releases, testing, experimental, svn)
# ARC_BUILD_VERSION (e.g. 1970-01-01, 1.0.0...)
# ARC_BUILD_RELEASEVERSION (ARC_BUILD_VERSION)
# ARC_BUILD_MAKECHECK (no, yes)
# ARC_BUILD_INTERACTIVE (no, yes)
# ARC_BUILD_LFC (no, yes)
# ARC_BUILD_CLEANONSUCCESS (yes, no)
#
# TODO:
# - Support building different architectures, currently only x86_64 is
#   supported.
#   ARC_BUILD_ARCHITECTURE (x86_64, i386)


import os, sys, stat
from os.path import join as pj
import tempfile
import shutil
import datetime, time
import subprocess
import urllib
import re
import tarfile
import glob
import gzip


def otool(patterns):
    '''Returns a dictionary with key vs value pairs as files vs list of linked
    libraries.'''
    files = []
    for pattern in patterns:
        files += glob.glob(pattern)
    proc_otool = subprocess.Popen(["otool", "-L"] + files, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
    stdout, stderr = proc_otool.communicate()

    paths_links = {}
    current_file = ''
    for line in stdout.splitlines():
        if re.search('is not an object file', line):
            continue
        if line[-1] == ":":
            current_file = line[:-1]
            paths_links[current_file] = []
            continue
        paths_links[current_file].append(line.split()[0])
    return paths_links

def changeinstallnames(pattern, paths):
    linked_libraries = otool([pattern])
    for exec_lib in linked_libraries:
        chginstname_arg = []
        for lib in linked_libraries[exec_lib]:
            for frompath in paths:
                if lib[:len(frompath)] == frompath:
                    chginstname_arg += ["-change", lib, pj(paths[frompath], os.path.basename(lib))]
        chginstname = subprocess.Popen(["install_name_tool", "-id", "@loader_path/"+os.path.basename(exec_lib)] + chginstname_arg + [exec_lib], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
        chginstname.wait()
    return True

def hdiutil(args):
    proc_hdiutil = subprocess.Popen(["hdiutil"] + args, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
    stdout, stderr = proc_hdiutil.communicate()
    return { "success" : proc_hdiutil.returncode == 0, "stdout" : stdout, "stderr" : stderr}



class ARCPackageTool:
    ## DEFAULT VALUES.
    name = "nordugrid-arc"

    # Currently only used for naming
    architecture = "x86_64"

    # Where to store ARC globus modules/libraries in order to separate globus dependency. Relative to nordugrid working directory.
    arcglobusdir = "globus/lib"

    # The following packages must be installed before building ARC.
    # Order matters!
    deppackages =  ['libiconv', 'gettext', 'glib2', 'pkgconfig', 'libsigcxx2',
                    'glibmm', 'libtool', 'grid-packaging-tools']

    # The following globus packages are needed by the ARC globus modules.
    # Order matters!
    deppackages += [ 'globus-'+x for x in
                      ['core', 'libtool', 'common', 'callout', 'openssl',
                       'gsi-openssl-error', 'gsi-proxy-ssl', 'openssl-module',
                       'gsi-cert-utils', 'gsi-sysconfig', 'gsi-callback',
                       'gsi-credential', 'gsi-proxy-core', 'gssapi-gsi',
                       'gss-assist', 'gssapi-error', 'xio', 'xio-gsi-driver',
                       'io', 'xio-popen-driver', 'ftp-control', 'ftp-client',
                       'rls-client']
                    ]

    def mypj(self, path1, path2 = '', path3 = '', path4 = ''):
        if path1[:len(self.workdir)] == self.workdir:
{'fraction_non_alphanumeric': 0.12206196581196581, 'fraction_numerical': 0.010016025641025642, 'mean_word_length': 2.8623001547189273, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '461064', 'n_tokens_mistral': 2472, 'n_tokens_neox': 2376, 'n_words': 622}