Python os.path.join() Examples

The following are code examples for showing how to use os.path.join(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: Gurux.DLMS.Python   Author: Gurux   File: GXManufacturerCollection.py    GNU General Public License v2.0 6 votes vote down vote up
def isUpdatesAvailable(cls, path):
        if sys.version_info < (3, 0):
            return False
        # pylint: disable=broad-except
        if not os.path.isfile(os.path.join(path, "files.xml")):
            return True
        try:
            available = dict()
            for it in ET.parse(os.path.join(path, "files.xml")).iter():
                if it.tag == "File":
                    available[it.text] = datetime.datetime.strptime(it.attrib["Modified"], "%d-%m-%Y")

            path = NamedTemporaryFile()
            path.close()
            urllib.request.urlretrieve("https://www.gurux.fi/obis/files.xml", path.name)
            for it in ET.parse(path.name).iter():
                if it.tag == "File":
                    tmp = datetime.datetime.strptime(it.attrib["Modified"], "%d-%m-%Y")
                    if not it.text in available or available[it.text] != tmp:
                        return True
        except Exception as e:
            print(e)
            return True
        return False 
Example 2
Project: Gurux.DLMS.Python   Author: Gurux   File: GXManufacturerCollection.py    GNU General Public License v2.0 6 votes vote down vote up
def updateManufactureSettings(cls, directory):
        #
        # Update manufacturer settings from the Gurux www server.
        #
        # directory: Target directory.
        #
        if sys.version_info >= (3, 0):
            return
        if not os.path.isdir(directory):
            os.mkdir(directory)
            if not os.path.isdir(directory):
                return
        path = os.path.join(directory, "files.xml")
        urllib.request.urlretrieve("https://www.gurux.fi/obis/files.xml", path)
        for it in ET.parse(path).iter():
            if it.tag == "File":
                path = os.path.join(directory, it.text)
                urllib.request.urlretrieve("https://www.gurux.fi/obis/" + it.text, path) 
Example 3
Project: Gurux.DLMS.Python   Author: Gurux   File: GXManufacturerCollection.py    GNU General Public License v2.0 6 votes vote down vote up
def readManufacturerSettings(cls, manufacturers, path):
        # pylint: disable=broad-except
        manufacturers = []
        files = [f for f in listdir(path) if isfile(join(path, f))]
        if files:
            for it in files:
                if it.endswith(".obx"):
                    try:
                        manufacturers.append(cls.__parse(os.path.join(path, it)))
                    except Exception as e:
                        print(e)
                        continue

    #
    # Serialize manufacturer from the xml.
    #
    # @param in
    #            Input stream.
    # Serialized manufacturer.
    # 
Example 4
Project: godot-mono-builds   Author: godotengine   File: cmd_utils.py    MIT License 6 votes vote down vote up
def add_base_arguments(parser, default_help):
    import os
    from os.path import join as path_join

    home = os.environ.get('HOME')
    mono_sources_default = os.environ.get('MONO_SOURCE_ROOT', '')

    parser.add_argument('--verbose-make', action='store_true', default=False, help=default_help)
    parser.add_argument('--configure-dir', default=path_join(home, 'mono-configs'), help=default_help)
    parser.add_argument('--install-dir', default=path_join(home, 'mono-installs'), help=default_help)

    if mono_sources_default:
        parser.add_argument('--mono-sources', default=mono_sources_default, help=default_help)
    else:
        parser.add_argument('--mono-sources', required=True)

    parser.add_argument('--mxe-prefix', default='/usr', help=default_help) 
Example 5
Project: godot-mono-builds   Author: godotengine   File: llvm.py    MIT License 6 votes vote down vote up
def clean(opts: BaseOpts, target: str):
    build_dir = path_join(opts.configure_dir, 'llvm-%s' % target)
    install_dir = path_join(opts.install_dir, 'llvm-%s' % target)
    stamp_file = path_join(opts.configure_dir, '.stamp-%s-make' % target)

    rm_rf(stamp_file)

    make_args = [
	    '-C', '%s/llvm' % opts.mono_source_root,
        '-f', 'build.mk', 'clean-llvm',
		'LLVM_BUILD=%s' % build_dir,
		'LLVM_PREFIX=%s' % install_dir
    ]

    make_args += ['V=1'] if opts.verbose_make else []

    run_command('make', args=make_args, name='make clean') 
Example 6
Project: godot-mono-builds   Author: godotengine   File: android.py    MIT License 6 votes vote down vote up
def configure(opts: AndroidOpts, product: str, target: str):
    env = { 'ANDROID_API_VERSION': get_api_version_or_min(opts, target) }

    if is_cross(target):
        import llvm

        if is_cross_mxe(target):
            llvm.make(opts, 'llvmwin64')
            setup_android_cross_mxe_template(env, opts, target, host_arch='x86_64')
        else:
            llvm.make(opts, 'llvm64')
            setup_android_cross_template(env, opts, target, host_arch='x86_64')
    else:
        make_standalone_toolchain(opts, target, env['ANDROID_API_VERSION'])
        setup_android_target_template(env, opts, target)

    if not os.path.isfile(path_join(opts.mono_source_root, 'configure')):
        runtime.run_autogen(opts)

    runtime.run_configure(env, opts, product, target) 
Example 7
Project: godot-mono-builds   Author: godotengine   File: runtime.py    MIT License 6 votes vote down vote up
def run_configure(env: dict, opts: RuntimeOpts, product: str, target: str):
    build_dir = path_join(opts.configure_dir, '%s-%s-%s' % (product, target, opts.configuration))
    mkdir_p(build_dir)

    def str_dict_val(val):
        if isinstance(val, list):
            return ' '.join(val) # Don't need to surround with quotes
        return val

    ac_vars = env['_runtime_%s-%s_AC_VARS' % (product, target)]
    configure_env_args = env['_runtime_%s-%s_CONFIGURE_ENVIRONMENT' % (product, target)]
    configure_env_args = [('%s=%s' % (key, str_dict_val(value))) for (key, value) in configure_env_args.items()]
    configure_flags = env['_runtime_%s-%s_CONFIGURE_FLAGS' % (product, target)]

    configure = path_join(opts.mono_source_root, 'configure')
    configure_args = ac_vars + configure_env_args + configure_flags

    configure_env = os.environ.copy()
    target_extra_path = env.get('_%s-%s_PATH' % (product, target), '')
    if target_extra_path:
        configure_env['PATH'] += ':' + target_extra_path

    run_command(configure, args=configure_args, cwd=build_dir, env=configure_env, name='configure') 
Example 8
Project: cams-tools   Author: kstopa   File: tools.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def convert(grib2_path, path_out, time, format_out=Wgrib2Format.NETCDF):
        """

        :param grib2_in: Grib2 file to be converted
        :param path_out: Output path where each avaiable time (individual grid) will be save.
        :param time: Reference time of the grib2 forecast. Can be get using Time.from_file() method.
        :type time: Time
        :param format_out: One of the ava
        :return:
        """
        files = []
        print("Converting {0} to {1}".format(grib2_path, format_out.value))
        for hour in range(1, time.get_hours_range() + 1):
            hour_num = hour+time.get_base_time()
            out_filename = path.basename(grib2_path).replace(time.value, Converter._format_hour(hour_num)).replace('.grib2', '.{0}'.format(format_out.get_file_extension()))
            out_filepath = path.join(path_out, out_filename)
            cmd = ['wgrib2', grib2_path, '-d', str(hour), format_out.to_cmd(), out_filepath]
            # TODO Add error control. Check if wgrib2 worked
            call(cmd)
            files.append(out_filepath)
        return files 
Example 9
Project: pyblish-win   Author: pyblish   File: fix_import.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def traverse_imports(names):
    """
    Walks over all the names imported in a dotted_as_names node.
    """
    pending = [names]
    while pending:
        node = pending.pop()
        if node.type == token.NAME:
            yield node.value
        elif node.type == syms.dotted_name:
            yield "".join([ch.value for ch in node.children])
        elif node.type == syms.dotted_as_name:
            pending.append(node.children[0])
        elif node.type == syms.dotted_as_names:
            pending.extend(node.children[::-2])
        else:
            raise AssertionError("unknown node type") 
Example 10
Project: pyblish-win   Author: pyblish   File: test_sdist.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def test_unicode_metadata_tgz(self):
        """
        Unicode name or version should not break building to tar.gz format.
        Reference issue #11638.
        """

        # create the sdist command with unicode parameters
        dist, cmd = self.get_cmd({'name': u'fake', 'version': u'1.0'})

        # create the sdist as gztar and run the command
        cmd.formats = ['gztar']
        cmd.ensure_finalized()
        cmd.run()

        # The command should have created the .tar.gz file
        dist_folder = join(self.tmp_dir, 'dist')
        result = os.listdir(dist_folder)
        self.assertEqual(result, ['fake-1.0.tar.gz'])

        os.remove(join(dist_folder, 'fake-1.0.tar.gz')) 
Example 11
Project: pyblish-win   Author: pyblish   File: test_os.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def get_urandom_subprocess(self, count):
        # We need to use repr() and eval() to avoid line ending conversions
        # under Windows.
        code = '\n'.join((
            'import os, sys',
            'data = os.urandom(%s)' % count,
            'sys.stdout.write(repr(data))',
            'sys.stdout.flush()',
            'print >> sys.stderr, (len(data), data)'))
        cmd_line = [sys.executable, '-c', code]
        p = subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        out, err = p.communicate()
        self.assertEqual(p.wait(), 0, (p.wait(), err))
        out = eval(out)
        self.assertEqual(len(out), count, err)
        return out 
Example 12
Project: python-pyvot-cookiecutter   Author: microsoft   File: pyvot_app.py    MIT License 6 votes vote down vote up
def main():
    """Loads and modifies a sample spreadsheet in Excel."""
    workbook_path = path.join(path.dirname(__file__), 'pyvot_sample.xlsx')
    workbook = xl.Workbook(workbook_path)

    workbook.range("A1").set("Hello World!")

    def doubled(val):
        """Returns double of value passed in."""
        return 2 * val

    def alpha(val):
        """Returns letter at specified position in alphabet."""
        return "abcdefgh"[int(val) - 1]

    xl.map(doubled, workbook.get("Values"))
    xl.map(alpha, workbook.get("doubled"))

    print(workbook.range("C3:E7").get()) 
Example 13
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: loaders.py    Apache License 2.0 6 votes vote down vote up
def get_source(self, environment, template):
        pieces = split_template_path(template)
        for searchpath in self.searchpath:
            filename = path.join(searchpath, *pieces)
            f = open_if_exists(filename)
            if f is None:
                continue
            try:
                contents = f.read().decode(self.encoding)
            finally:
                f.close()

            mtime = path.getmtime(filename)
            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False
            return contents, filename, uptodate
        raise TemplateNotFound(template) 
Example 14
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: loaders.py    Apache License 2.0 6 votes vote down vote up
def get_source(self, environment, template):
        pieces = split_template_path(template)
        for searchpath in self.searchpath:
            filename = path.join(searchpath, *pieces)
            f = open_if_exists(filename)
            if f is None:
                continue
            try:
                contents = f.read().decode(self.encoding)
            finally:
                f.close()

            mtime = path.getmtime(filename)
            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False
            return contents, filename, uptodate
        raise TemplateNotFound(template) 
Example 15
Project: Gurux.DLMS.Python   Author: Gurux   File: GXManufacturerCollection.py    GNU General Public License v2.0 5 votes vote down vote up
def isFirstRun(cls, path):
        if not os.path.isdir(path):
            os.mkdir(path)
            return True
        if not os.path.isfile(os.path.join(path, "files.xml")):
            return True
        return False

    #
    # Check if there are any updates available in Gurux www server.
    #
    # @param path
    #            Settings directory.
    # Returns true if there are any updates available.
    # 
Example 16
Project: PEAKachu   Author: tbischler   File: replicons.py    ISC License 5 votes vote down vote up
def _check_annotations(self):
        if self._gff_folder is None:
            print("No folder with .gff files specified")
        else:
            gff_files = [join(self._gff_folder, f) for f in listdir(
                self._gff_folder) if isfile(join(self._gff_folder, f))]
            if not gff_files:
                print("No .gff file found in specified folder")
            else:
                for gff_file in gff_files:
                    self._store_annotations(gff_file) 
Example 17
Project: PEAKachu   Author: tbischler   File: replicons.py    ISC License 5 votes vote down vote up
def _store_annotations(self, gff_file):
        with open(gff_file) as gff_fh:
            for rec in GFF.parse(gff_fh, limit_info=self._limit_info):
                if rec.id not in self.replicon_dict:
                    sys.stderr.write(
                        "Annotations for sequence ID {} skipped as sequence"
                        "is not present in alignment files!\n".format(rec.id))
                    continue
                if 'features' not in self.replicon_dict[rec.id]:
                    self.replicon_dict[rec.id]['features'] = []
                for feature in rec.features:
                    feature_entry = {
                        'type': feature.type,
                        'start': feature.location.start.position+1,
                        'end': feature.location.end.position,
                        'strand': '+' if feature.strand == 1 else '-',
                        'locus_tag': '/'.join(feature.qualifiers[
                            'locus_tag']) if ('locus_tag' in
                                              feature.qualifiers) else None,
                        'Name': '/'.join(feature.qualifiers[
                            'Name']) if ('Name' in
                                         feature.qualifiers) else None,
                        'product': '/'.join(feature.qualifiers[
                            'product']) if ('product' in
                                            feature.qualifiers) else None
                    }
                    for subfeature in feature.sub_features:
                        if subfeature.type not in self._sub_features:
                            continue
                        feature_entry['subfeature_type'] = subfeature.type
                        if feature_entry['product'] is not None:
                            continue
                        feature_entry['product'] = '/'.join(
                            subfeature.qualifiers['product']) if (
                                'product' in subfeature.qualifiers) else None
                    self.replicon_dict[rec.id]['features'].append(
                        feature_entry) 
Example 18
Project: PEAKachu   Author: tbischler   File: consensus_peak.py    ISC License 5 votes vote down vote up
def _store_peaks(self):
        peak_table_folder = "{}/peak_tables".format(self._project_folder)
        peak_files = [join(peak_table_folder, f) for f in listdir(
            peak_table_folder) if isfile(join(peak_table_folder, f))]
        for peak_file in peak_files:
            peak_df = pd.read_table(peak_file, sep='\t')
            for peak in peak_df.to_dict("records"):
                self._replicon_peak_dict[peak["replicon"]][
                    peak["peak_strand"]].add(
                        (peak["peak_start"], peak["peak_end"])) 
Example 19
Project: PEAKachu   Author: tbischler   File: consensus_peak.py    ISC License 5 votes vote down vote up
def _get_peak_coverage(self):
        norm_coverage_folder = "{}/normalized_coverage".format(
            self._project_folder)
        coverage_files = [join(norm_coverage_folder, f) for f in listdir(
            norm_coverage_folder) if isfile(join(norm_coverage_folder, f))]
        wiggle_parser = WiggleParser()
        cons_value_dict = defaultdict(dict)
        for coverage_file in coverage_files:
            cons_values = np.zeros(self._consensus_length)
            with open(coverage_file, 'r') as cov_fh:
                for wiggle_entry in wiggle_parser.entries(cov_fh):
                    lib_name_and_strand = wiggle_entry.track_name
                    lib_name = '_'.join(lib_name_and_strand.split('_')[:-1])
                    lib_strand = '+' if lib_name_and_strand.split(
                        '_')[-1] == "forward" else '-'
                    replicon = wiggle_entry.replicon
                    pos_value_pairs = dict(wiggle_entry.pos_value_pairs)
                    self._get_coverage_for_replicon_peaks(
                        replicon, lib_strand, pos_value_pairs, cons_values)
            cons_value_dict[lib_name][lib_strand] = cons_values
        # combine strands
        comb_cons_value_dict = {}
        for lib in cons_value_dict:
            comb_cons_value_dict[lib] = np.zeros(self._consensus_length)
            for strand in cons_value_dict[lib]:
                comb_cons_value_dict[lib] += cons_value_dict[lib][strand]
        return comb_cons_value_dict 
Example 20
Project: Coulomb   Author: DynamoDS   File: extract_sessions_buffered.py    MIT License 5 votes vote down vote up
def flush(outpath, session_maps):

    lns_count = 0
    for sessions_lst in session_maps.values():
        lns_count += len(sessions_lst)

    log ("Flushing lines/sessions: " + str(lns_count) + " / " + str(len(session_maps.keys())))

    # Verify that the folders exist
    for session in session_maps.keys():
        sessions_folder_path = join(outPath, session[0:3])
        if sessions_folder_path not in existing_sessions_path:
            if not os.path.exists(sessions_folder_path):
                os.makedirs(sessions_folder_path)
            existing_sessions_path.add(sessions_folder_path)

        sessionPath = join(sessions_folder_path, session + ".gz")
        if not os.path.exists(sessionPath):
            newSessionIDSet.add(session)
            

        o = gzip.open(sessionPath, 'a')
        # o = open(join(outPath, session + ".json"), 'a')
        for ln in session_maps[session]:
            o.write(ln)
        o.flush()

        f = open(completedInputListPath, 'a')
        for filePath in completedInputFiles_buffer:
            completedInputFiles.add(filePath)
            f.write(filePath + "\n")
        f.flush()
        completedInputFiles_buffer.clear()

    log ("Flushing complete. Total sessions:\t" + str(len(sessionIDSet)) + "\tTotal new sessions:\t" + str(len(newSessionIDSet))) 
Example 21
Project: godot-mono-builds   Author: godotengine   File: bcl.py    MIT License 5 votes vote down vote up
def configure_bcl(opts: BclOpts):
    stamp_file = path_join(opts.configure_dir, '.stamp-bcl-configure')

    if os.path.isfile(stamp_file):
        return

    if not os.path.isfile(path_join(opts.mono_source_root, 'configure')):
        runtime.run_autogen(opts)

    build_dir = path_join(opts.configure_dir, 'bcl')
    mkdir_p(build_dir)

    CONFIGURE_FLAGS = [
        '--disable-boehm',
        '--disable-btls-lib',
        '--disable-nls',
        '--disable-support-build',
        '--with-mcs-docs=no'
    ]

    configure = path_join(opts.mono_source_root, 'configure')
    configure_args = CONFIGURE_FLAGS

    run_command(configure, args=configure_args, cwd=build_dir, name='configure bcl')

    touch(stamp_file) 
Example 22
Project: godot-mono-builds   Author: godotengine   File: bcl.py    MIT License 5 votes vote down vote up
def make_bcl(opts: BclOpts):
    stamp_file = path_join(opts.configure_dir, '.stamp-bcl-make')

    if os.path.isfile(stamp_file):
        return

    build_dir = path_join(opts.configure_dir, 'bcl')

    make_args = ['-C', build_dir, '-C', 'mono']
    make_args += ['V=1'] if opts.verbose_make else []

    run_command('make', args=make_args, name='make bcl')

    touch(stamp_file) 
Example 23
Project: godot-mono-builds   Author: godotengine   File: bcl.py    MIT License 5 votes vote down vote up
def clean_bcl(opts: BclOpts):
    configure_stamp_file = path_join(opts.configure_dir, '.stamp-bcl-configure')
    make_stamp_file = path_join(opts.configure_dir, '.stamp-bcl-make')
    build_dir = path_join(opts.configure_dir, 'bcl')
    rm_rf(configure_stamp_file, make_stamp_file, build_dir) 
Example 24
Project: godot-mono-builds   Author: godotengine   File: bcl.py    MIT License 5 votes vote down vote up
def clean_product(opts: BclOpts, product: str):
    clean_bcl(opts)

    install_dir = path_join(opts.install_dir, '%s-bcl' % product)
    rm_rf(install_dir) 
Example 25
Project: godot-mono-builds   Author: godotengine   File: reference_assemblies.py    MIT License 5 votes vote down vote up
def install(opts: BaseOpts):
    build_dir = '%s/mcs/class/reference-assemblies' % opts.mono_source_root
    install_dir = path_join(opts.install_dir, 'reference-assemblies')

    mkdir_p(install_dir)

    make_args = ['-C', build_dir, 'install-local', 'DESTDIR=%s' % install_dir, 'prefix=/']
    make_args += ['V=1'] if opts.verbose_make else []
    run_command('make', args=make_args, name='make install-local') 
Example 26
Project: godot-mono-builds   Author: godotengine   File: reference_assemblies.py    MIT License 5 votes vote down vote up
def clean(opts: BaseOpts):
    install_dir = path_join(opts.install_dir, 'reference-assemblies')
    rm_rf(install_dir) 
Example 27
Project: godot-mono-builds   Author: godotengine   File: desktop.py    MIT License 5 votes vote down vote up
def strip_libs(opts: DesktopOpts, product: str, target_platform: str, target: str):
    if is_cross_compiling(target_platform):
        if target_platform == 'windows':
            mxe_bin = path_join(opts.mxe_prefix, 'bin')
            name_fmt = path_join(mxe_bin, target + '-w64-mingw32-%s')
            strip = name_fmt % 'strip'
        elif target_platform == 'osx':
            assert 'OSXCROSS_ROOT' in os.environ
            osxcross_root = os.environ['OSXCROSS_ROOT']
            osxcross_bin = path_join(osxcross_bin, 'target', 'bin')
            osxcross_sdk = get_osxcross_sdk(target, osxcross_bin)

            name_fmt = path_join(osxcross_bin, target + ('-apple-darwin%s-' % osxcross_sdk) + '%s')
            strip = name_fmt % 'strip'
    else:
        strip = 'strip'

    install_dir = path_join(opts.install_dir, '%s-%s-%s' % (product, target, opts.configuration))
    out_libs_dir = path_join(install_dir, 'lib')

    lib_files = globs(('*.a', '*.so'), dirpath=out_libs_dir)
    if len(lib_files):
        run_command(strip, args=['--strip-unneeded'] + lib_files, name='strip')

    if target_platform == 'windows':
        out_bin_dir = path_join(install_dir, 'bin')

        dll_files = globs(('*.dll',), dirpath=out_bin_dir)
        if len(dll_files):
            run_command(strip, args=['--strip-unneeded'] + dll_files, name='strip') 
Example 28
Project: godot-mono-builds   Author: godotengine   File: desktop.py    MIT License 5 votes vote down vote up
def configure(opts: DesktopOpts, product: str, target_platform: str, target: str):
    env = {}

    setup_desktop_template(env, opts, product, target_platform, target)

    if not os.path.isfile(path_join(opts.mono_source_root, 'configure')):
        runtime.run_autogen(opts)

    runtime.run_configure(env, opts, product, target) 
Example 29
Project: godot-mono-builds   Author: godotengine   File: desktop.py    MIT License 5 votes vote down vote up
def make(opts: DesktopOpts, product: str, target_platform: str, target: str):
    build_dir = path_join(opts.configure_dir, '%s-%s-%s' % (product, target, opts.configuration))

    make_args = ['-C', build_dir]
    make_args += ['V=1'] if opts.verbose_make else []

    run_command('make', args=make_args, name='make')
    run_command('make', args=['-C', '%s/mono' % build_dir, 'install'], name='make install mono')
    run_command('make', args=['-C', '%s/support' % build_dir, 'install'], name='make install support')
    run_command('make', args=['-C', '%s/data' % build_dir, 'install'], name='make install data')

    if opts.strip_libs:
        strip_libs(opts, product, target_platform, target) 
Example 30
Project: godot-mono-builds   Author: godotengine   File: desktop.py    MIT License 5 votes vote down vote up
def clean(opts: DesktopOpts, product: str, target_platform: str, target: str):
    rm_rf(
        path_join(opts.configure_dir, '%s-%s-%s' % (product, target, opts.configuration)),
        path_join(opts.configure_dir, '%s-%s-%s.config.cache' % (product, target, opts.configuration)),
        path_join(opts.install_dir, '%s-%s-%s' % (product, target, opts.configuration))
    ) 
Example 31
Project: godot-mono-builds   Author: godotengine   File: android.py    MIT License 5 votes vote down vote up
def make_standalone_toolchain(opts: AndroidOpts, target: str, api: str):
    install_dir = path_join(opts.android_toolchains_prefix, opts.toolchain_name_fmt % (target, api))
    if os.path.isdir(path_join(install_dir, 'bin')):
        return # Looks like it's already there, so no need to re-create it
    command = path_join(opts.android_ndk_root, 'build', 'tools', 'make_standalone_toolchain.py')
    args = ['--verbose', '--force', '--api=' + api, '--arch=' + AndroidTargetTable.archs[target],
            '--install-dir=' + install_dir]
    run_command(command, args=args, name='make_standalone_toolchain') 
Example 32
Project: godot-mono-builds   Author: godotengine   File: android.py    MIT License 5 votes vote down vote up
def strip_libs(opts: AndroidOpts, product: str, target: str, api: str):
    toolchain_path = path_join(opts.android_toolchains_prefix, opts.toolchain_name_fmt % (target, api))

    tools_path = path_join(toolchain_path, 'bin')
    name_fmt = AndroidTargetTable.abi_names[target] + '-%s'

    strip = path_join(tools_path, name_fmt % 'strip')

    install_dir = path_join(opts.install_dir, '%s-%s-%s' % (product, target, opts.configuration))
    out_libs_dir = path_join(install_dir, 'lib')

    lib_files = globs(('*.a', '*.so'), dirpath=out_libs_dir)
    if len(lib_files):
        run_command(strip, args=['--strip-unneeded'] + lib_files, name='strip') 
Example 33
Project: godot-mono-builds   Author: godotengine   File: android.py    MIT License 5 votes vote down vote up
def make(opts: AndroidOpts, product: str, target: str):
    env = { 'ANDROID_API_VERSION': get_api_version_or_min(opts, target) }

    build_dir = path_join(opts.configure_dir, '%s-%s-%s' % (product, target, opts.configuration))

    make_args = ['-C', build_dir]
    make_args += ['V=1'] if opts.verbose_make else []

    run_command('make', args=make_args, name='make')
    run_command('make', args=['-C', '%s/mono' % build_dir, 'install'], name='make install mono')
    run_command('make', args=['-C', '%s/support' % build_dir, 'install'], name='make install support')
    run_command('make', args=['-C', '%s/data' % build_dir, 'install'], name='make install data')

    if opts.strip_libs and not is_cross(target):
        strip_libs(opts, product, target, env['ANDROID_API_VERSION']) 
Example 34
Project: godot-mono-builds   Author: godotengine   File: android.py    MIT License 5 votes vote down vote up
def clean(opts: AndroidOpts, product: str, target: str):
    rm_rf(
        path_join(opts.configure_dir, 'toolchains', '%s-%s' % (product, target)),
        path_join(opts.configure_dir, '%s-%s-%s' % (product, target, opts.configuration)),
        path_join(opts.configure_dir, '%s-%s-%s.config.cache' % (product, target, opts.configuration)),
        path_join(opts.install_dir, '%s-%s-%s' % (product, target, opts.configuration))
    ) 
Example 35
Project: godot-mono-builds   Author: godotengine   File: wasm.py    MIT License 5 votes vote down vote up
def configure(opts: RuntimeOpts, product: str, target: str):
    env = {}

    if is_cross(target):
        if is_cross_mxe(target):
            raise RuntimeError('TODO')
        else:
            raise RuntimeError('TODO')
    else:
        setup_wasm_target_template(env, opts, target)

    if not os.path.isfile(path_join(opts.mono_source_root, 'configure')):
        runtime.run_autogen(opts)

    wasm_run_configure(env, opts, product, target, get_emsdk_root()) 
Example 36
Project: godot-mono-builds   Author: godotengine   File: wasm.py    MIT License 5 votes vote down vote up
def clean(opts: RuntimeOpts, product: str, target: str):
    rm_rf(
        path_join(opts.configure_dir, '%s-%s-%s' % (product, target, opts.configuration)),
        path_join(opts.configure_dir, '%s-%s-%s.config.cache' % (product, target, opts.configuration)),
        path_join(opts.install_dir, '%s-%s-%s' % (product, target, opts.configuration))
    ) 
Example 37
Project: invenio-openaire   Author: inveniosoftware   File: conftest.py    MIT License 5 votes vote down vote up
def __init__(self, source):
        """Initialize the harvester."""
        self.source = source
        fname = join(dirname(__file__), 'testdata/mock_oai_pmh.txt')
        with open(fname, 'r') as f:
            self.data = f.readlines() 
Example 38
Project: pyblish-win   Author: pyblish   File: test_email_torture.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def openfile(filename):
    from os.path import join, dirname, abspath
    path = abspath(join(dirname(testfile), os.pardir, 'moredata', filename))
    return open(path, 'r')

# Prevent this test from running in the Python distro 
Example 39
Project: pyblish-win   Author: pyblish   File: fix_import.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def probably_a_local_import(self, imp_name):
        if imp_name.startswith(u"."):
            # Relative imports are certainly not local imports.
            return False
        imp_name = imp_name.split(u".", 1)[0]
        base_path = dirname(self.filename)
        base_path = join(base_path, imp_name)
        # If there is no __init__.py next to the file its not in a package
        # so can't be a relative import.
        if not exists(join(dirname(base_path), "__init__.py")):
            return False
        for ext in [".py", sep, ".pyc", ".so", ".sl", ".pyd"]:
            if exists(base_path + ext):
                return True
        return False 
Example 40
Project: pyblish-win   Author: pyblish   File: os.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def _execvpe(file, args, env=None):
    if env is not None:
        func = execve
        argrest = (args, env)
    else:
        func = execv
        argrest = (args,)
        env = environ

    head, tail = path.split(file)
    if head:
        func(file, *argrest)
        return
    if 'PATH' in env:
        envpath = env['PATH']
    else:
        envpath = defpath
    PATH = envpath.split(pathsep)
    saved_exc = None
    saved_tb = None
    for dir in PATH:
        fullname = path.join(dir, file)
        try:
            func(fullname, *argrest)
        except error, e:
            tb = sys.exc_info()[2]
            if (e.errno != errno.ENOENT and e.errno != errno.ENOTDIR
                and saved_exc is None):
                saved_exc = e
                saved_tb = tb 
Example 41
Project: pyblish-win   Author: pyblish   File: test_sdist.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def setUp(self):
        # PyPIRCCommandTestCase creates a temp dir already
        # and put it in self.tmp_dir
        super(SDistTestCase, self).setUp()
        # setting up an environment
        self.old_path = os.getcwd()
        os.mkdir(join(self.tmp_dir, 'somecode'))
        os.mkdir(join(self.tmp_dir, 'dist'))
        # a package, and a README
        self.write_file((self.tmp_dir, 'README'), 'xxx')
        self.write_file((self.tmp_dir, 'somecode', '__init__.py'), '#')
        self.write_file((self.tmp_dir, 'setup.py'), SETUP_PY)
        os.chdir(self.tmp_dir) 
Example 42
Project: pyblish-win   Author: pyblish   File: test_sdist.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_make_distribution(self):
        # now building a sdist
        dist, cmd = self.get_cmd()

        # creating a gztar then a tar
        cmd.formats = ['gztar', 'tar']
        cmd.ensure_finalized()
        cmd.run()

        # making sure we have two files
        dist_folder = join(self.tmp_dir, 'dist')
        result = os.listdir(dist_folder)
        result.sort()
        self.assertEqual(result, ['fake-1.0.tar', 'fake-1.0.tar.gz'])

        os.remove(join(dist_folder, 'fake-1.0.tar'))
        os.remove(join(dist_folder, 'fake-1.0.tar.gz'))

        # now trying a tar then a gztar
        cmd.formats = ['tar', 'gztar']

        cmd.ensure_finalized()
        cmd.run()

        result = os.listdir(dist_folder)
        result.sort()
        self.assertEqual(result, ['fake-1.0.tar', 'fake-1.0.tar.gz']) 
Example 43
Project: pyblish-win   Author: pyblish   File: test_sdist.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_manual_manifest(self):
        # check that a MANIFEST without a marker is left alone
        dist, cmd = self.get_cmd()
        cmd.formats = ['gztar']
        cmd.ensure_finalized()
        self.write_file((self.tmp_dir, cmd.manifest), 'README.manual')
        self.write_file((self.tmp_dir, 'README.manual'),
                         'This project maintains its MANIFEST file itself.')
        cmd.run()
        self.assertEqual(cmd.filelist.files, ['README.manual'])

        f = open(cmd.manifest)
        try:
            manifest = [line.strip() for line in f.read().split('\n')
                        if line.strip() != '']
        finally:
            f.close()

        self.assertEqual(manifest, ['README.manual'])

        archive_name = join(self.tmp_dir, 'dist', 'fake-1.0.tar.gz')
        archive = tarfile.open(archive_name)
        try:
            filenames = [tarinfo.name for tarinfo in archive]
        finally:
            archive.close()
        self.assertEqual(sorted(filenames), ['fake-1.0', 'fake-1.0/PKG-INFO',
                                             'fake-1.0/README.manual']) 
Example 44
Project: pyblish-win   Author: pyblish   File: turtle.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def readconfig(cfgdict):
    """Read config-files, change configuration-dict accordingly.

    If there is a turtle.cfg file in the current working directory,
    read it from there. If this contains an importconfig-value,
    say 'myway', construct filename turtle_mayway.cfg else use
    turtle.cfg and read it from the import-directory, where
    turtle.py is located.
    Update configuration dictionary first according to config-file,
    in the import directory, then according to config-file in the
    current working directory.
    If no config-file is found, the default configuration is used.
    """
    default_cfg = "turtle.cfg"
    cfgdict1 = {}
    cfgdict2 = {}
    if isfile(default_cfg):
        cfgdict1 = config_dict(default_cfg)
        #print "1. Loading config-file %s from: %s" % (default_cfg, os.getcwd())
    if "importconfig" in cfgdict1:
        default_cfg = "turtle_%s.cfg" % cfgdict1["importconfig"]
    try:
        head, tail = split(__file__)
        cfg_file2 = join(head, default_cfg)
    except:
        cfg_file2 = ""
    if isfile(cfg_file2):
        #print "2. Loading config-file %s:" % cfg_file2
        cfgdict2 = config_dict(cfg_file2)
##    show(_CFG)
##    show(cfgdict2)
    _CFG.update(cfgdict2)
##    show(_CFG)
##    show(cfgdict1)
    _CFG.update(cfgdict1)
##    show(_CFG) 
Example 45
Project: pyblish-win   Author: pyblish   File: test_os.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def setUp(self):
        os.mkdir(test_support.TESTFN)
        self.fname = os.path.join(test_support.TESTFN, "f1")
        f = open(self.fname, 'wb')
        f.write("ABC")
        f.close() 
Example 46
Project: pyblish-win   Author: pyblish   File: test_os.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def tearDown(self):
        # Tear everything down.  This is a decent use for bottom-up on
        # Windows, which doesn't have a recursive delete command.  The
        # (not so) subtlety is that rmdir will fail unless the dir's
        # kids are removed first, so bottom up is essential.
        for root, dirs, files in os.walk(test_support.TESTFN, topdown=False):
            for name in files:
                os.remove(os.path.join(root, name))
            for name in dirs:
                dirname = os.path.join(root, name)
                if not os.path.islink(dirname):
                    os.rmdir(dirname)
                else:
                    os.remove(dirname)
        os.rmdir(test_support.TESTFN) 
Example 47
Project: pyblish-win   Author: pyblish   File: test_os.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_makedir(self):
        base = test_support.TESTFN
        path = os.path.join(base, 'dir1', 'dir2', 'dir3')
        os.makedirs(path)             # Should work
        path = os.path.join(base, 'dir1', 'dir2', 'dir3', 'dir4')
        os.makedirs(path)

        # Try paths with a '.' in them
        self.assertRaises(OSError, os.makedirs, os.curdir)
        path = os.path.join(base, 'dir1', 'dir2', 'dir3', 'dir4', 'dir5', os.curdir)
        os.makedirs(path)
        path = os.path.join(base, 'dir1', os.curdir, 'dir2', 'dir3', 'dir4',
                            'dir5', 'dir6')
        os.makedirs(path) 
Example 48
Project: pyblish-win   Author: pyblish   File: test_os.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def tearDown(self):
        path = os.path.join(test_support.TESTFN, 'dir1', 'dir2', 'dir3',
                            'dir4', 'dir5', 'dir6')
        # If the tests failed, the bottom-most directory ('../dir6')
        # may not have been created, so we look for the outermost directory
        # that exists.
        while not os.path.exists(path) and path != test_support.TESTFN:
            path = os.path.dirname(path)

        os.removedirs(path) 
Example 49
Project: pyblish-win   Author: pyblish   File: test_startfile.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_empty(self):
        empty = path.join(path.dirname(__file__), "empty.vbs")
        startfile(empty)
        startfile(empty, "open")
        # Give the child process some time to exit before we finish.
        # Otherwise the cleanup code will not be able to delete the cwd,
        # because it is still in use.
        sleep(0.1) 
Example 50
Project: pyblish-win   Author: pyblish   File: test_startfile.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_empty_u(self):
        empty = path.join(path.dirname(__file__), "empty.vbs")
        startfile(unicode(empty, "mbcs"))
        startfile(unicode(empty, "mbcs"), "open")
        sleep(0.1) 
Example 51
Project: plotter-bot   Author: unleashed-coding   File: bot.py    Apache License 2.0 5 votes vote down vote up
def plot(ctx, *, exp):
    exp = syp.sympify(exp)

    img_path = path.join(log_dir, 'figure.png')
    img = syp.plot(exp, show=False)
    img.save(img_path)

    return await bot.upload(img_path) 
Example 52
Project: Collaborative-Learning-for-Weakly-Supervised-Object-Detection   Author: Sunarker   File: config.py    MIT License 5 votes vote down vote up
def get_output_dir(imdb, weights_filename):
  """Return the directory where experimental artifacts are placed.
  If the directory does not exist, it is created.

  A canonical path is built using the name from an imdb and a network
  (if not None).
  """
  outdir = osp.abspath(osp.join(__C.ROOT_DIR, 'output', __C.EXP_DIR, imdb.name))
  if weights_filename is None:
    weights_filename = 'default'
  outdir = osp.join(outdir, weights_filename)
  if not os.path.exists(outdir):
    os.makedirs(outdir)
  return outdir 
Example 53
Project: Collaborative-Learning-for-Weakly-Supervised-Object-Detection   Author: Sunarker   File: config.py    MIT License 5 votes vote down vote up
def get_output_tb_dir(imdb, weights_filename):
  """Return the directory where tensorflow summaries are placed.
  If the directory does not exist, it is created.

  A canonical path is built using the name from an imdb and a network
  (if not None).
  """
  outdir = osp.abspath(osp.join(__C.ROOT_DIR, 'tensorboard', __C.EXP_DIR, imdb.name))
  if weights_filename is None:
    weights_filename = 'default'
  outdir = osp.join(outdir, weights_filename)
  if not os.path.exists(outdir):
    os.makedirs(outdir)
  return outdir 
Example 54
Project: Collaborative-Learning-for-Weakly-Supervised-Object-Detection   Author: Sunarker   File: coco.py    MIT License 5 votes vote down vote up
def __init__(self, image_set, year):
    imdb.__init__(self, 'coco_' + year + '_' + image_set)
    # COCO specific config options
    self.config = {'use_salt': True,
                   'cleanup': True}
    # name, paths
    self._year = year
    self._image_set = image_set
    self._data_path = osp.join(cfg.DATA_DIR, 'coco')
    # load COCO API, classes, class <-> id mappings
    self._COCO = COCO(self._get_ann_file())
    cats = self._COCO.loadCats(self._COCO.getCatIds())
    self._classes = tuple(['__background__'] + [c['name'] for c in cats])
    self._class_to_ind = dict(list(zip(self.classes, list(range(self.num_classes)))))
    self._class_to_coco_cat_id = dict(list(zip([c['name'] for c in cats],
                                               self._COCO.getCatIds())))
    self._image_index = self._load_image_set_index()
    # Default to roidb handler
    self.set_proposal_method('gt')
    self.competition_mode(False)

    # Some image sets are "views" (i.e. subsets) into others.
    # For example, minival2014 is a random 5000 image subset of val2014.
    # This mapping tells us where the view's images and proposals come from.
    self._view_map = {
      'minival2014': 'val2014',  # 5k val2014 subset
      'valminusminival2014': 'val2014',  # val2014 \setminus minival2014
      'test-dev2015': 'test2015',
    }
    coco_name = image_set + year  # e.g., "val2014"
    self._data_name = (self._view_map[coco_name]
                       if coco_name in self._view_map
                       else coco_name)
    # Dataset splits that have ground-truth annotations (test splits
    # do not have gt annotations)
    self._gt_splits = ('train', 'val', 'minival') 
Example 55
Project: Collaborative-Learning-for-Weakly-Supervised-Object-Detection   Author: Sunarker   File: coco.py    MIT License 5 votes vote down vote up
def _get_ann_file(self):
    prefix = 'instances' if self._image_set.find('test') == -1 \
      else 'image_info'
    return osp.join(self._data_path, 'annotations',
                    prefix + '_' + self._image_set + self._year + '.json') 
Example 56
Project: Collaborative-Learning-for-Weakly-Supervised-Object-Detection   Author: Sunarker   File: coco.py    MIT License 5 votes vote down vote up
def image_path_from_index(self, index):
    """
    Construct an image path from the image's "index" identifier.
    """
    # Example image path for index=119993:
    #   images/train2014/COCO_train2014_000000119993.jpg
    file_name = ('COCO_' + self._data_name + '_' +
                 str(index).zfill(12) + '.jpg')
    image_path = osp.join(self._data_path, 'images',
                          self._data_name, file_name)
    assert osp.exists(image_path), \
      'Path does not exist: {}'.format(image_path)
    return image_path 
Example 57
Project: Collaborative-Learning-for-Weakly-Supervised-Object-Detection   Author: Sunarker   File: coco.py    MIT License 5 votes vote down vote up
def _get_box_file(self, index):
    # first 14 chars / first 22 chars / all chars + .mat
    # COCO_val2014_0/COCO_val2014_000000447/COCO_val2014_000000447991.mat
    file_name = ('COCO_' + self._data_name +
                 '_' + str(index).zfill(12) + '.mat')
    return osp.join(file_name[:14], file_name[:22], file_name) 
Example 58
Project: Collaborative-Learning-for-Weakly-Supervised-Object-Detection   Author: Sunarker   File: coco.py    MIT License 5 votes vote down vote up
def _do_detection_eval(self, res_file, output_dir):
    ann_type = 'bbox'
    coco_dt = self._COCO.loadRes(res_file)
    coco_eval = COCOeval(self._COCO, coco_dt)
    coco_eval.params.useSegm = (ann_type == 'segm')
    coco_eval.evaluate()
    coco_eval.accumulate()
    self._print_detection_eval_metrics(coco_eval)
    eval_file = osp.join(output_dir, 'detection_results.pkl')
    with open(eval_file, 'wb') as fid:
      pickle.dump(coco_eval, fid, pickle.HIGHEST_PROTOCOL)
    print('Wrote COCO eval results to: {}'.format(eval_file)) 
Example 59
Project: Collaborative-Learning-for-Weakly-Supervised-Object-Detection   Author: Sunarker   File: coco.py    MIT License 5 votes vote down vote up
def evaluate_detections(self, all_boxes, output_dir):
    res_file = osp.join(output_dir, ('detections_' +
                                     self._image_set +
                                     self._year +
                                     '_results'))
    if self.config['use_salt']:
      res_file += '_{}'.format(str(uuid.uuid4()))
    res_file += '.json'
    self._write_coco_results_file(all_boxes, res_file)
    # Only do evaluation on non-test sets
    if self._image_set.find('test') == -1:
      self._do_detection_eval(res_file, output_dir)
    # Optionally cleanup results json file
    if self.config['cleanup']:
      os.remove(res_file) 
Example 60
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: bccache.py    Apache License 2.0 5 votes vote down vote up
def _get_default_cache_dir(self):
        tmpdir = tempfile.gettempdir()

        # On windows the temporary directory is used specific unless
        # explicitly forced otherwise.  We can just use that.
        if os.name == 'nt':
            return tmpdir
        if not hasattr(os, 'getuid'):
            raise RuntimeError('Cannot determine safe temp directory.  You '
                               'need to explicitly provide one.')

        dirname = '_jinja2-cache-%d' % os.getuid()
        actual_dir = os.path.join(tmpdir, dirname)
        try:
            os.mkdir(actual_dir, stat.S_IRWXU) # 0o700
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise

        actual_dir_stat = os.lstat(actual_dir)
        if actual_dir_stat.st_uid != os.getuid() \
                or not stat.S_ISDIR(actual_dir_stat.st_mode) \
                or stat.S_IMODE(actual_dir_stat.st_mode) != stat.S_IRWXU:
            raise RuntimeError('Temporary directory \'%s\' has an incorrect '
	                       'owner, permissions, or type.' % actual_dir)

        return actual_dir 
Example 61
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: bccache.py    Apache License 2.0 5 votes vote down vote up
def _get_cache_filename(self, bucket):
        return path.join(self.directory, self.pattern % bucket.key) 
Example 62
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: bccache.py    Apache License 2.0 5 votes vote down vote up
def clear(self):
        # imported lazily here because google app-engine doesn't support
        # write access on the file system and the function does not exist
        # normally.
        from os import remove
        files = fnmatch.filter(listdir(self.directory), self.pattern % '*')
        for filename in files:
            try:
                remove(path.join(self.directory, filename))
            except OSError:
                pass 
Example 63
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: loaders.py    Apache License 2.0 5 votes vote down vote up
def list_templates(self):
        found = set()
        for searchpath in self.searchpath:
            for dirpath, dirnames, filenames in os.walk(searchpath):
                for filename in filenames:
                    template = os.path.join(dirpath, filename) \
                        [len(searchpath):].strip(os.path.sep) \
                                          .replace(os.path.sep, '/')
                    if template[:2] == './':
                        template = template[2:]
                    if template not in found:
                        found.add(template)
        return sorted(found) 
Example 64
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: bccache.py    Apache License 2.0 5 votes vote down vote up
def _get_default_cache_dir(self):
        tmpdir = tempfile.gettempdir()

        # On windows the temporary directory is used specific unless
        # explicitly forced otherwise.  We can just use that.
        if os.name == 'nt':
            return tmpdir
        if not hasattr(os, 'getuid'):
            raise RuntimeError('Cannot determine safe temp directory.  You '
                               'need to explicitly provide one.')

        dirname = '_jinja2-cache-%d' % os.getuid()
        actual_dir = os.path.join(tmpdir, dirname)
        try:
            os.mkdir(actual_dir, stat.S_IRWXU) # 0o700
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise

        actual_dir_stat = os.lstat(actual_dir)
        if actual_dir_stat.st_uid != os.getuid() \
                or not stat.S_ISDIR(actual_dir_stat.st_mode) \
                or stat.S_IMODE(actual_dir_stat.st_mode) != stat.S_IRWXU:
            raise RuntimeError('Temporary directory \'%s\' has an incorrect '
	                       'owner, permissions, or type.' % actual_dir)

        return actual_dir 
Example 65
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: bccache.py    Apache License 2.0 5 votes vote down vote up
def _get_cache_filename(self, bucket):
        return path.join(self.directory, self.pattern % bucket.key) 
Example 66
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: bccache.py    Apache License 2.0 5 votes vote down vote up
def clear(self):
        # imported lazily here because google app-engine doesn't support
        # write access on the file system and the function does not exist
        # normally.
        from os import remove
        files = fnmatch.filter(listdir(self.directory), self.pattern % '*')
        for filename in files:
            try:
                remove(path.join(self.directory, filename))
            except OSError:
                pass 
Example 67
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: loaders.py    Apache License 2.0 5 votes vote down vote up
def list_templates(self):
        found = set()
        for searchpath in self.searchpath:
            for dirpath, dirnames, filenames in os.walk(searchpath):
                for filename in filenames:
                    template = os.path.join(dirpath, filename) \
                        [len(searchpath):].strip(os.path.sep) \
                                          .replace(os.path.sep, '/')
                    if template[:2] == './':
                        template = template[2:]
                    if template not in found:
                        found.add(template)
        return sorted(found) 
Example 68
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: __init__.py    Apache License 2.0 5 votes vote down vote up
def get_resource(self, request, filename):
        """Return a static resource from the shared folder."""
        filename = join(dirname(__file__), 'shared', basename(filename))
        if isfile(filename):
            mimetype = mimetypes.guess_type(filename)[0] \
                or 'application/octet-stream'
            f = open(filename, 'rb')
            try:
                return Response(f.read(), mimetype=mimetype)
            finally:
                f.close()
        return Response('Not Found', status=404) 
Example 69
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: sessions.py    Apache License 2.0 5 votes vote down vote up
def generate_key(salt=None):
    if salt is None:
        salt = repr(salt).encode('ascii')
    return sha1(b''.join([
        salt,
        str(time()).encode('ascii'),
        _urandom()
    ])).hexdigest() 
Example 70
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: sessions.py    Apache License 2.0 5 votes vote down vote up
def get_session_filename(self, sid):
        # out of the box, this should be a strict ASCII subset but
        # you might reconfigure the session object to have a more
        # arbitrary string.
        if isinstance(sid, text_type) and PY2:
            sid = sid.encode(sys.getfilesystemencoding() or 'utf-8')
        return path.join(self.path, self.filename_template % sid) 
Example 71
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: __init__.py    Apache License 2.0 5 votes vote down vote up
def get_resource(self, request, filename):
        """Return a static resource from the shared folder."""
        filename = join(dirname(__file__), 'shared', basename(filename))
        if isfile(filename):
            mimetype = mimetypes.guess_type(filename)[0] \
                or 'application/octet-stream'
            f = open(filename, 'rb')
            try:
                return Response(f.read(), mimetype=mimetype)
            finally:
                f.close()
        return Response('Not Found', status=404) 
Example 72
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: sessions.py    Apache License 2.0 5 votes vote down vote up
def generate_key(salt=None):
    if salt is None:
        salt = repr(salt).encode('ascii')
    return sha1(b''.join([
        salt,
        str(time()).encode('ascii'),
        _urandom()
    ])).hexdigest() 
Example 73
Project: DataHack2018   Author: InnovizTech   File: iou_evaluator.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def evaluate_dataset(top_folder_gt, top_folder_pred, validmode=False):
    # find all folders in top_folder_gt
    folders = [e for e in os.listdir(top_folder_gt) if osp.isdir(osp.join(top_folder_gt, e))]
    if len(folders) == 0:
        raise ValueError("No folders inside ground truth folder {}".format(top_folder_gt))

    if validmode:
        # keep only folders that have matches in predictions folder
        folders = [folder for folder in folders if osp.isdir(osp.join(top_folder_pred, folder))]
    else:
        # verify all folders in gt have corresponding folders in top_folder_pred
        for folder in folders:
            if not osp.isdir(osp.join(top_folder_pred, folder)):
                raise ValueError("No matching prediction folder for {}".format(folder))

    agg_tp = 0
    agg_fp = 0
    agg_fn = 0
    # evaluate and aggregate data from all folders
    for folder in folders:
        tp, fn, fp = evaluate_folder(osp.join(top_folder_gt, folder), osp.join(top_folder_pred, folder), validmode)
        agg_tp += tp
        agg_fn += fn
        agg_fp += fp
        # calculate IoU
        if agg_tp + agg_fp + agg_fn == 0:
            iou = 1.
        else:
            iou = agg_tp / float(agg_tp + agg_fp + agg_fn)
        print("IoU: {:.2f}%".format(iou*100))

    return iou 
Example 74
Project: DataHack2018   Author: InnovizTech   File: vis_utils.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, point_cloud_size):
        format = GeomVertexFormat.getV3c4t2()
        vdata = GeomVertexData('point', format, Geom.UHDynamic)
        self._pos_writer = GeomVertexWriter(vdata, 'vertex')
        self._color_writer = GeomVertexWriter(vdata, 'color')
        self._tex_writer = GeomVertexWriter(vdata, 'texcoord')
        self._point_cloud_size = point_cloud_size
        self._prev_point_cloud_size = 0

        assert point_cloud_size > 0
        vdata.setNumRows(point_cloud_size * 6)
        self._tex_writer.set_row(0)
        set_texture(self._tex_writer, point_cloud_size)
        pnts = GeomTriangles(Geom.UHStatic)
        pnts.addConsecutiveVertices(0, 3 * 2 * point_cloud_size)
        pnts.closePrimitive()
        points_geom = Geom(vdata)
        points_geom.addPrimitive(pnts)
        snode = GeomNode('points')
        snode.addGeom(points_geom)
        dir_name = osp.dirname(__file__)
        # print(osp.join(dir_name, 'pnts_vs.glsl'))
        vs_shader = osp.join(dir_name, 'pnts_vs.glsl')
        fs_shader = osp.join(dir_name, 'pnts_fs.glsl')
        myShader = Shader.load(Shader.SL_GLSL, vertex=Filename.fromOsSpecific(vs_shader).getFullpath(),
                               fragment=Filename.fromOsSpecific(fs_shader).getFullpath())

        assert myShader is not None
        self.points_node = base.render.attachNewNode(snode)
        self.points_node.setPos(0., 0., 0.)
        self.points_node.set_shader(myShader)
        self.points_node.set_shader_input("view_size", (base.win.getXSize(), base.win.getYSize()))
        self.points_node.node().setBounds(BoundingBox((-1000., -1000., -1000.), (1000., 1000., 1000.)))
        self.points_node.setTransparency(TransparencyAttrib.MAlpha) 
Example 75
Project: DataHack2018   Author: InnovizTech   File: data_utils.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def find_sorted_files(main_dir, file_type):
    # find all point cloud files
    path_re = osp.join(main_dir, '[0-9]*_' + file_type + '.csv')
    return sorted(glob.glob(path_re)) 
Example 76
Project: badge-o-matic   Author: markuslindenberg   File: webapp.py    BSD 2-Clause "Simplified" License 4 votes vote down vote up
def badge():
    name = request.form['name'][:MAX_CHARS_PER_LINE] if 'name' in request.form else ''
    name2 = request.form['name2'][:MAX_CHARS_PER_LINE] if 'name2' in request.form else ''
    nick = request.form['nick'][:MAX_CHARS_PER_LINE] if 'nick' in request.form else ''
    community = request.form['community'][:MAX_CHARS_PER_LINE] if 'community' in request.form else ''

    pdf = BytesIO()
    c = Canvas(pdf, pagesize=(BADGE_W, BADGE_H))

    c.translate(ORIGIN_X, ORIGIN_Y)

    ico_center = 7*mm
    offset = HEIGHT+2*mm

    c.setFillGray(0.66)
    c.setFont('Awesome', 42)
    c.drawCentredString(ico_center, offset-42*pica/12, '\uf007')
    c.setFont('Awesome', 38)
    c.drawCentredString(ico_center, offset-(2*42+40)*pica/12, '\uf1fa')
    c.drawCentredString(ico_center, offset-(2*42+2*40)*pica/12, '\uf041')

    txt_start = 15*mm

    c.setFillGray(0.0)
    c.setFont('LeagueGothic', 42)
    c.drawString(txt_start, offset-42*pica/12, name)
    c.drawString(txt_start, offset-2*42*pica/12, name2)
    c.setFont('LeagueGothic', 38)
    c.drawString(txt_start, offset-(2*42+40)*pica/12, nick)
    c.drawString(txt_start, offset-(2*42+2*40)*pica/12, community)

    evt_width = 38*pica/12
    evt_start = WIDTH - evt_width

    img_width = 20*mm
    img_start = evt_start - img_width
    c.drawImage(path.join(path.dirname(__file__), 'images/ffrhein_logo_claim_line_rot.png'), img_start, 0, img_width, HEIGHT, mask=None, preserveAspectRatio=True, anchor='c')

    c.rotate(90)
    c.rect(0, -WIDTH, HEIGHT, evt_width, 0, 1)
    c.setFillGray(1.0)
    c.drawCentredString(HEIGHT/2, -WIDTH+MARGIN_R, 'routing days')  

    c.showPage()
    c.save()
    _print(pdf.getvalue())
    pdf.close()

    # response = make_response('Meh')
    # response.headers['Content-Type'] = 'text/plain'
    # return response
    return redirect('/badge/printing.html') 
Example 77
Project: godot-mono-builds   Author: godotengine   File: bcl.py    MIT License 4 votes vote down vote up
def make_product(opts: BclOpts, product: str):
    build_bcl(opts)

    build_dir = path_join(opts.configure_dir, 'bcl')

    profiles = profiles_table[product]
    test_profiles = test_profiles_table[product]

    install_dir = path_join(opts.install_dir, '%s-bcl' % product)

    mkdir_p(install_dir)

    for profile in profiles:
        mkdir_p('%s/%s' % (install_dir, profile))

    make_args = ['-C', build_dir, '-C', 'runtime', 'all-mcs', 'build_profiles=%s' % ' '.join(profiles)]
    make_args += ['V=1'] if opts.verbose_make else []
    run_command('make', args=make_args, name='make profiles')

    if opts.tests and len(test_profiles) > 0:
        test_make_args = ['-C', build_dir, '-C', 'runtime', 'test', 'xunit-test', 'test_profiles=%s' % ' '.join(test_profiles)]
        test_make_args += ['V=1'] if opts.verbose_make else []
        run_command('make', args=test_make_args, name='make tests')

    # Copy the bcl profiles to the output directory
    from distutils.dir_util import copy_tree
    for profile in profiles:
        copy_tree('%s/mcs/class/lib/%s' % (opts.mono_source_root, profile), '%s/%s' % (install_dir, profile))

    # Remove unneeded files
    import glob
    file_patterns = []
    file_patterns += ['.*'] # Recursively remove hidden files we shoudln't have copied (e.g.: .stamp)
    file_patterns += ['*.dll.so', '*.exe.so'] # Remove pre-built AOT modules. We don't need them and they take a lot of space.
    file_patterns += ['*.pdb'] if opts.remove_pdb else []
    for profile in profiles:
        for file_pattern in file_patterns:
            file_pattern_recursive = '%s/**/%s' % (install_dir, file_pattern)
            [rm_rf(x) for x in glob.iglob(file_pattern_recursive, recursive=True)]

    # godot_android_ext profile (custom 'Mono.Android.dll')
    if product == 'android':
        this_script_dir = os.path.dirname(os.path.realpath(__file__))
        monodroid_profile_dir = '%s/%s' % (install_dir, 'monodroid')
        godot_profile_dir = '%s/%s' % (install_dir, 'godot_android_ext')
        refs = ['mscorlib.dll', 'System.Core.dll', 'System.dll']

        mkdir_p(godot_profile_dir)

        android_env_csc_args = [
            path_join(this_script_dir, 'files', 'godot-AndroidEnvironment.cs'),
            '-target:library', '-out:%s' % path_join(godot_profile_dir, 'Mono.Android.dll'),
            '-nostdlib', '-noconfig', '-langversion:latest'
        ]
        android_env_csc_args += ['-r:%s' % path_join(monodroid_profile_dir, r) for r in refs]

        run_command('csc', android_env_csc_args) 
Example 78
Project: godot-mono-builds   Author: godotengine   File: llvm.py    MIT License 4 votes vote down vote up
def make(opts: BaseOpts, target: str):
    stamp_file = path_join(opts.configure_dir, '.stamp-%s-make' % target)

    if os.path.isfile(stamp_file):
        return

    build_dir = path_join(opts.configure_dir, 'llvm-%s' % target)
    install_dir = path_join(opts.install_dir, 'llvm-%s' % target)

    mkdir_p(build_dir)
    mkdir_p(install_dir)

    CMAKE_ARGS = []

    if target in mxe_targets:
        mxe = mxe_targets[target]['mxe']
        arch = mxe_targets[target]['arch']

        CMAKE_ARGS += [
            '-DCMAKE_EXE_LINKER_FLAGS="-static"',
            '-DCROSS_TOOLCHAIN_FLAGS_NATIVE=-DCMAKE_TOOLCHAIN_FILE=%s/external/llvm/cmake/modules/NATIVE.cmake' % opts.mono_source_root,
            '-DCMAKE_TOOLCHAIN_FILE=%s/external/llvm/cmake/modules/%s.cmake' % (opts.mono_source_root, mxe),
            '-DLLVM_ENABLE_THREADS=Off',
            '-DLLVM_BUILD_EXECUTION_ENGINE=Off'
        ]

        if sys.platform == 'darwin':
            mingw_zlib_prefix = '%s/opt/mingw-zlib/usr' % opts.mxe_prefix
            if not os.path.isfile(mingw_zlib_prefix):
                mingw_zlib_prefix = opts.mxe_prefix

            CMAKE_ARGS += [
                '-DZLIB_ROOT=%s/%s-w64-mingw32' % (mingw_zlib_prefix, arch),
                '-DZLIB_LIBRARY=%s/%s-w64-mingw32/lib/libz.a' % (mingw_zlib_prefix, arch),
                '-DZLIB_INCLUDE_DIR=%s/%s-w64-mingw32/include' % (mingw_zlib_prefix, arch)
            ]

        replace_in_new_file(
            src_file='%s/sdks/builds/%s.cmake.in' % (opts.mono_source_root, mxe),
            search='@MXE_PATH@', replace=opts.mxe_prefix,
            dst_file='%s/external/llvm/cmake/modules/%s.cmake' % (opts.mono_source_root, mxe)
        )

    if target in ['llvm32', 'llvmwin32']:
        CMAKE_ARGS += ['-DLLVM_BUILD_32_BITS=On']

    CMAKE_ARGS += [os.environ.get('llvm-%s_CMAKE_ARGS' % target, '')]

    make_args = [
	    '-C', '%s/llvm' % opts.mono_source_root,
        '-f', 'build.mk', 'install-llvm',
		'LLVM_BUILD=%s' % build_dir,
		'LLVM_PREFIX=%s' % install_dir,
		'LLVM_CMAKE_ARGS=%s' % ' '.join([a for a in CMAKE_ARGS if a])
    ]

    make_args += ['V=1'] if opts.verbose_make else []

    run_command('make', args=make_args, name='make')

    touch(stamp_file) 
Example 79
Project: godot-mono-builds   Author: godotengine   File: desktop.py    MIT License 4 votes vote down vote up
def setup_desktop_template(env: dict, opts: DesktopOpts, product: str, target_platform: str, target: str):
    host_triple = host_triples[target_platform] % target

    CONFIGURE_FLAGS = [
        '--disable-boehm',
        '--disable-iconv',
        '--disable-mcs-build',
        '--disable-nls',
        '--enable-dynamic-btls',
        '--enable-maintainer-mode',
        '--with-sigaltstack=yes',
        '--with-tls=pthread',
        '--without-ikvm-native'
    ]

    if target_platform == 'windows':
        mxe_bin = path_join(opts.mxe_prefix, 'bin')

        env['_%s-%s_PATH' % (product, target)] = mxe_bin

        name_fmt = path_join(mxe_bin, target + '-w64-mingw32-%s')

        env['_%s-%s_AR' % (product, target)] = name_fmt % 'ar'
        env['_%s-%s_AS' % (product, target)] = name_fmt % 'as'
        env['_%s-%s_CC' % (product, target)] = name_fmt % 'gcc'
        env['_%s-%s_CXX' % (product, target)] = name_fmt % 'g++'
        env['_%s-%s_DLLTOOL' % (product, target)] = name_fmt % 'dlltool'
        env['_%s-%s_LD' % (product, target)] = name_fmt % 'ld'
        env['_%s-%s_OBJDUMP' % (product, target)] = name_fmt % 'objdump'
        env['_%s-%s_RANLIB' % (product, target)] = name_fmt % 'ranlib'
        env['_%s-%s_STRIP' % (product, target)] = name_fmt % 'strip'

        CONFIGURE_FLAGS += [
            '--enable-static-gcc-libs'
        ]
    elif target_platform == 'osx' and 'OSXCROSS_ROOT' in os.environ:
        osxcross_root = os.environ['OSXCROSS_ROOT']
        osxcross_bin = path_join(osxcross_root, 'target', 'bin')
        osxcross_sdk = get_osxcross_sdk(target, osxcross_bin)

        env['_%s-%s_PATH' % (product, target)] = osxcross_bin

        name_fmt = path_join(osxcross_bin, target + ('-apple-darwin%s-' % osxcross_sdk) + '%s')

        env['_%s-%s_AR' % (product, target)] = name_fmt % 'ar'
        env['_%s-%s_AS' % (product, target)] = name_fmt % 'as'
        env['_%s-%s_CC' % (product, target)] = name_fmt % 'cc'
        env['_%s-%s_CXX' % (product, target)] = name_fmt % 'c++'
        env['_%s-%s_LD' % (product, target)] = name_fmt % 'ld'
        env['_%s-%s_RANLIB' % (product, target)] = name_fmt % 'ranlib'
        env['_%s-%s_CMAKE' % (product, target)] = name_fmt % 'cmake'
        env['_%s-%s_STRIP' % (product, target)] = name_fmt % 'strip'
    else:
        env['_%s-%s_CC' % (product, target)] = 'cc'

    env['_%s-%s_CONFIGURE_FLAGS' % (product, target)] = CONFIGURE_FLAGS

    llvm = llvm_table[target_platform][target] if opts.with_llvm else ''

    runtime.setup_runtime_template(env, opts, product, target, host_triple, llvm=llvm) 
Example 80
Project: pyblish-win   Author: pyblish   File: test_sdist.py    GNU Lesser General Public License v3.0 4 votes vote down vote up
def test_make_distribution_owner_group(self):
        # now building a sdist
        dist, cmd = self.get_cmd()

        # creating a gztar and specifying the owner+group
        cmd.formats = ['gztar']
        cmd.owner = pwd.getpwuid(0)[0]
        cmd.group = grp.getgrgid(0)[0]
        cmd.ensure_finalized()
        cmd.run()

        # making sure we have the good rights
        archive_name = join(self.tmp_dir, 'dist', 'fake-1.0.tar.gz')
        archive = tarfile.open(archive_name)
        try:
            for member in archive.getmembers():
                self.assertEqual(member.uid, 0)
                self.assertEqual(member.gid, 0)
        finally:
            archive.close()

        # building a sdist again
        dist, cmd = self.get_cmd()

        # creating a gztar
        cmd.formats = ['gztar']
        cmd.ensure_finalized()
        cmd.run()

        # making sure we have the good rights
        archive_name = join(self.tmp_dir, 'dist', 'fake-1.0.tar.gz')
        archive = tarfile.open(archive_name)

        # note that we are not testing the group ownership here
        # because, depending on the platforms and the container
        # rights (see #7408)
        try:
            for member in archive.getmembers():
                self.assertEqual(member.uid, os.getuid())
        finally:
            archive.close()

    # the following tests make sure there is a nice error message instead
    # of a traceback when parsing an invalid manifest template