Extract package to a temporary folder.

        Return:
            pathlib.Path: Temp dir with package contents.
4781
def _extract(filename):
        
        random_string = '{:0d}'.format(randint(0, 10**6))
        tmp = '/tmp/kytos-napp-' + Path(filename).stem + '-' + random_string
        os.mkdir(tmp)
        with tarfile.open(filename, 'r:xz') as tar:
            tar.extractall(tmp)
        return Path(tmp)
749834
def get_temp_dir(suffix=None):
    
    to_join = [tempfile.gettempdir()]

    if os.name == 'nt':
        to_join.append('spyder')
    else:
        username = encoding.to_unicode_from_fs(getuser())
        to_join.append('spyder-' + username)

    if suffix is not None:
        to_join.append(suffix)

    tempdir = osp.join(*to_join)

    if not osp.isdir(tempdir):
        os.mkdir(tempdir)

    return tempdir
985270
def _tempDirectories(self):
        
        def _dirs(path, levels):
            if levels > 0:
                for subPath in os.listdir(path):
                    for i in _dirs(os.path.join(path, subPath), levels-1):
                        yield i
            else:
                yield path
        for tempDir in _dirs(self.tempFilesDir, self.levels):
            yield tempDir
1020288
def _make_tmp_path(self, remote_user=None):
        
        LOG.debug('_make_tmp_path(remote_user=%r)', remote_user)
        path = self._generate_tmp_path()
        LOG.debug('Temporary directory: %r', path)
        self._connection.get_chain().call_no_reply(os.mkdir, path)
        self._connection._shell.tmpdir = path
        return path
718392
def generate_temporary_file(folder='/tmp', prefix='helpme', ext='json'):
    '''

    '''        
    tmp = next(tempfile._get_candidate_names())
    return '%s/%s.%s.%s' %(folder, prefix, tmp, ext)
1175262
def _default_temporary_directory(self, prefix):
    """"""
    try:
      self.temporary_file = tempfile.NamedTemporaryFile(prefix=prefix)

    except OSError as err: # pragma: no cover
      logger.critical('Cannot create a system temporary directory: '+repr(err))
      raise securesystemslib.exceptions.Error(err)
689543
def empty_directory(path=None):
    
    install_dir = tempfile.mkdtemp(dir=path)
    try:
        yield install_dir
    finally:
        shutil.rmtree(install_dir)
997258
def getTempFile(suffix="", rootDir=None):
    
    if rootDir is None:
        handle, tmpFile = tempfile.mkstemp(suffix)
        os.close(handle)
        return tmpFile
    else:
        tmpFile = os.path.join(rootDir, "tmp_" + getRandomAlphaNumericString() + suffix)
        open(tmpFile, 'w').close()
        os.chmod(tmpFile, 0777) #Ensure everyone has access to the file.
        return tmpFile
1025672
def _cleanup_temp_dir(self, base_dir):
        """"""
        if self._should_cleanup_temp_dir:
            logging.debug('Cleaning up temporary directory %s.', base_dir)
            if self._user is None:
                util.rmtree(base_dir, onerror=util.log_rmtree_error)
            else:
                rm = subprocess.Popen(self._build_cmdline(['rm', '-rf', '--', base_dir]),
                                      stderr=subprocess.PIPE)
                rm_output = rm.stderr.read().decode()
                rm.stderr.close()
                if rm.wait() != 0 or rm_output:
                    logging.warning("Failed to clean up temp directory %s: %s.",
                                    base_dir, rm_output)
        else:
            logging.info("Skipping cleanup of temporary directory %s.", base_dir)
123924
def tmppath(path=None, include_unix_username=True):
    
    addon = "luigitemp-%08d" % random.randrange(1e9)
    temp_dir = '/tmp'  # default tmp dir if none is specified in config

    # 1. Figure out to which temporary directory to place
    configured_hdfs_tmp_dir = hdfs().tmp_dir
    if configured_hdfs_tmp_dir is not None:
        # config is superior
        base_dir = configured_hdfs_tmp_dir
    elif path is not None:
        # need to copy correct schema and network location
        parsed = urlparse(path)
        base_dir = urlunparse((parsed.scheme, parsed.netloc, temp_dir, '', '', ''))
    else:
        # just system temporary directory
        base_dir = temp_dir

    # 2. Figure out what to place
    if path is not None:
        if path.startswith(temp_dir + '/'):
            # Not 100%, but some protection from directories like /tmp/tmp/file
            subdir = path[len(temp_dir):]
        else:
            # Protection from /tmp/hdfs:/dir/file
            parsed = urlparse(path)
            subdir = parsed.path
        subdir = subdir.lstrip('/') + '-'
    else:
        # just return any random temporary location
        subdir = ''

    if include_unix_username:
        subdir = os.path.join(getpass.getuser(), subdir)

    return os.path.join(base_dir, subdir + addon)
600559
def _get_temp_file_location():
    '''
    

    '''
    from .._connect import main as _glconnect
    unity = _glconnect.get_unity()
    cache_dir = _convert_slashes(unity.get_current_cache_file_location())
    if not _os.path.exists(cache_dir):
        _os.makedirs(cache_dir)
    return cache_dir
159475
def _prepare_temp_dir(self):
    """"""
    shell_call(['rm', '-rf', os.path.join(self._temp_dir, '*')])
    # NOTE: we do not create self._extracted_submission_dir
    # this is intentional because self._tmp_extracted_dir or it's subdir
    # will be renames into self._extracted_submission_dir
    os.mkdir(self._tmp_extracted_dir)
    os.mkdir(self._sample_input_dir)
    os.mkdir(self._sample_output_dir)
    # make output dir world writable
    shell_call(['chmod', 'a+rwX', '-R', self._sample_output_dir])
937314
def tar_and_copy_usr_dir(usr_dir, train_dir):
  """"""
  tf.logging.info("Tarring and pushing t2t_usr_dir.")
  usr_dir = os.path.abspath(os.path.expanduser(usr_dir))
  # Copy usr dir to a temp location
  top_dir = os.path.join(tempfile.gettempdir(), "t2t_usr_container")
  tmp_usr_dir = os.path.join(top_dir, usr_dir_lib.INTERNAL_USR_DIR_PACKAGE)
  shutil.rmtree(top_dir, ignore_errors=True)
  shutil.copytree(usr_dir, tmp_usr_dir)
  # Insert setup.py if one does not exist
  top_setup_fname = os.path.join(top_dir, "setup.py")
  setup_file_str = get_setup_file(
      name="DummyUsrDirPackage",
      packages=get_requirements(usr_dir)
  )
  with tf.gfile.Open(top_setup_fname, "w") as f:
    f.write(setup_file_str)
  usr_tar = _tar_and_copy(top_dir, train_dir)
  return usr_tar
840885
def MakeDir(self, path="temp"):
        
        full_path = _os.path.join(self.path_home, path)

        # only make it if it doesn't exist!
        if not _os.path.exists(full_path): _os.makedirs(full_path)
1033742
def package_files(directory):
    """"""
    paths = []
    for (path, _, file_names) in walk(directory):
        for filename in file_names:
            paths.append(join('..', path, filename))
    return paths
313434
def abspath(myPath):
    import sys, os
    
    try:
        # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
        return os.path.join(base_path, os.path.basename(myPath))
    except Exception:
        base_path = os.path.abspath(os.path.dirname(__file__))
        return os.path.join(base_path, myPath)
355411
def extract_lzma(path):
    """"""
    tlfile = pathlib.Path(path)
    # open lzma file
    with tlfile.open("rb") as td:
        data = lzma.decompress(td.read())
    # write temporary tar file
    fd, tmpname = tempfile.mkstemp(prefix="odt_ex_", suffix=".tar")
    with open(fd, "wb") as fo:
        fo.write(data)
    return tmpname