Пример #1
0
    def write_files(self):

        absolute_base_file = None
        tempdir = tempfile.mkdtemp()

        if zipfile.is_zipfile(self.cleaned_data['base_file']):
            absolute_base_file = unzip_file(self.cleaned_data['base_file'], '.shp', tempdir=tempdir)

        else:
            for field in self.spatial_files:
                f = self.cleaned_data[field]
                if f is not None:
                    path = os.path.join(tempdir, f.name)
                    with open(path, 'wb') as writable:
                        for c in f.chunks():
                            writable.write(c)
            absolute_base_file = os.path.join(tempdir,
                                              self.cleaned_data["base_file"].name)
        return tempdir, absolute_base_file
        import configuration

        config = configuration.ConfigClass()

        # do we need to download a pretrained model?
        model_url = config.get_model_url()
        if model_url is not None and config.get_download_model():
            import utils

            dest_path = 'model.zip'
            utils.download_file_from_google_drive(model_url, dest_path)
            if not os.path.exists(model_dir):
                os.mkdir(model_dir)
            if os.path.exists(dest_path):
                utils.unzip_file(dest_path, model_dir)
                logging.info(f'Successfully downloaded and extracted pretrained model into {model_dir}.')
            else:
                logging.error('model.zip file does not exists.')

        # test for each search engine module
        #engine_modules = ['search_engine_' + name for name in ['1', '2', 'best']]
        engine_modules = ['search_engine_' + name for name in ['3']]
        for engine_module in engine_modules:
            try:
                # does the module file exist?
                if not test_file_exists(engine_module + '.py'):
                    continue
                # try importing the module
                se = importlib.import_module(engine_module)
                logging.info(f"Successfully imported module {engine_module}.")
Пример #3
0
import os, sys
import utils
import subprocess

if __name__ == "__main__":
    # Argumentos que o programa deve receber:
    # -1º: Ano que desejar baixar dos contratos
    # -2º: Caminho da pasta de destino

    if len(sys.argv) != 3:
        utils.print_usage()
        exit(1)

    year = str(sys.argv[1])
    output_path = str(sys.argv[2])
    url = 'http://dados.tce.rs.gov.br/dados/licitacon/contrato/ano/' + year + '.csv.zip'
    path = output_path + '/contratos/' + year
    file_name = year + '.csv.zip'
    utils.download_zip(url, file_name)
    utils.unzip_file(file_name, path)
    subprocess.call(['chmod', '-R', '0777', output_path + '/contratos/'])
    os.remove(file_name)
Пример #4
0
    def _dependency(self, snm, sver, ars):
        spth = self.get_path_tmp() + os.sep + snm
        smsg = snm + " " + sver
        utils.info("BEGIN " + snm)
        try:
            conf = utils.read_json_file(spth + os.sep + snm + ".json")
            bupd = True
            if conf is not None:
                if "version" in conf:
                    if conf["version"] == sver:
                        bupd = False
                    else:
                        utils.info("incorrect version.")
                else:
                    utils.info("version not found.")
            else:
                utils.info("version not found.")
            if bupd:
                sfx = detectinfo.get_native_suffix()
                if sfx is None or "generic" in sfx:
                    utils.info("os not detected.")
                    raise Exception("You have to compile it manually.")
                if self._b32bit:
                    sfx = sfx.replace("64", "32")
                utils.init_path(spth)
                utils.info("download headers and library ...")
                nurl = utils.get_node_url()

                if snm is not "lib_gcc" and snm is not "lib_stdcpp":
                    appnm = "headers_" + snm + ".zip"
                    utils.download_file(nurl + "getAgentFile.dw?name=" + appnm,
                                        spth + os.sep + appnm)
                    utils.unzip_file(spth + os.sep + appnm, spth + os.sep)
                    utils.remove_file(spth + os.sep + appnm)

                appnm = snm + "_" + sfx + ".zip"
                utils.download_file(nurl + "getAgentFile.dw?name=" + appnm,
                                    spth + os.sep + appnm)
                utils.unzip_file(spth + os.sep + appnm, spth + os.sep,
                                 "native/")
                utils.remove_file(spth + os.sep + appnm)
                #FIX Version
                conf = utils.read_json_file(spth + os.sep + snm + ".json")
                if conf is not None:
                    if "version" not in conf:
                        conf["version"] = sver
                        utils.write_json_file(conf,
                                              spth + os.sep + snm + ".json")

            #COPY LIB TO NATIVE
            for f in os.listdir(spth):
                if f.endswith('.dll') or f.endswith('.so') or f.endswith(
                        '.dylib'):
                    shutil.copy2(spth + os.sep + f,
                                 self.get_path_native() + os.sep + f)

            #POST FIX
            self._dependency_post_fix(snm, sver)

            smsg += " - OK!"
            ars.append(smsg)
            utils.info("END " + snm)
        except Exception as e:
            smsg += " - ERROR: " + utils.exception_to_string(e)
            ars.append(smsg)
            raise e