def run(pkg, clusterUrl, clusterName, directory):

#Initial some thing.Just like copy & extract tccbus.ear packages
    x = ModifyZip(pkg)
    x.Copy()
    x.Extract()
    #print "Tempdir: %s" % x.tempdir

##modify the file like jndi.properties & jboss.xml in the tccbus.ear program 
#packages. Just like:
#   TccBus.ear/TccBusWeb.war/WEB-INF/classes/jndi.properties
#   TccBus.ear/TccBusEJB.jar/jndi.properties
#   TccBus.ear/TccBusEJB.jar/META-INF/jboss.xml

    x.ModifyFile('jndi.properties', clusterUrl, \
            clusterName, os.path.join(x.tempdir, 'TccBusWeb.war'), os.path.join(x.tempdir, 'TccBusWeb1.war'))
    x.ModifyFile('jndi.properties', clusterUrl, \
            clusterName, os.path.join(x.tempdir, 'TccBusEJB.jar'), os.path.join(x.tempdir, 'TccBusEJB1.jar'))
    x.ModifyFile('jboss.xml', clusterUrl, \
            clusterName, os.path.join(x.tempdir, 'TccBusEJB1.jar'), os.path.join(x.tempdir, 'TccBusEJB2.jar'))

#modify TccBus.ear. Add New zipfile in TccBus.ear.
    x.ModifyZip(os.path.join(x.tempdir, 'TccBus.ear'), os.path.join(x.tempdir, 'TccBus1.ear'), \
            'TccBusWeb.war', os.path.join(x.tempdir, 'TccBusWeb1.war'))
    x.ModifyZip(os.path.join(x.tempdir, 'TccBus1.ear'), os.path.join(x.tempdir, 'TccBus2.ear'), \
            'TccBusEJB.jar', os.path.join(x.tempdir, 'TccBusEJB2.jar'))

#####Copy the modified package to export dir.
    shutil.copy2(os.path.join(x.tempdir, 'TccBus2.ear'), os.path.join(directory, 'TccBus.ear'))
	def log(self, file, crashReport = None, fileDesc = None, maxPerIssue=25):
		tmpDir = "" + self.dir		
		if not os.path.isdir(tmpDir):
			os.makedirs(tmpDir)	
		
		if crashReport != None:
			if crashReport.nearNull:
				tmpDir += "/nearNull"
			else:
				tmpDir += "/notNearNull"
			if not os.path.isdir(tmpDir):
				os.makedirs(tmpDir)	
				
			tmpDir += "/" + crashReport.type
			if not os.path.isdir(tmpDir):
				os.makedirs(tmpDir)	
				
			tmpDir += "/" + crashReport.location.replace(":",".")
			if not os.path.isdir(tmpDir):
				os.makedirs(tmpDir)
				
		count = len(os.listdir(tmpDir))/2
		if count >= maxPerIssue:
			return
		shutil.copy2(file, tmpDir  + ("/%04d_crash" % count) + os.path.splitext(file)[1])
		fout = open(tmpDir + ("/%04d_description.txt" % count), "wb")
		if fileDesc != None:
			fout.write(fileDesc + "\n\n")
		if crashReport != None:
			fout.write(crashReport.getInfo())
		fout.close()
		
		
Example #3
0
    def __update_dse_ldif(self):
        """
        This method updates dse.ldif right after instance creation. This is
        supposed to allow admin modify configuration of the DS which has to be
        done before IPA is fully installed (for example: settings for
        replication on replicas)
        DS must be turned off.
        """
        dse_filename = os.path.join(
            paths.ETC_DIRSRV_SLAPD_INSTANCE_TEMPLATE % self.serverid,
            'dse.ldif'
        )

        with tempfile.NamedTemporaryFile(
                mode='w', delete=False) as new_dse_ldif:
            temp_filename = new_dse_ldif.name
            with open(dse_filename, "r") as input_file:
                parser = installutils.ModifyLDIF(input_file, new_dse_ldif)
                parser.replace_value(
                        'cn=config,cn=ldbm database,cn=plugins,cn=config',
                        'nsslapd-db-locks',
                        [b'50000']
                        )
                if self.config_ldif:
                    # parse modifications from ldif file supplied by the admin
                    with open(self.config_ldif, "r") as config_ldif:
                        parser.modifications_from_ldif(config_ldif)
                parser.parse()
            new_dse_ldif.flush()
        shutil.copy2(temp_filename, dse_filename)
        tasks.restore_context(dse_filename)
        try:
            os.remove(temp_filename)
        except OSError as e:
            logger.debug("Failed to clean temporary file: %s", e)
Example #4
0
def main():

    # Parameters.
    bookmarkdir = os.environ["HOME"] + "/Dropbox/Apps/pinboard/"
    pinboard_credentials = bookmarkdir + "pinboard_credentials.txt"
    current = bookmarkdir + "most_current_bookmarks.xml"

    pinboard_api = "https://api.pinboard.in/v1/"
    yearfmt = "%Y"
    datefmt = "%m-%d"
    homeTZ = pytz.timezone("GMT")
    y = datetime.now(pytz.utc).strftime(yearfmt)
    t = datetime.now(pytz.utc).strftime(datefmt)

    daily_file = bookmarkdir + y + "/pinboard-backup." + t + ".xml"

    # Get the user's authentication token
    with open(pinboard_credentials) as credentials:
        for line in credentials:
            me, token = line.split(":")

    if not os.path.exists(bookmarkdir + y):
        os.makedirs(bookmarkdir + y)

    # Set up a new bookmarks file
    bookmarkfile = open(daily_file, "w")

    # Get all the posts from Pinboard
    u = urllib2.urlopen(pinboard_api + "posts/all?auth_token=" + me + ":" + token)
    bookmarkfile.write(u.read())
    bookmarkfile.close()
    shutil.copy2(daily_file, current)
Example #5
0
def buildApp():
    # ----------------------
    # Under Windows, we're just going to grab the xulrunner-stub.exe and run Resource Hacker
    # to rename it to "Kylo", set the icon, and set some version info, etc.
    reshack_temp_dir = os.path.join(Settings.prefs.build_dir, "stub")
    if not os.path.exists(reshack_temp_dir):
        os.makedirs(reshack_temp_dir)
    
    build_stub.main(Settings.config.get('App','Version'), 
                    Settings.config.get('App','BuildID'), 
                    temp_dir = reshack_temp_dir, 
                    stub_dir = os.path.join(Settings.prefs.build_dir, "application"))
    
    # ----------------------
    # We also need mozilla DLLS
    for lib in ["mozcrt19.dll", "mozutils.dll", "gkmedias.dll"]:
        f = os.path.join(Settings.prefs.xul_dir, lib)
        if (os.path.isfile(f)):
            shutil.copy2(f, os.path.join(Settings.prefs.build_dir, "application"))

    # ----------------------
    # Now let's grab the XULRunner directory and drop it in to our working application directory
    xulrunner_dir = os.path.join(Settings.prefs.build_dir, "application", "xulrunner")
    if not os.path.exists(xulrunner_dir):
        os.makedirs(xulrunner_dir)
        
    build_util.syncDirs(Settings.prefs.xul_dir, xulrunner_dir, exclude=["xulrunner-stub.exe"])
Example #6
0
def copy_wpt_tree(tree, dest):
    """Copy the working copy of a Tree to a destination directory.

    :param tree: The Tree to copy.
    :param dest: The destination directory"""
    if os.path.exists(dest):
        assert os.path.isdir(dest)

    shutil.rmtree(dest)
    os.mkdir(dest)

    for tree_path in tree.paths():
        source_path = os.path.join(tree.root, tree_path)
        dest_path = os.path.join(dest, tree_path)

        dest_dir = os.path.split(dest_path)[0]
        if not os.path.isdir(source_path):
            if not os.path.exists(dest_dir):
                os.makedirs(dest_dir)
            shutil.copy2(source_path, dest_path)

    for source, destination in [("testharness_runner.html", ""),
                                ("testharnessreport.js", "resources/")]:
        source_path = os.path.join(here, os.pardir, source)
        dest_path = os.path.join(dest, destination, os.path.split(source)[1])
        shutil.copy2(source_path, dest_path)

    add_license(dest)
Example #7
0
def main():
    os.chdir(os.path.dirname(os.path.realpath(__file__)))
    os.system("pip install certifi")

    print "Copying certifi's cacert.pem"
    import certifi
    shutil.copy2(certifi.where(), 'agkyra/resources/cacert.pem')
Example #8
0
 def can_retrieve_cache(self):
     if not getattr(self, "outputs", None):
         return None
     sig = self.signature()
     ssig = Utils.to_hex(self.uid()) + Utils.to_hex(sig)
     dname = os.path.join(self.generator.bld.cache_global, ssig)
     try:
         t1 = os.stat(dname).st_mtime
     except OSError:
         return None
     for node in self.outputs:
         orig = os.path.join(dname, node.name)
         try:
             shutil.copy2(orig, node.abspath())
             os.utime(orig, None)
         except (OSError, IOError):
             Logs.debug("task: failed retrieving file")
             return None
     try:
         t2 = os.stat(dname).st_mtime
     except OSError:
         return None
     if t1 != t2:
         return None
     for node in self.outputs:
         node.sig = sig
         if self.generator.bld.progress_bar < 1:
             self.generator.bld.to_log("restoring from cache %r\n" % node.abspath())
     self.cached = True
     return True
Example #9
0
 def put_files_cache(self):
     if getattr(self, "cached", None):
         return None
     sig = self.signature()
     ssig = Utils.to_hex(self.uid()) + Utils.to_hex(sig)
     dname = os.path.join(self.generator.bld.cache_global, ssig)
     tmpdir = tempfile.mkdtemp(prefix=self.generator.bld.cache_global + os.sep + "waf")
     try:
         shutil.rmtree(dname)
     except:
         pass
     try:
         for node in self.outputs:
             dest = os.path.join(tmpdir, node.name)
             shutil.copy2(node.abspath(), dest)
     except (OSError, IOError):
         try:
             shutil.rmtree(tmpdir)
         except:
             pass
     else:
         try:
             os.rename(tmpdir, dname)
         except OSError:
             try:
                 shutil.rmtree(tmpdir)
             except:
                 pass
         else:
             try:
                 os.chmod(dname, Utils.O755)
             except:
                 pass
Example #10
0
def mvrun(isimstr,**options):
    """
    Move/rename files assosiated with a run
    """
    # Get sim objects
    print 'Getting info on new file names...'
    fsimstr=mmlyt.asksimboj(infodict=isimstr.infodict,runtyp=isimstr['runtyp'])
    fname=mmlparam.par2fname('mmlyt.simlist','mmlsim',inpar=dict(fsimstr))
    # Rename old run files
    fname_new=fname+'_new'
    fname_old=fname+'_old'
    if os.path.isfile(fname): os.rename(fname,fname_old)
    if os.path.isfile(fname_new):
        print 'Using info from new file: {}'.format(fname_new)
        shutil.copy2(fname_new,fname)
    # Get sim objects
    shutil.copy2(fname,fname_new)
    # Move files
    try:
        for ftype in LIST_FILETYPES:
            mvfiles(isimstr,fsimstr,ftype,groups='all',**options)
        cleantree(simstr=isimstr,**options)
        if os.path.isfile(fname_old): os.remove(fname_old)
        os.remove(fname_new)
    except:
        print "Error moving files:", sys.exc_info()[0]
        print "Moving run files back..."
        os.rename(fname,fname_new)
        if os.path.isfile(fname_old): os.rename(fname_old,fname)
        raise
    # Return control
    return
Example #11
0
def copyfile(src, dst, logger=None, force=True, vars=None, subst_content=False):
    if vars is not None:
        src = subst_vars(src, **vars)
        dst = subst_vars(dst, **vars)
    
    if not os.path.exists(src) and not force:
        if logger is not None:
            logger.info("**Skiping copy file %s to %s. Source does not exists." % (src, dst))
        return
    
    if logger is not None:
        logger.info("Copying file %s to %s." % (src, dst))
    
    if vars is None or not subst_content:
        shutil.copy2(src, dst)
        return
    
    print ("copyfile " + src)
    f = open(src, "rt")
    content =  f.read()
    f.close()
    content = subst_vars(content, **vars)
    f = open(dst, "wt")
    f.write(content)
    f.close()
Example #12
0
def _prepare_disks(vm_settings, target_dir):
    """
    Prepare VM disks for OVF appliance creation.
    File based disks will be copied to VM creation directory.
    LVM and block-device based disks will be converted into file based images and copied to creation directory.

    @param target_dir: directory where disks will be copied
    """
    disk_list_dom = get_libvirt_conf_xml(vm_settings["vm_name"])\
                        .getElementsByTagName("domain")[0].getElementsByTagName("disk")
    disk_num, disk_list = 0, []
    for disk_dom in disk_list_dom:
        if disk_dom.getAttribute("device") == "disk":
            disk_num += 1
            source_dom = disk_dom.getElementsByTagName("source")[0]
            filename = "%s%d.img" % (vm_settings["template_name"], disk_num)
            new_path = path.join(target_dir, filename)
            if disk_dom.getAttribute("type") == "file":
                disk_path = source_dom.getAttribute("file")
                shutil.copy2(disk_path, new_path)
            elif disk_dom.getAttribute("type") == "block":
                source_dev = source_dom.getAttribute("dev")
                execute("qemu-img convert -f raw -O qcow2 %s %s" % (source_dev, new_path))
            disk_dict = {
                "file_size": str(get_file_size_bytes(new_path)),
                "filename": filename,
                "new_path": new_path,
                "file_id": "diskfile%d" % (disk_num),
                "disk_id": "vmdisk%d.img" % (disk_num),
                "disk_capacity": str(get_kvm_disk_capacity_bytes(new_path))
            }
            disk_list.append(disk_dict)
    return disk_list
Example #13
0
def copy_python(src, dst, symlinks=False):
    " Copies just Python source files "
    import shutil
    names = os.listdir(src)
    try:
        os.makedirs(dst)
    except:
        pass
    errors = []
    for name in names:
        srcname = os.path.join(src, name)
        dstname = os.path.join(dst, name)
        try:
            if symlinks and os.path.islink(srcname):
                linkto = os.readlink(srcname)
                os.symlink(linkto, dstname)
            elif os.path.isdir(srcname):
                if not name.startswith("."):
                    copy_python(srcname, dstname, symlinks)
            else:
                if name.endswith(".py"):
                    print "create", dstname
                    shutil.copy2(srcname, dstname)
            # XXX What about devices, sockets etc.?
        except (IOError, os.error), why:
            errors.append((srcname, dstname, str(why)))
        # catch the Error from the recursive copytree so that we can
        # continue with other files
        except Error, err:
            errors.extend(err.args[0])
Example #14
0
    def create_reference(self):
        """ Determines and passes the reference files to a reference folder.
        """
        if self.test_status == 'PASSED':
            reference_dir = os.path.join(self.ref_path, 'regtest-ref')
            create_dir(reference_dir)
            ltraj, lprop = self.get_filesname(self.test_path,
                                              reference_dir, self.io_dir)

            try:
                for prop in lprop:
                    for sprop in prop:
                        remove_file(sprop['old_filename'])
                        shutil.copy2(sprop['new_filename'],
                                     sprop['old_filename'])
                for traj in ltraj:
                    for straj in traj:
                        remove_file(straj['old_filename'])
                        shutil.copy2(straj['new_filename'],
                                     straj['old_filename'])
            except IOError, e:
                self.test_status = 'ERROR'
                self.msg += 'Error while copying the new reference!!\n'
                self.msg += "Unable to copy file. %s" % e
            else:
                self.test_status = 'COPIED'
Example #15
0
    def addFile(self, opath):
        """Copy PATH to MEDIADIR, and return new filename.
If the same name exists, compare checksums."""
        mdir = self.dir()
        # remove any dangerous characters
        base = re.sub(r"[][<>:/\\&]", "", os.path.basename(opath))
        dst = os.path.join(mdir, base)
        # if it doesn't exist, copy it directly
        if not os.path.exists(dst):
            shutil.copy2(opath, dst)
            return base
        # if it's identical, reuse
        if self.filesIdentical(opath, dst):
            return base
        # otherwise, find a unique name
        (root, ext) = os.path.splitext(base)
        def repl(match):
            n = int(match.group(1))
            return " (%d)" % (n+1)
        while True:
            path = os.path.join(mdir, root + ext)
            if not os.path.exists(path):
                break
            reg = " \((\d+)\)$"
            if not re.search(reg, root):
                root = root + " (1)"
            else:
                root = re.sub(reg, repl, root)
        # copy and return
        shutil.copy2(opath, path)
        return os.path.basename(os.path.basename(path))
    def install_step(self):
        """
        Install LAPACK: copy all .a files to lib dir in install directory
        """

        if self.cfg['test_only']:
            self.log.info('Only testing, so skipping make install.')
            pass

        srcdir = self.cfg['start_dir']
        destdir = os.path.join(self.installdir, 'lib')

        try:
            os.makedirs(destdir)

            # copy all .a files
            os.chdir(srcdir)
            for lib in glob.glob('*.a'):
                srcfile = os.path.join(srcdir, lib)
                self.log.debug("Copying file %s to dir %s" % (srcfile, destdir))
                shutil.copy2(srcfile, destdir)

            # symlink libraries to sensible names, if they aren't renamed already
            for (fromfile, tofile) in [('liblapack_LINUX.a', 'liblapack.a'),
                                       ('tmglib_LINUX.a', 'libtmglib.a')]:
                frompath = os.path.join(destdir, fromfile)
                topath = os.path.join(destdir, tofile)
                if os.path.isfile(frompath) and not os.path.isfile(tofile):
                    self.log.debug("Symlinking %s to %s" % (fromfile, tofile))
                    os.symlink(frompath, topath)

        except OSError, err:
            self.log.error("Copying %s to installation dir %s failed: %s" % (srcdir, destdir, err))
Example #17
0
    def _persist_file(self, abspath):
        """Persist file and bind mount it back to its current location
        """

        persisted_path = self._config_path(abspath)
        if os.path.exists(persisted_path):
            current_checksum = self.checksum(abspath)
            stored_checksum = self.checksum(persisted_path)
            if stored_checksum == current_checksum:
                self._logger.warn('File "%s" had already been persisted',
                                  abspath)
                return
            else:
                # If this happens, somehow the bind mount was undone, so we try
                # and clean up before re-persisting
                try:
                    if mount.ismount(abspath):
                        mount.umount(abspath)
                    os.unlink(persisted_path)
                except OSError as ose:
                    self._logger.error('Failed to clean up persisted file '
                                       '"%s": %s', abspath, ose.message)
        self._prepare_dir(abspath, persisted_path)
        shutil.copy2(abspath, persisted_path)
        self.copy_attributes(abspath, persisted_path)
        mount.mount(persisted_path, abspath, flags=mount.MS_BIND)
        self._logger.info('File "%s" successfully persisted', abspath)
        self._add_path_entry(abspath)
		def copytree(src, dst, symlinks=False, ignore=None):
			names = os.listdir(src)
			if ignore is not None:
				ignored_names = ignore(src, names)
			else:
				ignored_names = set()
			
			if not os.path.exists(dst): os.makedirs(dst)
			errors = []
			for name in names:
				if name in ignored_names:
					continue
				srcname = os.path.join(src, name)
				dstname = os.path.join(dst, name)
				try:
					if symlinks and os.path.islink(srcname):
						linkto = os.readlink(srcname)
						os.symlink(linkto, dstname)
					elif os.path.isdir(srcname):
						copytree(srcname, dstname, symlinks, ignore)
					else:
						shutil.copy2(srcname, dstname)
					# XXX What about devices, sockets etc.?
				except (IOError, os.error), why:
					errors.append((srcname, dstname, str(why)))
				# catch the Error from the recursive copytree so that we can
				# continue with other files
				except Error, err:
					errors.extend(err.args[0])
Example #19
0
def make_store(problem, opts, exists_handler):
    """
    Create the store directory and populate it with the model definition file.
    """
    # Determine if command line override
    if opts.store:
        problem.store = opts.store
    problem.output_path = os.path.join(problem.store, problem.name)

    # Check if already exists
    if not opts.overwrite and os.path.exists(problem.output_path + '.out'):
        if opts.batch:
            print(
                problem.store + " already exists.  Use --overwrite to replace.", file=sys.stderr)
            sys.exit(1)
        exists_handler(problem.output_path)

    # Create it and copy model
    if not os.path.exists(problem.store):
        os.mkdir(problem.store)
    shutil.copy2(problem.path, problem.store)

    # Redirect sys.stdout to capture progress
    if opts.batch:
        sys.stdout = open(problem.output_path + ".mon", "w")
Example #20
0
def client_cert(source, destination, user=None, group=None):
    """
    Copy the client certificate to the destination creating directories if
    needed and assign ownership if set.

    :param string source: The path to look for the certificate, if None
    the certificate will be copied from the default location.
    :param string destination: The path to save the certificate.
    :param string user: The optional name of the user to own the certificate.
    :param string group: The optional name of the group to own certificate.
    """
    _ensure_directory(destination, user, group)

    if not source:
        # When source not specified use the default client certificate path.
        source = os.path.join(charm_dir(),
                              'easy-rsa/easyrsa3/pki/issued/client.crt')

    # Check for the client certificate.
    if os.path.isfile(source):
        # Copy the client certificate to the destination.
        copy2(source, destination)
    else:
        # No client certificate file, get the value from unit data.
        client_cert_key = 'tls.client.certificate'
        # Save the certificate data to the destination.
        _save_unitdata(client_cert_key, destination)

    chown(destination, user, group)

    # Set the destination path for the client certificate path on the unitdata.
    unitdata.kv().set('client-cert-path', destination)
Example #21
0
def server_cert(source, destination, user=None, group=None):
    """
    Copy the server certificate to the destination, creating directories if
    needed and assign ownership if set.

    :param string source: The directory to look for the certificate, if None
    the certificate will be copied from unit data.
    :param string destination: The path to save the certificate.
    :param string user: The optional name of the user to own the certificate.
    :param string group: The optional name of the group to own certificate.
    """
    _ensure_directory(destination, user, group)

    if not source:
        # Must remove the path characters from the local unit name.
        key_name = local_unit().replace('/', '_')
        # The location of server certificate is easy-rsa/easyrsa3/pki/issued
        source = \
            os.path.join(
                charm_dir(),
                'easy-rsa/easyrsa3/pki/issued/{0}.crt'.format(key_name))

    if os.path.isfile(source):
        # Copy the server certificate to the destination.
        copy2(source, destination)
    else:
        # No source server certificate, get the value from unit data.
        server_cert_key = 'tls.server.certificate'
        # Save the certificate data to the destination directory.
        _save_unitdata(server_cert_key, destination)

    chown(destination, user, group)
    # Set the destination path for the client certificate path on the unitdata.
    unitdata.kv().set('server-cert-path', destination)
Example #22
0
def ca(source, destination, user=None, group=None):
    """
    Copy the Certificate Authority (CA) to the destination, creating parent
    directories if needed and assign owner if set. The tls layer installs the
    CA on all the peers in /usr/local/share/ca-certificates/.

    :param string source: The path to look or the certificate, if None the
    CA will be copied from the default location.
    :param string destination: The path to save the CA certificate.
    :param string user: The optional user name to own the CA certificate.
    :param string group: The optional group name to own the CA certificate.
    """
    _ensure_directory(destination, user, group)

    if not source:
        # When source not specified use the default CA path.
        source = \
            '/usr/local/share/ca-certificates/{0}.crt'.format(service_name())

    # Copy the ca certificate to the destination directory.
    copy2(source, destination)
    chown(destination, user, group)

    # Set the destination path for the ca certificate path on the unitdata.
    unitdata.kv().set('ca-cert-path', destination)
Example #23
0
    def pull(self):
        if common.isurl(self.source):
            self.download()
        else:
            shutil.copy2(self.source, self.source_dir)

        self.provision(self.source_dir)
Example #24
0
def install(host, src, dstdir):
    if isLocal(host):
        if not exists(host, src):
            util.output("file does not exist: %s" % src)
            return False

        dst = os.path.join(dstdir, os.path.basename(src))
        if exists(host, dst):
            # Do not clobber existing files/dirs (this is not an error)
            return True

        util.debug(1, "cp %s %s" % (src, dstdir))

        try:
            if os.path.isfile(src):
                shutil.copy2(src, dstdir)
            elif os.path.isdir(src):
                shutil.copytree(src, dst)
        except OSError:
            # Python 2.6 has a bug where this may fail on NFS. So we just
            # ignore errors.
            pass

    else:
        util.error("install() not yet supported for remote hosts")

    return True
Example #25
0
    def browse_curve_file(self, preferredExt="crv"):
        """
        Gets curve file from a file browser. If the returned string from the
        browser is a valid file, the curve input box is set to that new item
        and "Default Curve" and "Estimate Curve Only" are disabled

        Args:
            preferredExt (str): The extension that the browser will look for
                                whenever listing directories for a curve file
        """
        # make sure to filter out all unwanted files and leave a * (All Files)
        #
        filepaths = QtGui.QFileDialog.getOpenFileName(self, "Browse Curve Profile")
        filepaths = [x for x in filepaths if x.strip() != ""]

        for f in filepaths:
            if os.path.isfile(f) and f.lower().endswith(preferredExt):
                fname = paths.path_leaf(f)
                shutil.copy2(f, os.path.join(self.curveInputDir, fname))

                self.curveInput_cb.addItem(fname)
                index = self.curveInput_cb.findText(fname,
                                                    QtCore.Qt.MatchFixedString)
                if index >= 0:
                    self.curveInput_cb.setCurrentIndex(index)

                self.defaultCurve_cb.setEnabled(False)
                self.estimateCurve_cb.setEnabled(False)
Example #26
0
 def savedir(self, savedir):
     if savedir is None:
         self._savedir = None
     elif hasattr(self, '_savedir') and savedir == self.savedir:
         return
     else:
         if hasattr(self, '_savedir'):
             orig_dir = self.savedir
         else:
             orig_dir = False
         savedir = abspath(savedir)
         if not savedir.endswith('.sima'):
             savedir += '.sima'
         os.makedirs(savedir)
         self._savedir = savedir
         if orig_dir:
             from shutil import copy2
             for f in os.listdir(orig_dir):
                 if f.endswith('.pkl'):
                     try:
                         copy2(os.path.join(orig_dir, f), self.savedir)
                     except IOError:
                         pass
         if self._read_only:
             self._read_only = False
Example #27
0
    def configure_step(self):
        """Configure SCOTCH build: locate the template makefile, copy it to a general Makefile.inc and patch it."""

        # pick template makefile
        comp_fam = self.toolchain.comp_family()
        if comp_fam == toolchain.INTELCOMP:  #@UndefinedVariable
            makefilename = 'Makefile.inc.x86-64_pc_linux2.icc'
        elif comp_fam == toolchain.GCC:  #@UndefinedVariable
            makefilename = 'Makefile.inc.x86-64_pc_linux2'
        else:
            self.log.error("Unknown compiler family used: %s" % comp_fam)

        # create Makefile.inc
        try:
            srcdir = os.path.join(self.cfg['start_dir'], 'src')
            src = os.path.join(srcdir, 'Make.inc', makefilename)
            dst = os.path.join(srcdir, 'Makefile.inc')
            shutil.copy2(src, dst)
            self.log.debug("Successfully copied Makefile.inc to src dir.")
        except OSError:
            self.log.error("Copying Makefile.inc to src dir failed.")

        # the default behaviour of these makefiles is still wrong
        # e.g., compiler settings, and we need -lpthread
        try:
            for line in fileinput.input(dst, inplace=1, backup='.orig.easybuild'):
                # use $CC and the likes since we're at it.
                line = re.sub(r"^CCS\s*=.*$", "CCS\t= $(CC)", line)
                line = re.sub(r"^CCP\s*=.*$", "CCP\t= $(MPICC)", line)
                line = re.sub(r"^CCD\s*=.*$", "CCD\t= $(MPICC)", line)
                # append -lpthread to LDFLAGS
                line = re.sub(r"^LDFLAGS\s*=(?P<ldflags>.*$)", "LDFLAGS\t=\g<ldflags> -lpthread", line)
                sys.stdout.write(line)
        except IOError, err:
            self.log.error("Can't modify/write Makefile in 'Makefile.inc': %s" % (err))
Example #28
0
def walk(src, dest):
    print '****************************************************************'
    print dest
    print '****************************************************************'
    dirCmp = filecmp.dircmp(src, dest, ignore=['Thumbs.db'])
    for destFile in dirCmp.right_only:
        destFilePath = dest+'/'+destFile
        if os.path.isfile(destFilePath):
            print u'删除文件\n',destFilePath
            os.remove(destFilePath)
        else:
            print u'删除文件夹\n',destFilePath
#            os.rmdir(destFilePath)
            shutil.rmtree(destFilePath)
    for srcFile in dirCmp.left_only:
        srcFilePath = src+'/'+srcFile
        destFilePath = dest+'/'+srcFile
        if os.path.isfile(srcFilePath):
            print u'复制文件\n',destFilePath
            shutil.copy2(srcFilePath, dest)
        else:
            print u'复制文件夹\n',destFilePath
            shutil.copytree(srcFilePath, destFilePath)
    for srcFile in dirCmp.diff_files:
        srcFilePath = src+'/'+srcFile
        destFilePath = dest+'/'+srcFile
        print u'同步文件\n',destFilePath
        shutil.copy2(srcFilePath, dest)
    subDirs = set(os.listdir(src))-set(dirCmp.left_only)
    targetDirs = [subDir for subDir in subDirs if os.path.isdir(src+'/'+subDir)]
    for targetDir in targetDirs:
        walk(src+'/'+targetDir, dest+'/'+targetDir)
Example #29
0
    def _stage_files(self, bin_name=None):
        dirs = self.query_abs_dirs()
        abs_app_dir = self.query_abs_app_dir()

        # For mac these directories are in Contents/Resources, on other
        # platforms abs_res_dir will point to abs_app_dir.
        abs_res_dir = self.query_abs_res_dir()
        abs_res_components_dir = os.path.join(abs_res_dir, 'components')
        abs_res_plugins_dir = os.path.join(abs_res_dir, 'plugins')
        abs_res_extensions_dir = os.path.join(abs_res_dir, 'extensions')

        if bin_name:
            self.info('copying %s to %s' % (os.path.join(dirs['abs_test_bin_dir'],
                      bin_name), os.path.join(abs_app_dir, bin_name)))
            shutil.copy2(os.path.join(dirs['abs_test_bin_dir'], bin_name),
                         os.path.join(abs_app_dir, bin_name))

        self.copytree(dirs['abs_test_bin_components_dir'],
                      abs_res_components_dir,
                      overwrite='overwrite_if_exists')
        self.mkdir_p(abs_res_plugins_dir)
        self.copytree(dirs['abs_test_bin_plugins_dir'],
                      abs_res_plugins_dir,
                      overwrite='overwrite_if_exists')
        if os.path.isdir(dirs['abs_test_extensions_dir']):
            self.mkdir_p(abs_res_extensions_dir)
            self.copytree(dirs['abs_test_extensions_dir'],
                          abs_res_extensions_dir,
                          overwrite='overwrite_if_exists')
Example #30
0
def server_key(source, destination, user=None, group=None):
    """
    Copy the server key to the destination, creating directories if needed and
    assign ownership if set.

    :param string source: The directory to look for the key, if None the key
    will be copied from default location.
    :param string destination: The path to save the key.
    :param string user: The optional name of the user to own the key.
    :param string group: The optional name of the group to own key.
    """
    _ensure_directory(destination, user, group)

    if not source:
        # Must remove the path characters from the local unit name.
        key_name = local_unit().replace('/', '_')
        # The location of server key is easy-rsa/easyrsa3/pki/private
        source = \
            os.path.join(
                charm_dir(),
                'easy-rsa/easyrsa3/pki/private/{0}.key'.format(key_name))

    # Copy the key to the destination.
    copy2(source, destination)
    chown(destination, user, group)

    # Set the destination path for the client key path on the unitdata.
    unitdata.kv().set('server-key-path', destination)
Example #31
0
    def _applypatch(self, patch, force = False, reverse = False, run = True):
        import shutil

        def _applypatchhelper(shellcmd, patch, force = False, reverse = False, run = True):
            if reverse:
                shellcmd.append('-R')

            shellcmd.append(patch['file'])

            if not run:
                return "sh" + "-c" + " ".join(shellcmd)

            return runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)

        # Add hooks which add a pointer to the original patch file name in the commit message
        reporoot = (runcmd("git rev-parse --show-toplevel".split(), self.dir) or '').strip()
        if not reporoot:
            raise Exception("Cannot get repository root for directory %s" % self.dir)
        hooks_dir = os.path.join(reporoot, '.git', 'hooks')
        hooks_dir_backup = hooks_dir + '.devtool-orig'
        if os.path.lexists(hooks_dir_backup):
            raise Exception("Git hooks backup directory already exists: %s" % hooks_dir_backup)
        if os.path.lexists(hooks_dir):
            shutil.move(hooks_dir, hooks_dir_backup)
        os.mkdir(hooks_dir)
        commithook = os.path.join(hooks_dir, 'commit-msg')
        applyhook = os.path.join(hooks_dir, 'applypatch-msg')
        with open(commithook, 'w') as f:
            # NOTE: the formatting here is significant; if you change it you'll also need to
            # change other places which read it back
            f.write('echo >> $1\n')
            f.write('echo "%s: $PATCHFILE" >> $1\n' % GitApplyTree.patch_line_prefix)
        os.chmod(commithook, 0o755)
        shutil.copy2(commithook, applyhook)
        try:
            patchfilevar = 'PATCHFILE="%s"' % os.path.basename(patch['file'])
            try:
                shellcmd = [patchfilevar, "git", "--work-tree=%s" % reporoot, "am", "-3", "--keep-cr", "-p%s" % patch['strippath']]
                return _applypatchhelper(shellcmd, patch, force, reverse, run)
            except CmdError:
                # Need to abort the git am, or we'll still be within it at the end
                try:
                    shellcmd = ["git", "--work-tree=%s" % reporoot, "am", "--abort"]
                    runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
                except CmdError:
                    pass
                # git am won't always clean up after itself, sadly, so...
                shellcmd = ["git", "--work-tree=%s" % reporoot, "reset", "--hard", "HEAD"]
                runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
                # Also need to take care of any stray untracked files
                shellcmd = ["git", "--work-tree=%s" % reporoot, "clean", "-f"]
                runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)

                # Fall back to git apply
                shellcmd = ["git", "--git-dir=%s" % reporoot, "apply", "-p%s" % patch['strippath']]
                try:
                    output = _applypatchhelper(shellcmd, patch, force, reverse, run)
                except CmdError:
                    # Fall back to patch
                    output = PatchTree._applypatch(self, patch, force, reverse, run)
                # Add all files
                shellcmd = ["git", "add", "-f", "-A", "."]
                output += runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
                # Exclude the patches directory
                shellcmd = ["git", "reset", "HEAD", self.patchdir]
                output += runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
                # Commit the result
                (tmpfile, shellcmd) = self.prepareCommit(patch['file'])
                try:
                    shellcmd.insert(0, patchfilevar)
                    output += runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
                finally:
                    os.remove(tmpfile)
                return output
        finally:
            shutil.rmtree(hooks_dir)
            if os.path.lexists(hooks_dir_backup):
                shutil.move(hooks_dir_backup, hooks_dir)
Example #32
0
def patch_wheel(whl_path, extracted=False):
    """Patch a wheel in a manner similar to auditwheel.

    If extracted is False, whl_path must be the path to a .whl file, and this
    file is replaced with a fixed version. If extracted is True, then whl_path
    must be a directory containing the extracted contents of the wheel to patch,
    and the contents of the directory are replaced with the contents of a
    patched version (the contents are not zipped up).

    This is necessary for packaging the dependent shared libraries in a way that
    avoids dependency hell and ensures that Python packages are self-contained
    and isolated. There are a few reasons for patching the libraries.

    1. We need to be able to load the libraries no matter where they are
    installed.
    2. We don't want a system library with the same name to interfere with
    loading.
    3. We don't want two Python packages containing libraries with the same name
    to interfere with each other.

    To patch the wheel, we rename the iKnow engine and ICU shared libraries by
    adding a hash to the file names, and then we re-link them to the newly
    renamed libraries. This way, we can guarantee that the correct library is
    loaded when iknowpy is imported."""

    print('repairing wheel')

    # extract wheel
    if extracted:
        extracted_dir = whl_path
    else:
        extracted_dir = f'dist{os.sep}temp'
        rmtree(extracted_dir)
        os.mkdir(extracted_dir)
        extract_wheel(whl_path, extracted_dir)

    # copy ICU and iKnow engine library files
    iculib_map = {
    }  # name of symlink to ICU library -> name of actual ICU library file
    repair_lib_dir = os.path.join(extracted_dir, 'iknowpy')
    for lib_path in iculib_paths:
        if os.path.islink(lib_path):
            iculib_map[os.path.basename(lib_path)] = os.path.basename(
                os.path.realpath(lib_path))
        else:
            shutil.copy2(lib_path, repair_lib_dir)
    for lib_path in enginelib_paths:
        shutil.copy2(lib_path, repair_lib_dir)

    # copy extra library files
    for lib_name in extra_libs:
        lib_path = ctypes.util.find_library(lib_name)
        if lib_path is None:
            raise FileNotFoundError(f'Unable to find library {lib_name}')
        shutil.copy2(lib_path, repair_lib_dir)

    # create list of libraries to repair
    module_pattern = os.path.join(repair_lib_dir, module_name_pattern)
    repair_lib_paths = glob.glob(module_pattern)
    if not repair_lib_paths:
        raise BuildError(
            f'Unable to find module matching pattern {module_pattern!r}')
    repair_lib_paths.extend(
        glob.iglob(os.path.join(repair_lib_dir, iculibs_name_pattern)))
    repair_lib_paths.extend(
        glob.iglob(os.path.join(repair_lib_dir, enginelibs_name_pattern)))

    # repair libraries by setting dependency paths and renaming them
    patcher = PatchLib()
    lib_rename = {}  # dict from old lib name to new lib name
    for lib_path in repair_lib_paths:
        lib_name = os.path.basename(lib_path)
        if lib_name.startswith('engine.'):  # don't rename main module file
            lib_rename[lib_name] = lib_name
        else:
            lib_name_split = lib_name.split('.')
            with open(lib_path, 'rb') as lib_file:
                lib_name_split[0] = f'{lib_name_split[0]}-{hashfile(lib_file)}'
            lib_name_new = '.'.join(lib_name_split)
            lib_rename[lib_name] = lib_name_new
    for lib_name in iculib_map:
        # replace dependency on symlink to dependency on actual library file
        lib_rename[lib_name] = lib_rename[iculib_map[lib_name]]

    os.makedirs(CACHE_DIR, exist_ok=True)
    for lib_path in repair_lib_paths:
        lib_dir, lib_name = os.path.split(lib_path)
        print(
            f'repairing {lib_path} -> {os.path.join(lib_dir, lib_rename[lib_name])}',
            end='')
        if not lib_name.startswith('engine.') and os.path.isfile(
                os.path.join('dist/cache', lib_rename[lib_name])):
            # copy patched library from cache
            os.remove(lib_path)
            shutil.copy2(os.path.join(CACHE_DIR, lib_rename[lib_name]),
                         lib_dir)
            print(' (cached)')
        else:
            dep_libs = patcher.getneeded(lib_path)
            patcher.setname(lib_path, lib_rename[lib_name])
            if dep_libs:
                if sys.platform == 'linux':
                    patcher.setrpath(lib_path)
                patcher.replaceneeded(lib_path, dep_libs, lib_rename)
            os.rename(lib_path, os.path.join(lib_dir, lib_rename[lib_name]))
            if not lib_name.startswith('engine.'):
                # copy patched library into cache and remove old entries
                for old_entry in glob.iglob(
                        os.path.join(CACHE_DIR,
                                     lib_name[:lib_name.index('.')] + '-*')):
                    remove(old_entry)
                shutil.copy2(os.path.join(lib_dir, lib_rename[lib_name]),
                             CACHE_DIR)
            print()

    # update record file, which tracks wheel contents and their checksums
    update_wheel_record(extracted_dir)

    if not extracted:
        # repackage wheel
        repackage_wheel(whl_path, extracted_dir)

        # remove extracted files
        print(f'removing {extracted_dir}')
        rmtree(extracted_dir)
Example #33
0
    def run(self):
        metadata = None  # metadata from .dist-info/WHEEL file
        python_tags = []
        abi_tags = []
        platform_tag = None
        extracted_dirs = []
        tmp_dir_base = f'dist{os.sep}temp'
        rmtree(tmp_dir_base)

        # extract wheels
        whl_paths = glob.glob(f'dist/iknowpy-{version}-*.whl')
        if len(whl_paths) < 2:
            raise BuildError('Fewer than 2 wheels were found in dist/')
        if len(set(map(lambda s: s[s.rindex('-') + 1:], whl_paths))) > 1:
            raise BuildError(
                'Multiple platform tags were found in the wheels in dist/. '
                'Only wheels with the same platform tag can be merged.')
        for whl_path in whl_paths:
            whl_name = os.path.basename(whl_path)
            whl_name = whl_name[:-len('.whl')]  # strip off the extension
            whl_name_split = whl_name.split('-')
            # whl_name_split has the form [name, version, python_tag, abi_tag, platform_tag]
            python_tags.append(whl_name_split[2])
            abi_tags.append(whl_name_split[3])
            platform_tag = whl_name_split[4]
            extracted_dir = os.path.join(tmp_dir_base, whl_name)
            extracted_dirs.append(extracted_dir)
            extract_wheel(whl_path, extracted_dir)

            # verify that original wheels were created with --no-dependencies flag
            if glob.glob(
                    os.path.join(extracted_dir, 'iknowpy',
                                 enginelibs_name_pattern)):
                raise BuildError(
                    f'{whl_path} was not built with --no-dependencies and cannot be merged'
                )

            # get the wheel metadata
            metadata_filepath = os.path.join(extracted_dir,
                                             f'iknowpy-{version}.dist-info',
                                             'WHEEL')
            if metadata is None:
                metadata = extract_metadata(metadata_filepath)
            else:
                merge_metadata(metadata, extract_metadata(metadata_filepath))

        # Ensure that all wheels have identical metadata with the exception of
        # the Tag key, which is expected to be different between wheels that
        # target different Python versions. This way, we don't merge wheels that
        # might be incompatible with each other.
        for key, values in metadata.items():
            if key != 'Tag' and len(values) > 1:
                raise BuildError(
                    f'Wheels have conflicting metadata for key {key!r} and cannot be merged. Conflicting values are {values!r}.'
                )

        python_tags.sort()
        abi_tags.sort()

        # copy all engine modules into extracted contents of first wheel
        for extracted_dir in extracted_dirs[1:]:
            for module_path in glob.iglob(
                    os.path.join(extracted_dir, 'iknowpy',
                                 module_name_pattern)):
                print(
                    f'copying {module_path} -> {os.path.join(extracted_dirs[0], "iknowpy", os.path.basename(module_path))}'
                )
                shutil.copy2(module_path,
                             os.path.join(extracted_dirs[0], 'iknowpy'))

        # update metadata
        metadata_filepath = os.path.join(extracted_dirs[0],
                                         f'iknowpy-{version}.dist-info',
                                         'WHEEL')
        print(f'updating wheel metadata file {metadata_filepath}')
        with open(metadata_filepath, 'w') as metadata_file:
            for key, values in metadata.items():
                for value in sorted(values):
                    metadata_file.write(f'{key}: {value}\n')

        # fix up the wheel
        if no_dependencies:
            update_wheel_record(extracted_dirs[0])
        else:
            patch_wheel(extracted_dirs[0], True)

        # create the merged wheel
        merged_whl_name = f'iknowpy-{version}-{".".join(python_tags)}-{".".join(abi_tags)}-{platform_tag}.whl'
        merged_whl_path = os.path.join('dist', 'merged', merged_whl_name)
        print(f'creating merged wheel {merged_whl_path}')
        repackage_wheel(merged_whl_path, extracted_dirs[0])

        # delete temp files
        rmtree(tmp_dir_base)
Example #34
0
    no_dependencies = True

with open('../../README.md', encoding='utf-8') as readme_file:
    long_description = readme_file.read()
    # Strip off badges. They belong in the GitHub version of the README file but
    # are less appropriate on PyPI.
    long_description = long_description[long_description.index('# iKnow\n'):]

dependent_lib_names = None
try:
    if fast_install:
        # copy dependent libraries into ./iknowpy
        dependent_lib_names = []
        for lib_path in itertools.chain(iculib_paths, enginelib_paths,
                                        extralib_paths):
            shutil.copy2(lib_path, 'iknowpy')
            dependent_lib_names.append(os.path.basename(lib_path))
        package_data = {'iknowpy': dependent_lib_names}
    else:
        # include MIT license in distribution
        shutil.copy2('../../LICENSE', '.')

        # include ICU license in distribution
        icu_license_found = False
        for root, _, files in os.walk(icudir):
            for filename in files:
                if filename == 'LICENSE':
                    icu_license_found = True
                    shutil.copy2(os.path.join(root, filename), 'LICENSE_ICU')
                    break
            if icu_license_found:
Example #35
0
def copytree(src, dst, symlinks=False, ignore=None):
    """Recursively copy a directory tree using copy2().

    The destination directory must not already exist.
    If exception(s) occur, an Error is raised with a list of reasons.

    If the optional symlinks flag is true, symbolic links in the
    source tree result in symbolic links in the destination tree; if
    it is false, the contents of the files pointed to by symbolic
    links are copied.

    The optional ignore argument is a callable. If given, it
    is called with the `src` parameter, which is the directory
    being visited by copytree(), and `names` which is the list of
    `src` contents, as returned by os.listdir():

        callable(src, names) -> ignored_names

    Since copytree() is called recursively, the callable will be
    called once for each directory that is copied. It returns a
    list of names relative to the `src` directory that should
    not be copied.

    XXX Consider this example code rather than the ultimate tool.

    """
    names = os.listdir(src)
    if ignore is not None:
        ignored_names = ignore(src, names)
    else:
        ignored_names = set()

    mkdirs(dst)
    errors = []
    for name in names:
        if name in ignored_names:
            continue
        srcname = os.path.join(src, name)
        dstname = os.path.join(dst, name)
        try:
            if symlinks and os.path.islink(srcname):
                linkto = os.readlink(srcname)
                os.symlink(linkto, dstname)
            elif os.path.isdir(srcname):
                copytree(srcname, dstname, symlinks, ignore)
            else:
                copy2(srcname, dstname)
            # XXX What about devices, sockets etc.?
        except (IOError, os.error) as why:
            errors.append((srcname, dstname, str(why)))
        # catch the Error from the recursive copytree so that we can
        # continue with other files
        except Error as err:
            errors.extend(err.args[0])
    try:
        copystat(src, dst)
    except OSError as why:
        if WindowsError is not None and isinstance(why, WindowsError):
            # Copying file access times may fail on Windows
            pass
        else:
            errors.extend((src, dst, str(why)))
    if errors:
        raise Error(errors)
Example #36
0
    def writeMesh(self):
        """ Convert or copy mesh files """
        if self.mesh_obj.Proxy.Type == "Fem::FemMeshGmsh" and not(self.meshConvertedTo2D):  # GMSH
            # Convert GMSH created UNV file to OpenFoam
            print("Writing GMSH")
            unvMeshFile = self.case_folder + os.path.sep + self.solver_obj.InputCaseName + u".unv"
            self.mesh_generated = CfdTools.write_unv_mesh(self.mesh_obj, self.bc_group, unvMeshFile)
            # FreeCAD always stores the CAD geometry in mm, while FOAM by default uses SI units. This is independent
            # of the user selected unit preferences.
            self.setupMesh(unvMeshFile, scale = 0.001)
        elif self.mesh_obj.Proxy.Type == "Fem::FemMeshGmsh" and self.meshConvertedTo2D:
            import tempfile
            tmpdir = tempfile.gettempdir()
            meshCaseDir = os.path.join(tmpdir, "meshCase")
            constantDir = os.path.join(meshCaseDir, 'constant')
            systemDir = os.path.join(meshCaseDir, 'system')
            polyMeshDir = os.path.join(constantDir, 'polyMesh')
            unvMeshFile = meshCaseDir + os.path.sep + self.solver_obj.InputCaseName + u".unv"

            CfdTools.copyFilesRec(polyMeshDir, os.path.join(self.case_folder, 'constant', 'polyMesh'))
            shutil.copy2(os.path.join(systemDir, 'extrudeMeshDict'), os.path.join(self.case_folder, 'system'))
            shutil.copy2(os.path.join(meshCaseDir, 'ConvertMeshTo2D'), self.case_folder)
            shutil.copy2(os.path.join(meshCaseDir, unvMeshFile), self.case_folder)
            shutil.copy2(os.path.join(meshCaseDir, 'log.extrudeMesh'), self.case_folder)
            shutil.copy2(os.path.join(meshCaseDir, 'log.ideasUnvToFoam'), self.case_folder)
            shutil.copy2(os.path.join(meshCaseDir, 'log.transformPoints'), self.case_folder)
        elif self.mesh_obj.Proxy.Type == "CfdMeshCart":  # Cut-cell Cartesian
            import CfdCartTools
            ## Move Cartesian mesh files from temporary mesh directory to case directory
            if self.mesh_obj.MeshUtility == "cfMesh":
                print("Writing Cartesian mesh\n")
                #import CfdCartTools
                self.cart_mesh = CfdCartTools.CfdCartTools(self.mesh_obj)
                cart_mesh = self.cart_mesh
                # cart_mesh.get_tmp_file_paths("cfMesh")  # Update tmp file locations
                cart_mesh.get_tmp_file_paths()  # Update tmp file locations
                CfdTools.copyFilesRec(cart_mesh.polyMeshDir, os.path.join(self.case_folder, 'constant', 'polyMesh'))
                CfdTools.copyFilesRec(cart_mesh.triSurfaceDir, os.path.join(self.case_folder, 'constant', 'triSurface'))
                # shutil.copy2(cart_mesh.temp_file_meshDict, os.path.join(self.case_folder,'system'))
                shutil.copy2(os.path.join(cart_mesh.meshCaseDir, 'system', 'meshDict'),
                             os.path.join(self.case_folder,'system'))
                shutil.copy2(os.path.join(cart_mesh.meshCaseDir,'Allmesh'),self.case_folder)
                shutil.copy2(os.path.join(cart_mesh.meshCaseDir,'log.cartesianMesh'),self.case_folder)
                shutil.copy2(os.path.join(cart_mesh.meshCaseDir,'log.surfaceFeatureEdges'),self.case_folder)

            elif self.mesh_obj.MeshUtility == "snappyHexMesh":
                print("Writing snappyHexMesh generated Cartesian mesh\n")
                self.cart_mesh = CfdCartTools.CfdCartTools(self.mesh_obj)
                cart_mesh = self.cart_mesh
                # cart_mesh.get_tmp_file_paths("snappyHexMesh")  # Update tmp file locations
                cart_mesh.get_tmp_file_paths()  # Update tmp file locations
                CfdTools.copyFilesRec(cart_mesh.polyMeshDir, os.path.join(self.case_folder,'constant','polyMesh'))
                CfdTools.copyFilesRec(cart_mesh.triSurfaceDir, os.path.join(self.case_folder,'constant','triSurface'))
                # shutil.copy2(cart_mesh.temp_file_blockMeshDict, os.path.join(self.case_folder,'system'))
                # shutil.copy2(cart_mesh.temp_file_snappyMeshDict, os.path.join(self.case_folder,'system'))
                # shutil.copy2(cart_mesh.temp_file_surfaceFeatureExtractDict, os.path.join(self.case_folder,'system'))
                shutil.copy2(os.path.join(cart_mesh.meshCaseDir, 'system', 'blockMeshDict'),
                             os.path.join(self.case_folder,'system'))
                shutil.copy2(os.path.join(cart_mesh.meshCaseDir, 'system', 'snappyHexMeshDict'),
                             os.path.join(self.case_folder,'system'))
                shutil.copy2(os.path.join(cart_mesh.meshCaseDir, 'system', 'surfaceFeatureExtractDict'),
                             os.path.join(self.case_folder,'system'))
                shutil.copy2(os.path.join(cart_mesh.meshCaseDir, 'Allmesh'), self.case_folder)
                shutil.copy2(os.path.join(cart_mesh.meshCaseDir, 'log.blockMesh'), self.case_folder)
                shutil.copy2(os.path.join(cart_mesh.meshCaseDir, 'log.surfaceFeatureExtract'), self.case_folder)
                shutil.copy2(os.path.join(cart_mesh.meshCaseDir, 'log.snappyHexMesh'), self.case_folder)

            if self.meshConvertedTo2D:
                shutil.copy2(os.path.join(os.path.join(cart_mesh.meshCaseDir,'system'),'extrudeMeshDict'), 
                             os.path.join(self.case_folder, 'system'))
                shutil.copy2(os.path.join(cart_mesh.meshCaseDir, 'ConvertMeshTo2D'), self.case_folder)
                shutil.copy2(os.path.join(cart_mesh.meshCaseDir, 'log.extrudeMesh'), self.case_folder)
        else:
            raise RuntimeError("Unrecognised mesh type")
Example #37
0
                                         "").replace("debug =TRUE,", "")
        file_copy.extend(txtfile(line))
        if "<- bugs(" in line:
            var = line.split()[0].replace(".", "")
        if "working.directory = getwd()" in line:
            code += "coda.data <- as.matrix(read.bugs(\"CODAchain1.txt\"))\nparam_file <- c()\nfor (out_param in colnames(as.matrix(coda.data))) {{\n    param_file <- cbind(param_file, paste(gsub(\"\\\\.\", \"_\", out_param), \",[\", paste(coda.data[, out_param], collapse = \" \"), \"],\", out$summary[,\"Rhat\"][out_param]))\n}}\nwrite.table(param_file, file = \"bugs_{0}.out\", row.names=FALSE, col.nam=FALSE, sep=\"\\n\", quote = FALSE)\n\n".format(
                var)

    else:
        if code != "":
            try:
                os.mkdir("bugs_bpa/{0}_{1}".format(outputBase, chapter))
            except:
                pass
            dest = open(
                "bugs_bpa/{0}_{1}/{0}_{1}R".format(outputBase, chapter), 'w')
            code = "library(R2OpenBUGS)\nlibrary(coda)" + code
            dest.write(code)
            code = ""
            dest.close()
            for f in file_copy:
                try:
                    shutil.copy2(
                        f, "bugs_bpa/{0}_{1}/".format(outputBase, chapter))
                except:
                    pass
            file_copy = []
        chapter = chapter_new
    #if (count <= 0):
    #    break
Example #38
0
def run_cfour(name, **kwargs):
    """Function that prepares environment and input files
    for a calculation calling Stanton and Gauss's CFOUR code.
    Also processes results back into Psi4 format.

    This function is not called directly but is instead called by
    :py:func:`~driver.energy` or :py:func:`~driver.optimize` when a Cfour
    method is requested (through *name* argument). In order to function
    correctly, the Cfour executable ``xcfour`` must be present in
    :envvar:`PATH` or :envvar:`PSIPATH`.

    .. hlist::
       :columns: 1

       * Many :ref:`PSI Variables <apdx:cfour_psivar>` extracted from the Cfour output
       * Python dictionary of associated file constants accessible as ``P4C4_INFO['zmat']``, ``P4C4_INFO['output']``, ``P4C4_INFO['grd']``, *etc.*


    :type name: string
    :param name: ``'c4-scf'`` || ``'c4-ccsd(t)'`` || ``'cfour'`` || etc.

        First argument, usually unlabeled. Indicates the computational
        method to be applied to the system.

    :type keep: :ref:`boolean <op_py_boolean>`
    :param keep: ``'on'`` || |dl| ``'off'`` |dr|

        Indicates whether to delete the Cfour scratch directory upon
        completion of the Cfour job.

    :type path: string
    :param path:

        Indicates path to Cfour scratch directory (with respect to Psi4
        scratch directory). Otherwise, the default is a subdirectory
        within the Psi4 scratch directory.

        If specified, GENBAS and/or ZMAT within will be used.

    :type genbas: string
    :param genbas:

        Indicates that contents should be used for GENBAS file.

    GENBAS is a complicated topic. It is quite unnecessary if the
    molecule is from a molecule {...} block and basis is set through
    |Psifours| BASIS keyword. In that case, a GENBAS is written from
    LibMints and all is well. Otherwise, a GENBAS is looked for in
    the usual places: PSIPATH, PATH, PSIDATADIR/basis. If path kwarg is
    specified, also looks there preferentially for a GENBAS. Can
    also specify GENBAS within an input file through a string and
    setting the genbas kwarg. Note that due to the input parser's
    aggression, blank lines need to be replaced by the text blankline.

    """
    lowername = name.lower()
    internal_p4c4_info = {}
    return_wfn = kwargs.pop('return_wfn', False)

    # Make sure the molecule the user provided is the active one
    molecule = kwargs.pop('molecule', core.get_active_molecule())
    molecule.update_geometry()

    optstash = p4util.OptionsState(
            ['CFOUR', 'TRANSLATE_PSI4'])

    # Determine calling function and hence dertype
    calledby = inspect.stack()[1][3]
    dertype = ['energy', 'gradient', 'hessian'].index(calledby)
    #print('I am %s called by %s called by %s.\n' %
    #    (inspect.stack()[0][3], inspect.stack()[1][3], inspect.stack()[2][3]))

    # Save submission directory
    current_directory = os.getcwd()

    # Move into job scratch directory
    psioh = core.IOManager.shared_object()
    psio = core.IO.shared_object()
    os.chdir(psioh.get_default_path())

    # Construct and move into cfour subdirectory of job scratch directory
    cfour_tmpdir = kwargs['path'] if 'path' in kwargs else \
        'psi.' + str(os.getpid()) + '.' + psio.get_default_namespace() + \
        '.cfour.' + str(uuid.uuid4())[:8]
    if not os.path.exists(cfour_tmpdir):
        os.mkdir(cfour_tmpdir)
    os.chdir(cfour_tmpdir)

    # Find environment by merging PSIPATH and PATH environment variables
    lenv = {
        'PATH': ':'.join([os.path.abspath(x) for x in os.environ.get('PSIPATH', '').split(':') if x != '']) + \
                ':' + os.environ.get('PATH') + \
                ':' + core.get_datadir() + '/basis',
        'GENBAS_PATH': core.get_datadir() + '/basis',
        'CFOUR_NUM_CORES': os.environ.get('CFOUR_NUM_CORES'),
        'MKL_NUM_THREADS':  os.environ.get('MKL_NUM_THREADS'),
        'OMP_NUM_THREADS':  os.environ.get('OMP_NUM_THREADS'),
        'LD_LIBRARY_PATH': os.environ.get('LD_LIBRARY_PATH')
        }

    if 'path' in kwargs:
        lenv['PATH'] = kwargs['path'] + ':' + lenv['PATH']
    #   Filter out None values as subprocess will fault on them
    lenv = {k: v for k, v in lenv.items() if v is not None}

    # Load the GENBAS file
    genbas_path = qcdb.search_file('GENBAS', lenv['GENBAS_PATH'])
    if genbas_path:
        try:
            shutil.copy2(genbas_path, psioh.get_default_path() + cfour_tmpdir)
        except shutil.Error:  # should only fail if src and dest equivalent
            pass
        core.print_out("\n  GENBAS loaded from %s\n" % (genbas_path))
        core.print_out("  CFOUR to be run from %s\n" % (psioh.get_default_path() + cfour_tmpdir))
    else:
        message = """
  GENBAS file for CFOUR interface not found. Either:
  [1] Supply a GENBAS by placing it in PATH or PSIPATH
      [1a] Use cfour {} block with molecule and basis directives.
      [1b] Use molecule {} block and CFOUR_BASIS keyword.
  [2] Allow Psi4's internal basis sets to convert to GENBAS
      [2a] Use molecule {} block and BASIS keyword.

"""
        core.print_out(message)
        core.print_out('  Search path that was tried:\n')
        core.print_out(lenv['PATH'].replace(':', ', '))

    # Generate the ZMAT input file in scratch
    if 'path' in kwargs and os.path.isfile('ZMAT'):
        core.print_out("  ZMAT loaded from %s\n" % (psioh.get_default_path() + kwargs['path'] + '/ZMAT'))
    else:
        with open('ZMAT', 'w') as cfour_infile:
            cfour_infile.write(write_zmat(lowername, dertype, molecule))

    internal_p4c4_info['zmat'] = open('ZMAT', 'r').read()
    #core.print_out('\n====== Begin ZMAT input for CFOUR ======\n')
    #core.print_out(open('ZMAT', 'r').read())
    #core.print_out('======= End ZMAT input for CFOUR =======\n\n')
    #print('\n====== Begin ZMAT input for CFOUR ======')
    #print(open('ZMAT', 'r').read())
    #print('======= End ZMAT input for CFOUR =======\n')

    if 'genbas' in kwargs:
        with open('GENBAS', 'w') as cfour_basfile:
            cfour_basfile.write(kwargs['genbas'].replace('\nblankline\n', '\n\n'))
        core.print_out('  GENBAS loaded from kwargs string\n')

    # Close psi4 output file and reopen with filehandle
    print('output in', current_directory + '/' + core.outfile_name())
    pathfill = '' if os.path.isabs(core.outfile_name()) else current_directory + os.path.sep

    # Handle threading
    #   OMP_NUM_THREADS from env is in lenv from above
    #   threads from psi4 -n (core.get_num_threads()) is ignored
    #   CFOUR_OMP_NUM_THREADS psi4 option takes precedence, handled below
    if core.has_option_changed('CFOUR', 'CFOUR_OMP_NUM_THREADS') == True:
        lenv['OMP_NUM_THREADS'] = str(core.get_option('CFOUR', 'CFOUR_OMP_NUM_THREADS'))

    #print("""\n\n<<<<<  RUNNING CFOUR ...  >>>>>\n\n""")
    # Call executable xcfour, directing cfour output to the psi4 output file
    cfour_executable = kwargs['c4exec'] if 'c4exec' in kwargs else 'xcfour'
    try:
        retcode = subprocess.Popen([cfour_executable], bufsize=0, stdout=subprocess.PIPE, env=lenv)
    except OSError as e:
        sys.stderr.write('Program %s not found in path or execution failed: %s\n' % (cfour_executable, e.strerror))
        message = ('Program %s not found in path or execution failed: %s\n' % (cfour_executable, e.strerror))
        raise ValidationError(message)

    c4out = ''
    while True:
        data = retcode.stdout.readline()
        data = data.decode('utf-8')
        if not data:
            break
        core.print_out(data)
        c4out += data
    internal_p4c4_info['output'] = c4out

    c4files = {}
    core.print_out('\n')
    for item in ['GRD', 'FCMFINAL', 'DIPOL']:
        try:
            with open(psioh.get_default_path() + cfour_tmpdir + '/' + item, 'r') as handle:
                c4files[item] = handle.read()
                core.print_out('  CFOUR scratch file %s has been read\n' % (item))
                core.print_out('%s\n' % c4files[item])
                internal_p4c4_info[item.lower()] = c4files[item]
        except IOError:
            pass
    core.print_out('\n')

    if molecule.name() == 'blank_molecule_psi4_yo':
        qcdbmolecule = None
    else:
        molecule.update_geometry()
        qcdbmolecule = qcdb.Molecule(molecule.create_psi4_string_from_molecule())
        qcdbmolecule.update_geometry()

    # c4mol, if it exists, is dinky, just a clue to geometry of cfour results
    psivar, c4grad, c4mol = qcdb.cfour.harvest(qcdbmolecule, c4out, **c4files)

    # Absorb results into psi4 data structures
    for key in psivar.keys():
        core.set_variable(key.upper(), float(psivar[key]))

    if qcdbmolecule is None and c4mol is not None:
        molecule = geometry(c4mol.create_psi4_string_from_molecule(), name='blank_molecule_psi4_yo')
        molecule.update_geometry()
        # This case arises when no Molecule going into calc (cfour {} block) but want
        #   to know the orientation at which grad, properties, etc. are returned (c4mol).
        #   c4mol is dinky, w/o chg, mult, dummies and retains name
        #   blank_molecule_psi4_yo so as to not interfere with future cfour {} blocks

    if c4grad is not None:
        mat = core.Matrix.from_list(c4grad)
        core.set_gradient(mat)

        #print '    <<<   [3] C4-GRD-GRAD   >>>'
        #mat.print()

#    exit(1)

    # # Things needed core.so module to do
    # collect c4out string
    # read GRD
    # read FCMFINAL
    # see if theres an active molecule

    # # Things delegatable to qcdb
    # parsing c4out
    # reading GRD and FCMFINAL strings
    # reconciling p4 and c4 molecules (orient)
# reconciling c4out and GRD and FCMFINAL results
# transforming frame of results back to p4

    # # Things run_cfour needs to have back
    # psivar
# qcdb.Molecule of c4?
# coordinates?
# gradient in p4 frame





#    # Process the cfour output
#    psivar, c4coord, c4grad = qcdb.cfour.cfour_harvest(c4out)
#    for key in psivar.keys():
#        core.set_variable(key.upper(), float(psivar[key]))
#
#    # Awful Hack - Go Away TODO
#    if c4grad:
#        molecule = core.get_active_molecule()
#        molecule.update_geometry()
#
#        if molecule.name() == 'blank_molecule_psi4_yo':
#            p4grad = c4grad
#            p4coord = c4coord
#        else:
#            qcdbmolecule = qcdb.Molecule(molecule.create_psi4_string_from_molecule())
#            #p4grad = qcdbmolecule.deorient_array_from_cfour(c4coord, c4grad)
#            #p4coord = qcdbmolecule.deorient_array_from_cfour(c4coord, c4coord)
#
#            with open(psioh.get_default_path() + cfour_tmpdir + '/GRD', 'r') as cfour_grdfile:
#                c4outgrd = cfour_grdfile.read()
#            print('GRD\n',c4outgrd)
#            c4coordGRD, c4gradGRD = qcdb.cfour.cfour_harvest_files(qcdbmolecule, grd=c4outgrd)
#
#        p4mat = core.Matrix.from_list(p4grad)
#        core.set_gradient(p4mat)

#    print('    <<<  P4 PSIVAR  >>>')
#    for item in psivar:
#        print('       %30s %16.8f' % (item, psivar[item]))
    #print('    <<<  P4 COORD   >>>')
    #for item in p4coord:
    #    print('       %16.8f %16.8f %16.8f' % (item[0], item[1], item[2]))
#    print('    <<<   P4 GRAD   >>>')
#    for item in c4grad:
#        print('       %16.8f %16.8f %16.8f' % (item[0], item[1], item[2]))














    # Clean up cfour scratch directory unless user instructs otherwise
    keep = yes.match(str(kwargs['keep'])) if 'keep' in kwargs else False
    os.chdir('..')
    try:
        if keep or ('path' in kwargs):
            core.print_out('\n  CFOUR scratch files have been kept in %s\n' % (psioh.get_default_path() + cfour_tmpdir))
        else:
            shutil.rmtree(cfour_tmpdir)
    except OSError as e:
        print('Unable to remove CFOUR temporary directory %s' % e, file=sys.stderr)
        exit(1)

    # Return to submission directory and reopen output file
    os.chdir(current_directory)

    core.print_out('\n')
    p4util.banner(' Cfour %s %s Results ' % (name.lower(), calledby.capitalize()))
    core.print_variables()
    if c4grad is not None:
        core.get_gradient().print_out()

    core.print_out('\n')
    p4util.banner(' Cfour %s %s Results ' % (name.lower(), calledby.capitalize()))
    core.print_variables()
    if c4grad is not None:
        core.get_gradient().print_out()

    # Quit if Cfour threw error
    if core.variable('CFOUR ERROR CODE'):
        raise ValidationError("""Cfour exited abnormally.""")

    P4C4_INFO.clear()
    P4C4_INFO.update(internal_p4c4_info)

    optstash.restore()

    # new skeleton wavefunction w/mol, highest-SCF basis (just to choose one), & not energy
    #   Feb 2017 hack. Could get proper basis in skel wfn even if not through p4 basis kw
    gobas = core.get_global_option('BASIS') if core.get_global_option('BASIS') else 'sto-3g'
    basis = core.BasisSet.build(molecule, "ORBITAL", gobas)
    if basis.has_ECP():
        raise ValidationError("""ECPs not hooked up for Cfour""")
    wfn = core.Wavefunction(molecule, basis)

    optstash.restore()

    if dertype == 0:
        finalquantity = psivar['CURRENT ENERGY']
    elif dertype == 1:
        finalquantity = core.get_gradient()
        wfn.set_gradient(finalquantity)
        if finalquantity.rows(0) < 20:
            core.print_out('CURRENT GRADIENT')
            finalquantity.print_out()
    elif dertype == 2:
        pass
        #finalquantity = finalhessian
        #wfn.set_hessian(finalquantity)
        #if finalquantity.rows(0) < 20:
        #    core.print_out('CURRENT HESSIAN')
        #    finalquantity.print_out()

    return wfn
Example #39
0
 def testDoesntMatchAfterCopy2ThenModifyStats(self):
     shutil.copy2(self.filename_a, self.filename_b)
     os.utime(self.filename_a, (20, 20))
     self.assertFalse(
         android_profiling_helper._FileMetadataMatches(
             self.filename_a, self.filename_b))
cv_score = accuracy_score(train_y, train_p)

print
print("CV Accuracy: %.5f +- %.5f" % (mae_mean, mae_std))
print("CV RES Accuracy: %.5f" % cv_score)

name = "%s-%s-%.5f" % (datetime.datetime.now().strftime('%Y%m%d-%H%M'), args.preset, cv_score)

print()
print("Saving predictions... (%s)" % name)
print()
print()

for part, pred in [('train', train_p), ('test-foldavg', test_foldavg_p), ('test-fulltrain', test_fulltrain_p)]:
    pred.rename('Loan_Status', inplace=True)
    pred.index.rename('Loan_ID', inplace=True)
    pred.to_csv('preds/%s-%s.csv' % (name, part), header=True)

copy2(os.path.realpath(__file__), os.path.join("preds", "%s-code.py" % name))

df = pd.DataFrame(columns=["model","CV"])
df.loc[len(df)] = ["'" + name + "',", cv_score]
import os
# if file does not exist write header
if not os.path.isfile('results/models.csv'):
   df.to_csv('results/models.csv',index_label=None)
else: # else it exists so append without writing the header
    df.to_csv('results/models.csv',mode = 'a',header=False,index_label=None)

print("Done.")
Example #41
0
def fetchJpgsAndMp4s(traj, outdir):
    archdir = os.getenv('ARCHDIR')
    if len(archdir) < 5:
        archdir = '/home/ec2-user/ukmon-shared/archive'

    print('getting camera details file')
    cinfo = cdet.SiteInfo()

    for obs in traj.observations:
        statid = obs.station_id
        fldr = cinfo.getFolder(statid)
        print(statid, fldr)
        evtdate = jd2Date(obs.jdt_ref, dt_obj=True)

        print('station {} event {} '.format(statid,
                                            evtdate.strftime('%Y%m%d-%H%M%S')))
        # if the event is after midnight the folder will have the previous days date
        if evtdate.hour < 12:
            evtdate += timedelta(days=-1)
        yr = evtdate.year
        ym = evtdate.year * 100 + evtdate.month
        ymd = ym * 100 + evtdate.day

        print('getting jpgs and mp4s')
        thispth = '{:s}/{:04d}/{:06d}/{:08d}/'.format(fldr, yr, ym, ymd)
        srcpath = os.path.join(archdir, thispth)
        print(thispth)
        flist = glob.glob1(srcpath, 'FF*.jpg')
        srcfil = None
        for fil in flist:
            spls = fil.split('_')
            fdt = datetime.strptime(spls[2] + '_' + spls[3], '%Y%m%d_%H%M%S')
            tdiff = (evtdate - fdt).seconds
            if tdiff > 0 and tdiff < 11:
                srcfil = fil
                break
        if srcfil is not None:
            srcfil = srcpath + srcfil
            shutil.copy2(srcfil, outdir)
            file_name, _ = os.path.splitext(srcfil)
            srcfil = file_name + '.mp4'
            try:
                shutil.copy2(srcfil, outdir)
            except FileNotFoundError:
                pass
        else:
            print('no jpgs in {}'.format(srcpath))

        print('R90 CSV, KML and FTPDetect file')
        flist = os.listdir(srcpath)
        for fil in flist:
            file_name, file_ext = os.path.splitext(fil)
            if ('FTPdetectinfo' in fil) and (file_ext == '.txt') and (
                    '_original' not in file_name
            ) and ('_uncal' not in file_name) and ('_backup' not in file_name):
                srcfil = srcpath + fil
                shutil.copy2(srcfil, outdir)
            elif file_ext == '.csv':
                srcfil = srcpath + fil
                shutil.copy2(srcfil, outdir)
            elif file_ext == '.kml':
                srcfil = srcpath + fil
                shutil.copy2(srcfil, outdir)
                kmldir = os.path.join(archdir, 'kmls')
                shutil.copy2(srcfil, kmldir)

    return
Example #42
0
    def __init__(self):
        self._logger = logging.getLogger(__name__)

        # Create config dir if it does not exist yet
        if not os.path.exists(jasperpath.CONFIG_PATH):
            try:
                os.makedirs(jasperpath.CONFIG_PATH)
            except OSError:
                self._logger.error("Could not create config dir: '%s'",
                                   jasperpath.CONFIG_PATH,
                                   exc_info=True)
                raise

        # Check if config dir is writable
        if not os.access(jasperpath.CONFIG_PATH, os.W_OK):
            self._logger.critical(
                "Config dir %s is not writable. Jasper " +
                "won't work correctly.", jasperpath.CONFIG_PATH)

        # FIXME: For backwards compatibility, move old config file to newly
        #        created config dir
        old_configfile = os.path.join(jasperpath.LIB_PATH, 'profile.yml')
        new_configfile = jasperpath.config('profile.yml')
        if os.path.exists(old_configfile):
            if os.path.exists(new_configfile):
                self._logger.warning(
                    "Deprecated profile file found: '%s'. " +
                    "Please remove it.", old_configfile)
            else:
                self._logger.warning(
                    "Deprecated profile file found: '%s'. " +
                    "Trying to copy it to new location '%s'.", old_configfile,
                    new_configfile)
                try:
                    shutil.copy2(old_configfile, new_configfile)
                except shutil.Error:
                    self._logger.error("Unable to copy config file. " +
                                       "Please copy it manually.",
                                       exc_info=True)
                    raise

        # Read config
        self._logger.debug("Trying to read config file: '%s'", new_configfile)
        try:
            with open(new_configfile, "r") as f:
                self.config = yaml.safe_load(f)
        except OSError:
            self._logger.error("Can't open config file: '%s'", new_configfile)
            raise

        try:
            stt_engine_slug = self.config['stt_engine']
        except KeyError:
            stt_engine_slug = 'sphinx'
            logger.warning(
                "stt_engine not specified in profile, defaulting " + "to '%s'",
                stt_engine_slug)
        stt_engine_class = stt.get_engine_by_slug(stt_engine_slug)

        try:
            slug = self.config['stt_passive_engine']
            stt_passive_engine_class = stt.get_engine_by_slug(slug)
        except KeyError:
            stt_passive_engine_class = stt_engine_class

        try:
            tts_engine_slug = self.config['tts_engine']
        except KeyError:
            tts_engine_slug = tts.get_default_engine_slug()
            logger.warning(
                "tts_engine not specified in profile, defaulting " + "to '%s'",
                tts_engine_slug)
        tts_engine_class = tts.get_engine_by_slug(tts_engine_slug)

        # Initialize Mic
        self.mic = Mic(tts_engine_class.get_instance(),
                       stt_passive_engine_class.get_passive_instance(),
                       stt_engine_class.get_active_instance())
Example #43
0
    def do_custom_build(self):
        # We're using a system freetype
        if not options.get('local_freetype'):
            return

        src_path = os.path.join(
            'build', 'freetype-{0}'.format(LOCAL_FREETYPE_VERSION))

        # We've already built freetype
        if sys.platform == 'win32':
            libfreetype = 'libfreetype.lib'
        else:
            libfreetype = 'libfreetype.a'

        # bailing because it is already built
        if os.path.isfile(os.path.join(
                src_path, 'objs', '.libs', libfreetype)):
            return

        # do we need to download / load the source from cache?
        if not os.path.exists(src_path):
            os.makedirs('build', exist_ok=True)

            url_fmts = [
                ('https://downloads.sourceforge.net/project/freetype'
                 '/freetype2/{version}/{tarball}'),
                ('https://download.savannah.gnu.org/releases/freetype'
                 '/{tarball}')
            ]
            tarball = 'freetype-{0}.tar.gz'.format(LOCAL_FREETYPE_VERSION)

            target_urls = [
                url_fmt.format(version=LOCAL_FREETYPE_VERSION,
                               tarball=tarball)
                for url_fmt in url_fmts]

            for tarball_url in target_urls:
                try:
                    tar_contents = download_or_cache(tarball_url,
                                                     LOCAL_FREETYPE_HASH)
                    break
                except Exception:
                    pass
            else:
                raise IOError("Failed to download FreeType.  Please download "
                              "one of {target_urls} and extract it into "
                              "{src_path} at the top-level of the source "
                              "repository".format(
                                  target_urls=target_urls, src_path=src_path))

            print("Extracting {}".format(tarball))
            # just to be sure
            tar_contents.seek(0)
            with tarfile.open(tarball, mode="r:gz",
                              fileobj=tar_contents) as tgz:
                tgz.extractall("build")

        print("Building freetype in {}".format(src_path))
        if sys.platform != 'win32':
            # compilation on all other platforms than windows
            env = {**os.environ,
                   "CFLAGS": "{} -fPIC".format(os.environ.get("CFLAGS", ""))}
            subprocess.check_call(
                ["./configure", "--with-zlib=no", "--with-bzip2=no",
                 "--with-png=no", "--with-harfbuzz=no"],
                env=env, cwd=src_path)
            subprocess.check_call(["make"], env=env, cwd=src_path)
        else:
            # compilation on windows
            shutil.rmtree(str(pathlib.Path(src_path, "objs")),
                          ignore_errors=True)
            FREETYPE_BUILD_CMD = r"""
call "%ProgramFiles%\Microsoft SDKs\Windows\v7.0\Bin\SetEnv.Cmd" ^
    /Release /{xXX} /xp
call "{vcvarsall}" {xXX}
set MSBUILD=C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
%MSBUILD% "builds\windows\{vc20xx}\freetype.sln" ^
    /t:Clean;Build /p:Configuration="Release";Platform={WinXX}
"""
            import distutils.msvc9compiler as msvc
            # Note: freetype has no build profile for 2014, so we don't bother...
            vc = 'vc2010'
            WinXX = 'x64' if platform.architecture()[0] == '64bit' else 'Win32'
            xXX = 'x64' if platform.architecture()[0] == '64bit' else 'x86'
            vcvarsall = msvc.find_vcvarsall(10.0)
            if vcvarsall is None:
                raise RuntimeError('Microsoft VS 2010 required')
            cmdfile = pathlib.Path("build/build_freetype.cmd")
            cmdfile.write_text(FREETYPE_BUILD_CMD.format(
                vc20xx=vc, WinXX=WinXX, xXX=xXX, vcvarsall=vcvarsall))
            subprocess.check_call([str(cmdfile.resolve())],
                                  shell=True, cwd=src_path)
            # Move to the corresponding Unix build path.
            pathlib.Path(src_path, "objs/.libs").mkdir()
            # Be robust against change of FreeType version.
            lib_path, = (pathlib.Path(src_path, "objs", vc, xXX)
                         .glob("freetype*.lib"))
            shutil.copy2(
                str(lib_path),
                str(pathlib.Path(src_path, "objs/.libs/libfreetype.lib")))
Example #44
0
 def testMatchesAfterCopy2(self):
     shutil.copy2(self.filename_a, self.filename_b)
     self.assertTrue(
         android_profiling_helper._FileMetadataMatches(
             self.filename_a, self.filename_b))
def handle_uncaught_exception_wx(t, v, tb):

    _log.debug('unhandled exception caught:', exc_info=(t, v, tb))

    if __handle_access_violation(t, v, tb):
        return

    if __handle_ctrl_c(t, v, tb):
        return

    if __handle_exceptions_on_shutdown(t, v, tb):
        return

    if __ignore_dead_objects_from_async(t, v, tb):
        return

    if __handle_import_error(t, v, tb):
        return

    if __handle_wxgtk_assertion(t, v, tb):
        return

    # other exceptions
    _cfg = gmCfgINI.gmCfgData()
    if _cfg.get(option='debug') is False:
        _log.error('enabling debug mode')
        _cfg.set_option(option='debug', value=True)
        root_logger = logging.getLogger()
        root_logger.setLevel(logging.DEBUG)
        _log.debug('unhandled exception caught:', exc_info=(t, v, tb))

    if __handle_lost_db_connection(t, v, tb):
        return

    gmLog2.log_stack_trace(None, t, v, tb)

    # only do this here or else we can invalidate the stack trace
    # by Windows throwing an exception ... |-(
    # careful: MSW does reference counting on Begin/End* :-(
    wx.EndBusyCursor()

    name = os.path.basename(_logfile_name)
    name, ext = os.path.splitext(name)
    new_name = os.path.expanduser(
        os.path.join(
            '~', '.local', 'gnumed', 'error_logs', '%s_%s%s' %
            (name, pyDT.datetime.now().strftime('%Y-%m-%d_%H-%M-%S'), ext)))

    dlg = cUnhandledExceptionDlg(None,
                                 -1,
                                 exception=(t, v, tb),
                                 logfile=new_name)
    dlg.ShowModal()
    comment = dlg._TCTRL_comment.GetValue()
    dlg.DestroyLater()
    if (comment is not None) and (comment.strip() != ''):
        _log.error('user comment: %s', comment.strip())

    _log.warning('syncing log file for backup to [%s]', new_name)
    gmLog2.flush()
    # keep a copy around
    shutil.copy2(_logfile_name, new_name)
scr2 = w + "/cl_me_km.job"

data = 0

for n in range(1,7):
      
      ang = 2.7+n*0.1
      
      command = "%s_ang_on_face" %ang
      os.makedirs(command)
      print "Creating Folder %s" %command
      
      dest = w +"/%s_ang_on_face/" %ang
      
      shutil.copy2(scr,dest)
      print "Coping to '%s'." %(dest)
      
      shutil.copy2(scr2,dest)
      print "Coping to '%s'." %(dest)
      
      
      myfile =w +'/%s_ang_on_face/cl_me_km.com' %ang
      
      with open (myfile,'r') as molin:
            data=molin.readlines()
      
      matching = [s for s in data if 'r=' in s]        #Zeilenindizes 
             
      r1 = [i for i, x in enumerate(data) if x ==matching[0]] #Index von zu a"nderender Zeile
      
Example #47
0
 def write_static(self, src_root, static):
     dst = os.path.join(self.root, "content", static.relpath)
     os.makedirs(os.path.dirname(dst), exist_ok=True)
     shutil.copy2(os.path.join(src_root, static.relpath), dst)
Example #48
0
    def create_dockerfile_object(self, directory: str) -> str:
        """
        Writes a dockerfile to the provided directory using the specified
        arguments on this Docker storage object.

        In order for the docker python library to build a container it needs a
        Dockerfile that it can use to define the container. This function takes the
        specified arguments then writes them to a temporary file called Dockerfile.

        *Note*: if `files` are added to this container, they will be copied to this
        directory as well.

        Args:
            - directory (str, optional): A directory where the Dockerfile will be
                created, if no directory is specified is will be created in the
                current working directory

        Returns:
            - str: the absolute file path to the Dockerfile
        """
        # Generate single pip install command for python dependencies
        pip_installs = "RUN pip install "
        if self.python_dependencies:
            for dependency in self.python_dependencies:
                pip_installs += "{} ".format(dependency)

        # Generate ENV variables to load into the image
        env_vars = ""
        if self.env_vars:
            white_space = " " * 20
            env_vars = "ENV " + " \\ \n{}".format(white_space).join(
                "{k}={v}".format(k=k, v=v) for k, v in self.env_vars.items())

        # Copy user specified files into the image
        copy_files = ""
        if self.files:
            for src, dest in self.files.items():
                fname = os.path.basename(src)
                full_fname = os.path.join(directory, fname)
                if os.path.exists(full_fname) and filecmp.cmp(
                        src, full_fname) is False:
                    raise ValueError(
                        "File {fname} already exists in {directory}".format(
                            fname=full_fname, directory=directory))
                else:
                    shutil.copy2(src, full_fname)
                copy_files += "COPY {fname} {dest}\n".format(
                    fname=full_fname if self.dockerfile else fname, dest=dest)

        # Write all flows to file and load into the image
        copy_flows = ""
        for flow_name, flow_location in self.flows.items():
            clean_name = slugify(flow_name)
            flow_path = os.path.join(directory, "{}.flow".format(clean_name))
            with open(flow_path, "wb") as f:
                cloudpickle.dump(self._flows[flow_name], f)
            copy_flows += "COPY {source} {dest}\n".format(
                source=flow_path
                if self.dockerfile else "{}.flow".format(clean_name),
                dest=flow_location,
            )

        # Write all extra commands that should be run in the image
        extra_commands = ""
        for cmd in self.extra_commands:
            extra_commands += "RUN {}\n".format(cmd)

        # Write a healthcheck script into the image
        with open(os.path.join(os.path.dirname(__file__), "_healthcheck.py"),
                  "r") as healthscript:
            healthcheck = healthscript.read()

        healthcheck_loc = os.path.join(directory, "healthcheck.py")
        with open(healthcheck_loc, "w") as health_file:
            health_file.write(healthcheck)

        if self.dockerfile:
            with open(self.dockerfile, "r") as contents:
                base_commands = textwrap.indent("\n" + contents.read(),
                                                prefix=" " * 16)
        else:
            base_commands = "FROM {base_image}".format(
                base_image=self.base_image)

        file_contents = textwrap.dedent("""\
            {base_commands}

            RUN pip install pip --upgrade
            {extra_commands}
            {pip_installs}

            RUN mkdir -p /opt/prefect/
            {copy_flows}
            COPY {healthcheck_loc} /opt/prefect/healthcheck.py
            {copy_files}

            {env_vars}
            """.format(
            base_commands=base_commands,
            extra_commands=extra_commands,
            pip_installs=pip_installs,
            copy_flows=copy_flows,
            healthcheck_loc=healthcheck_loc
            if self.dockerfile else "healthcheck.py",
            copy_files=copy_files,
            env_vars=env_vars,
        ))

        # append the line that runs the healthchecks
        if not self.ignore_healthchecks:
            file_contents += textwrap.dedent("""

                RUN python /opt/prefect/healthcheck.py '[{flow_file_paths}]' '{python_version}'
                """.format(
                flow_file_paths=", ".join(
                    ['"{}"'.format(k) for k in self.flows.values()]),
                python_version=(sys.version_info.major,
                                sys.version_info.minor),
            ))

        file_contents = "\n".join(line.lstrip()
                                  for line in file_contents.split("\n"))
        dockerfile_path = os.path.join(directory, "Dockerfile")
        with open(dockerfile_path, "w+") as dockerfile:
            dockerfile.write(file_contents)
        return dockerfile_path
Example #49
0
	def saveSettings(self):
		cData = []

		if len(self.e_fname.text()) > 0 and len(self.e_lname.text()) > 1:
			cData.append(['globals', "username", (self.e_fname.text() + " " + self.e_lname.text())])
			self.core.user = (self.e_fname.text()[0] + self.e_lname.text()[:2]).lower()

		if hasattr(self.core, "projectName") and self.e_localPath.isEnabled():
			lpath = self.core.fixPath(self.e_localPath.text())
			if not lpath.endswith(os.sep):
				lpath += os.sep

			cData.append(['localfiles', self.core.projectName, lpath])

		if self.e_localPath.text() != "disabled":
			self.core.localProjectPath = lpath

		rvPath = self.core.fixPath(self.e_rvPath.text())
		if rvPath != "" and not rvPath.endswith(os.sep):
			rvPath += os.sep
		cData.append(['globals', "rvpath", rvPath])

		djvPath = self.core.fixPath(self.e_djvPath.text())
		if djvPath != "" and not djvPath.endswith(os.sep):
			djvPath += os.sep
		cData.append(['globals', "djvpath", djvPath])

		cData.append(["globals", "prefer_djv", str(self.chb_preferDJV.isChecked())])
		cData.append(["globals", "showonstartup", str(self.chb_browserStartup.isChecked())])
		cData.append(["globals", "autosave", str(self.chb_autosave.isChecked())])
		cData.append(["globals", "highdpi", str(self.chb_highDPI.isChecked())])

		for i in self.exOverridePlugins:
			res = self.core.getPlugin(i).prismSettings_saveSettings(self)
			if type(res) == list:
				cData += res

		for i in self.exOverridePlugins:
			cData.append(['dccoverrides', "%s_override" % i, str(self.exOverridePlugins[i]["chb"].isChecked())])
			cData.append(['dccoverrides', "%s_path" % i, str(self.exOverridePlugins[i]["le"].text())])

		for i in self.core.prjManagers.values():
			res = i.prismSettings_saveSettings(self)
			if type(res) == list:
				cData += res

		if self.core.appPlugin.appType == "3d":
			if self.chb_autosave.isChecked():
				if not hasattr(self.core,  "asThread") or not self.core.asThread.isRunning():
					self.core.startasThread()
			else:
				self.core.startasThread(quit=True)

		self.core.setConfig(data=cData)

		if os.path.exists(self.core.prismIni):
			cData = []

			cData.append(['globals', 'project_name', (self.e_curPname.text())])
			cData.append(['globals', 'uselocalfiles', str(self.chb_curPuseLocal.isChecked())])
			cData.append(['globals', 'forcefps', str(self.chb_curPuseFps.isChecked())])
			cData.append(['globals', 'fps', str(self.sp_curPfps.value())])
			cData.append(['globals', 'forceversions', str(self.gb_curPversions.isChecked())])

			for i in self.core.prjManagers.values():
				res = i.prismSettings_savePrjSettings(self)
				if type(res) == list:
					cData += res

			for i in self.forceVersionPlugins:
				cData.append(['globals', "%s_version" % i, str(self.forceVersionPlugins[i]["le"].text())])

			self.core.setConfig(data=cData, configPath=self.core.prismIni)

			self.core.useLocalFiles = self.chb_curPuseLocal.isChecked()

			self.core.changeProject(self.core.prismIni)

		if platform.system() == "Windows":
			trayStartup = os.path.join(os.getenv('APPDATA'), "Microsoft", "Windows", "Start Menu", "Programs", "Startup", "PrismTray.lnk")
			trayLnk = self.core.fixPath(os.path.join(self.core.prismRoot, "Tools", "PrismTray.lnk"))

			if self.chb_trayStartup.isChecked():
				if os.path.exists(trayLnk):
					if os.path.exists(trayStartup):
						try:
							os.remove(trayStartup)
						except WindowsError as e:
							if e.winerror == 32:
								QMessageBox.warning(self, "Remove link", "Unable to remove autostart link, because the file is used by another process:\n\n%s" % trayStartup)
							else:
								raise

					if not os.path.exists(trayStartup):
						shutil.copy2(trayLnk, trayStartup)
				else:
					QMessageBox.warning(self, "Prism", "Cannot add Prism to the autostart because this shortcut doesn't exist:\n\n%s\n\nExecute '%s\\Win_Setup_Startmenu.bat' to create the shortcut." % (trayLnk, self.core.fixPath(self.core.prismRoot).replace("/", "\\")))
			elif os.path.exists(trayStartup):
				try:
					os.remove(trayStartup)
				except WindowsError as e:
					if e.winerror == 32:
						QMessageBox.warning(self, "Remove link", "Unable to remove autostart link, because the file is used by another process:\n\n%s" % trayStartup)
					else:
						raise


		elif platform.system() == "Linux":
			trayStartup = "/etc/xdg/autostart/PrismTray.desktop"
			trayLnk = "/usr/local/Prism/Tools/PrismTray.desktop"
			if os.path.exists(trayStartup):
				try:
					os.remove(trayStartup)
				except:
					QMessageBox.warning(self, "Warning", "Permission denied:\n\n%s\n\nTry to execute this tool as root." % trayStartup)

			if self.chb_trayStartup.isChecked():
				if not os.path.exists(trayStartup):
					shutil.copy2(trayLnk, trayStartup)
					os.chmod(trayStartup, 0o777)

		elif platform.system() == "Darwin":
			userName = os.environ['SUDO_USER'] if 'SUDO_USER' in os.environ else os.environ['USER']
			trayStartup = "/Users/%s/Library/LaunchAgents/com.user.PrismTray.plist" % userName
			trayLnk = "/Applications/Prism/Prism/Tools/com.user.PrismTray.plist"

			if os.path.exists(trayStartup):
				os.remove(trayStartup)

			if self.chb_trayStartup.isChecked():
				if not os.path.exists(trayStartup):
					shutil.copy2(trayLnk, trayStartup)
					os.chmod(trayStartup, 0o644)
					import pwd
					uid = pwd.getpwnam(userName).pw_uid
					os.chown(os.path.dirname(trayStartup), uid, -1)
					os.chown(trayStartup, uid, -1)
					os.system("launchctl load /Users/%s/Library/LaunchAgents/com.user.PrismTray.plist" % userName)

		self.core.callback(name="onPrismSettingsSave", types=["custom"], args=[self])
Example #50
0
 def copyToMirror(self, filename):
     '''Copy a file to its mirror path.'''
     mirPath = self.getMirrorPath(filename)
     destDir = mirPath.parent
     destDir.mkdir(parents=True, exist_ok=True)
     shutil.copy2(str(filename), str(mirPath))
Example #51
0
def copiarArquivos(dir):
    base = ABSBASE

    try:
        dst = os.path.join(dir, 'css')
        if os.path.exists(dst):
            shutil.rmtree(dst)
        shutil.copytree(os.path.join(base, 'css'), dst)
    except OSError, e:
        pass  # provavelmente diretório já existe
        logging.warning(e)

    # shutil.copy2(os.path.join(base, 'css', 'scriptLattes.css'), dir)
    # shutil.copy2(os.path.join(base, 'css', 'jquery.dataTables.css'), dir)

    shutil.copy2(os.path.join(base, 'imagens', 'lattesPoint0.png'), dir)
    shutil.copy2(os.path.join(base, 'imagens', 'lattesPoint1.png'), dir)
    shutil.copy2(os.path.join(base, 'imagens', 'lattesPoint2.png'), dir)
    shutil.copy2(os.path.join(base, 'imagens', 'lattesPoint3.png'), dir)
    shutil.copy2(os.path.join(base, 'imagens', 'lattesPoint_shadow.png'), dir)
    shutil.copy2(os.path.join(base, 'imagens', 'doi.png'), dir)

    try:
        dst = os.path.join(dir, 'images')
        if os.path.exists(dst):
            shutil.rmtree(dst)
        shutil.copytree(os.path.join(base, 'images'), dst)
    except OSError, e:
        pass  # provavelmente diretório já existe
        logging.warning(e)
Example #52
0
    def runThread(self): # start the forwader thread (once the start button is clicked from the window this function will execute)
        self.Message = self.messageTxt.toPlainText() # fetching the message form the UI
        self.Forwards = self.forwardsTxt.toPlainText() # fetching thenumber of forwards form theUI

        if self.Message == "" and self.imgPath == "": # if Message and Image path are both not definad show the error window
            self.errorWindow.setErrorMsg(
                "Please fill in at least one of the two :\n-Image path\n-Text Message\nOtherwise the program will not run")
            self.errorWindow.show()

        elif self.Forwards == "": # if the Number of forwards is not definad show the error window
            self.errorWindow.setErrorMsg(
                "Please set the number of forwards")
            self.errorWindow.show()

        elif (not self.is_number(self.Forwards)) or int(self.Forwards) < 1: # if the forward number is not valid as a number, show the error window
            self.errorWindow.setErrorMsg(
                "Please enter a valid number of forwards")
            self.errorWindow.show()

        elif (self.loadedCsvFile != None and self.loadedJsonFile != None and self.importedNamesCsvFile == None): # this is the case where you are startin completely new Forward WITHOUT target clients
            self.WhatsappForwader.setForwards(self.Forwards) # Setting the number of forwards to the forwader
            self.WhatsappForwader.setImagePath(self.imgPath) # Setting the image path to our forwader
            self.WhatsappForwader.setMessage(self.Message) # Setting the Message to our forwader
            self.WhatsappForwader.setFileName(self.loadedFileName) # if there is a loaded record we send it to our forwader here
            self.WhatsappForwader.setContactMode(variables.NEW_NAMES) # setContactMode is function that defines whether we are using targeted clients or we're starting fresh
            self.MODE = variables.NEW_NAMES # setting the contact mode in this class aswell
            self.WhatsappForwader.setContactDict(self.contactDict) # here we are passing the contacts names to our forwader 
            self.WhatsappForwader.setPreviewMode( 
                self.previewCheckBox.isChecked()) # if the preview mode checkbox in the window is checked, self.previewCheckBox.isChecked() will return true otherwise returns false 
            self.WhatsappForwader.setIsDelayMode(self.delayCheckBox.isChecked()) # same as above for the delay checkbox (used to set delay betweeen messages (30 to 60 seconds))
            self.WhatsappForwader.start() # start the forwader thread
            self.startBtn.setStyleSheet(
            "background-color: white;  border: 1px solid #ababab; border-radius: 10px; font-size: 12px;color: #ababab;text-align: center;")  # setting style sheet

        elif (self.loadedCsvFile == None and self.loadedJsonFile == None and self.importedNamesCsvFile != None):  # this is the case where you are starting a completely new Forward WITH target clients
            currentDate = datetime.today().strftime("%Y-%m-%d %H:%M:%S") # we create a name for the folder which will hold all the data of this sessio,  the name of the folder is the current time in the format of YY-mm-dd hh:mm:ss
            os.makedirs(f'records/{currentDate}') # os.makedirs creates teh folder with teh given name
            jsonFile = open(f'records/{currentDate}/record.json', 'w+') # here we create a new file record.json in the created folder 
            if self.importedNamesCsvFile != None:
                open(f'records/{currentDate}/importedNames.csv', 'w+') # open the imported names file if there is any 
                shutil.copy2(self.importedNamesCsvFile.name, f'records/{currentDate}/importedNames.csv') # make a copy of the imported names csv file and save it on the local folder 
            jsonData = {
                "date": currentDate,
                "Forwards": self.Forwards,
                "Message": self.Message,
                "imagePath": self.imgPath,
                "importedNames": 'False' if self.importedNamesCsvFile == None else 'True'
            } # this is the structure of the data that will be saved in json file 
            json.dump(jsonData, jsonFile) # dumping the data into the json file
            self.progressBar.setVisible(True) # setting the prograss bar to be visisble since we now know the number of forwards 
            self.progressLbl.setVisible(True) # setting the label of the progress bar visible for the same reason mentioned above
            self.WhatsappForwader.setContactMode(variables.IMPORTED_NAMES) # We tell the forwader that the contacts are imported 
            self.MODE = variables.IMPORTED_NAMES # we notify this class that we are working with imported names 
            self.progressLbl.setText(f"0/{self.Forwards}") # we set the text of the progress bar 
            self.progressBar.setMaximum(int(self.Forwards)) # setting the maximum value for the progress bar (aka the number of forwards desired)
            self.progressBar.setMinimum(0) # min is always 0 ...
            self.progressBar.setValue(len(self.importedContactDict)) # if we have record that had imported names and was loaded, the progress bar will automatically set the value of the number of contacts that were already scanned 
            self.WhatsappForwader.setForwards(self.Forwards) # set the number of forwards for the forwader 
            self.WhatsappForwader.setImagePath(self.imgPath) # set the image path if any for the forwader
            self.WhatsappForwader.setContactDict(self.importedContactDict) # we send the loaded contact hashmap for the forwader 
            self.WhatsappForwader.setMessage(self.Message) # sending message for the forwader
            self.WhatsappForwader.setFileName(currentDate) # sending the folder name for the forwader (it needs it because it writes directly to the files inside the folder to update the scanned names)
            self.WhatsappForwader.loadCsvFile() # this is the csv file contained in the above mentioned folder , i'm just opening it to get things ready and start adding scanned contact names to it 
            self.WhatsappForwader.setPreviewMode(
                self.previewCheckBox.isChecked()) # setting if preview mode from checkbox
            self.WhatsappForwader.setIsDelayMode(self.delayCheckBox.isChecked()) # setting if with delay from checkbox
            self.WhatsappForwader.start() # start the thread 
            self.startBtn.setStyleSheet(
            "background-color: white;  border: 1px solid #ababab; border-radius: 10px; font-size: 12px;color: #ababab;text-align: center;") # setting style sheet

        elif (self.loadedCsvFile != None and self.loadedJsonFile != None and self.importedNamesCsvFile != None):  # this is the case where you are continuing a previous forward specified from a record file WITHOUT target clients
            self.WhatsappForwader.setForwards(self.Forwards) # refer to above documentation to see what each function of the forwader does
            self.WhatsappForwader.setImagePath(self.imgPath)
            self.WhatsappForwader.setMessage(self.Message)
            self.WhatsappForwader.setFileName(self.loadedFileName)
            self.WhatsappForwader.setContactMode(variables.IMPORTED_NAMES)
            self.MODE = variables.IMPORTED_NAMES
            self.WhatsappForwader.setContactDict(self.remainingContactDict)
            self.WhatsappForwader.setPreviewMode(
                self.previewCheckBox.isChecked())
            self.WhatsappForwader.start()
            self.WhatsappForwader.setIsDelayMode(self.delayCheckBox.isChecked())
            self.startBtn.setStyleSheet(
            "background-color: white;  border: 1px solid #ababab; border-radius: 10px; font-size: 12px;color: #ababab;text-align: center;") # setting style sheet

        else: # this is the case where you are continuing a previous forward specified from a record file WITH target clients
            currentDate = datetime.today().strftime("%Y-%m-%d %H:%M:%S") # refer to above documentation to see what each function of the forwader does
            os.makedirs(f'records/{currentDate}')
            jsonFile = open(f'records/{currentDate}/record.json', 'w+')
            jsonData = {
                "date": currentDate,
                "Forwards": self.Forwards,
                "Message": self.Message,
                "imagePath": self.imgPath,
                "importedNames": 'False' if self.importedNamesCsvFile == None else 'True'
            }
            json.dump(jsonData, jsonFile)
            self.progressBar.setVisible(True)
            self.progressLbl.setVisible(True)
            self.WhatsappForwader.setContactMode(variables.NEW_NAMES)
            self.MODE = variables.NEW_NAMES
            self.progressLbl.setText(f"0/{self.Forwards}")
            self.progressBar.setMaximum(int(self.Forwards))
            self.progressBar.setMinimum(0)
            self.progressBar.setValue(len(self.contactDict))
            self.WhatsappForwader.setForwards(self.Forwards)
            self.WhatsappForwader.setImagePath(self.imgPath)
            self.WhatsappForwader.setMessage(self.Message)
            self.WhatsappForwader.setFileName(currentDate)
            self.WhatsappForwader.loadCsvFile()
            self.WhatsappForwader.setPreviewMode(
                self.previewCheckBox.isChecked())
            self.WhatsappForwader.setIsDelayMode(self.delayCheckBox.isChecked())
            self.WhatsappForwader.start()
            self.startBtn.setStyleSheet(
            "background-color: white;  border: 1px solid #ababab; border-radius: 10px; font-size: 12px;color: #ababab;text-align: center;") # setting style sheet
Example #53
0
if sys.platform == "linux":
    lib_dir = os.path.join(ctp_dir, "linux")
    package_data.append("*.so")
    extra_compile_args = ["-Wall"]
    extra_link_args = ['-Wl,-rpath,$ORIGIN']

elif sys.platform == "win32":
    lib_dir = os.path.join(ctp_dir, "win")
    extra_compile_args = ["/GR", "/EHsc"]
    # extra_link_args = []
    package_data.append("*.dll")

package_data.append("error.dtd")
package_data.append("error.xml")
shutil.copy2(header_dir + "/error.dtd", project_dir + "/error.dtd")
shutil.copy2(header_dir + "/error.xml", project_dir + "/error.xml")

if sys.platform in ["linux", "win32"]:
    copy_tree(lib_dir, project_dir)

common_args = {
    "cython_include_dirs": [cython_headers],
    "include_dirs": [header_dir, cpp_header_dir],
    "library_dirs": [lib_dir],
    "language": "c++",
    "extra_compile_args": extra_compile_args,
    "extra_link_args": extra_link_args,
}

ext_modules = [
Example #54
0
def build_ngraph_tf(build_dir, artifacts_location, ngtf_src_loc, venv_dir,
                    cmake_flags, verbose):
    pwd = os.getcwd()

    # Load the virtual env
    load_venv(venv_dir)

    command_executor(["pip", "list"])

    # Get the absolute path for the artifacts
    artifacts_location = os.path.abspath(artifacts_location)

    ngtf_src_loc = os.path.abspath(ngtf_src_loc)
    print("Source location: " + ngtf_src_loc)

    os.chdir(ngtf_src_loc)

    # mkdir build directory
    path = build_dir
    try:
        os.makedirs(path)
    except OSError as exc:  # Python >2.5
        if exc.errno == errno.EEXIST and os.path.isdir(path):
            pass

    # Run cmake
    os.chdir(path)
    cmake_cmd = ["cmake"]
    cmake_cmd.extend(cmake_flags)
    cmake_cmd.extend([ngtf_src_loc])
    command_executor(cmake_cmd)

    import psutil
    num_cores = str(psutil.cpu_count(logical=True))
    make_cmd = ["make", "-j" + num_cores, "install"]
    if verbose:
        make_cmd.extend(['VERBOSE=1'])

    command_executor(make_cmd)

    os.chdir(os.path.join("python", "dist"))
    ngtf_wheel_files = glob.glob("ngraph_tensorflow_bridge-*.whl")
    if (len(ngtf_wheel_files) != 1):
        print("Multiple Python whl files exist. Please remove old wheels")
        for whl in ngtf_wheel_files:
            print("Existing Wheel: " + whl)
        raise Exception("Error getting the ngraph-tf wheel file")

    output_wheel = ngtf_wheel_files[0]
    print("OUTPUT WHL FILE: %s" % output_wheel)

    output_path = os.path.join(artifacts_location, output_wheel)
    print("OUTPUT WHL DST: %s" % output_path)
    # Delete just in case it exists
    try:
        os.remove(output_path)
    except OSError:
        pass

    # Now copy
    shutil.copy2(output_wheel, artifacts_location)

    os.chdir(pwd)
    return output_wheel
Example #55
0
def copy_files(files_list, fromdir, todir):
    for file in files_list:
        copy2(fromdir + "\\" + file, todir)
Example #56
0
            for f in files:
                # Skip unwanted files
                if filter and filter(f):
                    continue
                srcfile = os.path.join(dir, f)
                destfile = os.path.join(dest, basedir, f)
<<<<<<< HEAD
                # directory creation is lazy and after the file filtering above
                # to ensure we don't install empty dirs; empty dirs can't be
                # uninstalled.
                if not os.path.exists(destdir):
                    os.makedirs(destdir)
                # use copy2 (not move) to be extra sure we're not moving
                # directories over; copy2 fails for directories.  this would
                # fail tests (not during released/user execution)
                shutil.copy2(srcfile, destfile)
=======
                shutil.move(srcfile, destfile)
>>>>>>> e4baf504ede925f4f1e07d823c9b20b3d0dbe14c
                changed = False
                if fixer:
                    changed = fixer(destfile)
                record_installed(srcfile, destfile, changed)

    clobber(source, lib_dir, True)

    assert info_dir, "%s .dist-info directory not found" % req

    # Get the defined entry points
    ep_file = os.path.join(info_dir[0], 'entry_points.txt')
    console, gui = get_entrypoints(ep_file)
Example #57
0
        print("Unfortunately, this can't be left blank")
        wo_user = input("Enter your name: ")

    wo_email = input("Enter your email: ")

    while not re.match(r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$",
                       wo_email):
        print("Whoops, seems like you made a typo - "
              "the e-mailaddress is invalid...")
        wo_email = input("Enter your email: ")

    os.system("git config --global user.name {0}".format(wo_user))
    os.system("git config --global user.email {0}".format(wo_email))

if not os.path.isfile('/root/.gitconfig'):
    shutil.copy2(os.path.expanduser("~") + '/.gitconfig', '/root/.gitconfig')

setup(
    name='wo',
    version='3.9.4',
    description=long_description,
    long_description=long_description,
    classifiers=[],
    keywords='',
    author='WordOps',
    author_email='*****@*****.**',
    url='https://wordops.net',
    license='MIT',
    packages=find_packages(
        exclude=['ez_setup', 'examples', 'tests', 'templates']),
    include_package_data=True,
Example #58
0
def rotateFile(filepath, depth=5, suffix='.', verbosity=0):
    """ backup/rotate a file
        depth (-1==no limit) refers to num. of backups (rotations) to keep.

        Behavior:
          (1)
            x.txt (current)
            x.txt.1 (old)
            x.txt.2 (older)
            x.txt.3 (oldest)
          (2)
            all file stats preserved. Doesn't blow away original file.
          (3)
            if x.txt and x.txt.1 are identical (size or checksum), None is
            returned
    """

    # check argument sanity (should really be down outside of this function)
    if not filepath or type(filepath) != type(''):
        raise ValueError("filepath '%s' is not a valid arguement" % filepath)
    if type(depth) != type(0) or depth < -1 \
      or depth > sys.maxint-1 or depth == 0:
        raise ValueError("depth must fall within range "
                         "[-1, 1...%s]" % (sys.maxint-1))

    # force verbosity to be a numeric value
    verbosity = verbosity or 0
    if type(verbosity) != type(0) or verbosity < -1 \
      or verbosity > sys.maxint-1:
        raise ValueError('invalid verbosity value: %s' % (verbosity))

    filepath = cleanupAbsPath(filepath)
    if not os.path.isfile(filepath):
        raise ValueError("filepath '%s' does not lead to a file" % filepath)

    pathNSuffix = filepath + suffix
    pathNSuffix1 = pathNSuffix + '1'


    if verbosity > 1:
        sys.stderr.write("Working dir: %s\n"
                         % os.path.dirname(pathNSuffix))

    # is there anything to do? (existence, then size, then checksum)
    checksum_type = 'sha1'
    if os.path.exists(pathNSuffix1) and os.path.isfile(pathNSuffix1) \
      and os.stat(filepath)[6] == os.stat(pathNSuffix1)[6] \
      and getFileChecksum(checksum_type, filepath) == \
          getFileChecksum(checksum_type, pathNSuffix1):
        # nothing to do
        if verbosity:
            sys.stderr.write("File '%s' is identical to its rotation. "
                             "Nothing to do.\n" % os.path.basename(filepath))
        return None

    # find last in series (of rotations):
    last = 0
    while os.path.exists('%s%d' % (pathNSuffix, last+1)):
        last = last+1

    # percolate renames:
    for i in range(last, 0, -1):
        os.rename('%s%d' % (pathNSuffix, i), '%s%d' % (pathNSuffix, i+1))
        if verbosity > 1:
            filename = os.path.basename(pathNSuffix)
            sys.stderr.write("Moving file: %s%d --> %s%d\n" % (filename, i,
                                                               filename, i+1))

    # blow away excess rotations:
    if depth != -1:
        last = last+1
        for i in range(depth+1, last+1):
            path = '%s%d' % (pathNSuffix, i)
            os.unlink(path)
            if verbosity:
                sys.stderr.write("Rotated out: '%s'\n" % (
                    os.path.basename(path)))

    # do the actual rotation
    shutil.copy2(filepath, pathNSuffix1)
    if os.path.exists(pathNSuffix1) and verbosity:
        sys.stderr.write("Backup made: '%s' --> '%s'\n"
                         % (os.path.basename(filepath),
                            os.path.basename(pathNSuffix1)))

    # return the full filepath of the backed up file
    return pathNSuffix1
Example #59
0
import os
import sys
import shutil

figdir = os.path.join("RVAT-Re-dep", "Figures")

figlist = ["cp_curves.pdf",
           "cd_curves.pdf",
           "perf_re_dep.pdf",
           "K_trans_bar_graph.pdf",
           "mom_bar_graph.pdf",
           "wake_spectra.pdf",
           "wake_trans_totals.pdf",
           "meancontquiv_10.pdf",
           "k_contours_10.pdf",
           "mean_u_k_profiles.pdf"]

for fig in figlist:
    shutil.copy2(os.path.join(figdir, fig), os.path.join("figures", fig))


figdir = os.path.join("NACAXX20-XFOIL", "figures")

figlist = ["all_foils_re_dep.pdf",
           "cft_re_dep_foils.pdf",
           "foil_kinematics_ct.pdf"]

for fig in figlist:
    shutil.copy2(os.path.join(figdir, fig), os.path.join("figures", fig))
Example #60
0
Keep the empty folders in place (don't delete since it might still be rendered right)
Also copy the corresponding yaml in there
"""

input_path = sys.argv[1]
output_path = sys.argv[2]
yaml_path = sys.argv[3]

# This overrides the softlink
# os.makedirs(output_path, exist_ok=True)

renders = os.listdir(input_path)
is_rendered = [len(os.listdir(path.join(input_path, r, 'segmentation')))==160 for r in renders]

updated = 0
for i, r in enumerate(renders):
    if is_rendered[i]:
        if not path.exists(path.join(output_path, r)):
            shutil.move(path.join(input_path, r), output_path)
            prefix = r[:3]
        
            shutil.copy2(path.join(yaml_path, 'yaml_%s'%prefix, '%s.yaml'%r), path.join(output_path, r))
            updated += 1
        else:
            print('path exist')
    else:
        # Nothing for now. Can do something later
        pass

print('Number of completed renders: ', len(os.listdir(output_path)))
print('Number of updated renders: ', updated)