Python shutil.move() Examples

The following are 30 code examples of shutil.move(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module shutil , or try the search function .
Example #1
Source File: demo.py    From svviz with MIT License 32 votes vote down vote up
def downloadDemo(which):
    try:
        downloadDir = tempfile.mkdtemp()
        archivePath = "{}/svviz-data.zip".format(downloadDir)

        # logging.info("Downloading...")
        downloadWithProgress("http://svviz.github.io/svviz/assets/examples/{}.zip".format(which), archivePath)
        
        logging.info("Decompressing...")
        archive = zipfile.ZipFile(archivePath)
        archive.extractall("{}".format(downloadDir))

        if not os.path.exists("svviz-examples"):
            os.makedirs("svviz-examples/")

        shutil.move("{temp}/{which}".format(temp=downloadDir, which=which), "svviz-examples/")
    except Exception as e:
        print("error downloading and decompressing example data: {}".format(e))
        return False

    if not os.path.exists("svviz-examples"):
        print("error finding example data after download and decompression")
        return False
    return True 
Example #2
Source File: purge_checkpoints.py    From imgcomp-cvpr with GNU General Public License v3.0 6 votes vote down vote up
def purge_checkpoints(log_dir_root, target_dir, verbose):
    vprint = print if verbose else no_op.NoOp
    ckpt_dir_glob = Saver.ckpt_dir_for_log_dir(path.join(log_dir_root, '*'))
    ckpt_dir_matches = sorted(glob.glob(ckpt_dir_glob))
    for ckpt_dir in ckpt_dir_matches:
        log_dir = Saver.log_dir_from_ckpt_dir(ckpt_dir)
        all_ckpts = Saver.all_ckpts_with_iterations(ckpt_dir)
        if len(all_ckpts) <= 5:
            vprint('Skipping {}'.format(log_dir))
            continue
        target_log_dir = path.join(target_dir, path.basename(log_dir))
        target_ckpt_dir = Saver.ckpt_dir_for_log_dir(target_log_dir)
        os.makedirs(target_ckpt_dir, exist_ok=True)
        ckpts_to_keep = {all_ckpts[2], all_ckpts[len(all_ckpts) // 2], all_ckpts[-1]}
        ckpts_to_move = set(all_ckpts) - ckpts_to_keep
        vprint('Moving to {}:'.format(target_ckpt_dir))
        for _, ckpt_to_move in ckpts_to_move:
            # ckpt_to_move is /path/to/dir/ckpt-7000, add a * to match ckpt-7000.data, .meta, .index
            for ckpt_file in glob.glob(ckpt_to_move + '*'):
                vprint('- {}'.format(ckpt_file))
                shutil.move(ckpt_file, target_ckpt_dir) 
Example #3
Source File: conanfile.py    From conan-center-index with MIT License 6 votes vote down vote up
def package(self):
        self.copy("COPYING", src=self._source_subfolder, dst="licenses")
        cmake = self._configure_cmake()
        cmake.install()

        if self.options.shared:
            if self.settings.compiler == "Visual Studio":
                static_lib = "x265-static.lib"
            else:
                static_lib = "libx265.a"
            os.unlink(os.path.join(self.package_folder, "lib", static_lib))

        if self.settings.compiler == "Visual Studio":
            name = "libx265.lib" if self.options.shared else "x265-static.lib"
            shutil.move(os.path.join(self.package_folder, "lib", name),
                        os.path.join(self.package_folder, "lib", "x265.lib"))

        if self.settings.os != "Windows" or not self.options.shared:
            tools.rmdir(os.path.join(self.package_folder, "bin"))
        else:
            for file in os.listdir(os.path.join(self.package_folder, "bin")):
                if not file.endswith(".dll"):
                    os.unlink(os.path.join(self.package_folder, "bin", file))
        tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) 
Example #4
Source File: _qemu.py    From ALF with Apache License 2.0 6 votes vote down vote up
def _remote_init(working_dir):
    global pickle
    import pickle
    import sys
    import shutil
    import os
    if not os.path.isdir(working_dir):
        os.mkdir(working_dir)
    sys.path.append(working_dir)
    shutil.move("_common.py", working_dir)
    shutil.move("_gdb.py", working_dir)
    shutil.move("cmds.gdb", working_dir)
    # setup CERT exploitable
    exp_lib_dir = os.path.join(working_dir, "exploitable", "lib")
    os.makedirs(exp_lib_dir)
    shutil.move("exploitable.py", os.path.join(working_dir, "exploitable"))
    shutil.move("__init__.py", exp_lib_dir)
    shutil.move("analyzers.py", exp_lib_dir)
    shutil.move("classifier.py", exp_lib_dir)
    shutil.move("elf.py", exp_lib_dir)
    shutil.move("gdb_wrapper.py", exp_lib_dir)
    shutil.move("rules.py", exp_lib_dir)
    shutil.move("tools.py", exp_lib_dir)
    shutil.move("versions.py", exp_lib_dir)
    os.chdir(working_dir)
    global _common
    global _gdb
    import _common
    import _gdb 
Example #5
Source File: parts.py    From Servo with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def get_return_label(self):
        """Get the GSX return label for this part."""
        if self.return_label.name == "":
            # Return label not yet set, get it...
            label = gsxws.Return(self.return_order).get_label(self.part_number)
            filename = "%s_%s.pdf" % (self.return_order, self.part_number)
            tmp_fp = os.path.join(settings.TEMP_ROOT, filename)
            #  move the label to local temp to avoid
            #  django.security.SuspiciousFileOperation
            shutil.move(label.returnLabelFileData, tmp_fp)

            f = File(open(tmp_fp, 'r'))
            self.return_label = f
            self.save()
            self.return_label.save(filename, f)
            f.closed
            os.remove(tmp_fp)

        return self.return_label.read() 
Example #6
Source File: test_delocating.py    From delocate with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def test_dyld_library_path_lookups():
    # Test that DYLD_LIBRARY_PATH can be used to find libs during
    # delocation
    with TempDirWithoutEnvVars('DYLD_LIBRARY_PATH') as tmpdir:
        # Copy libs into a temporary directory
        subtree = pjoin(tmpdir, 'subtree')
        all_local_libs = _make_libtree(subtree)
        liba, libb, libc, test_lib, slibc, stest_lib = all_local_libs
        # move libb and confirm that test_lib doesn't work
        hidden_dir = 'hidden'
        os.mkdir(hidden_dir)
        new_libb = os.path.join(hidden_dir, os.path.basename(LIBB))
        shutil.move(libb,
                    new_libb)
        assert_raises(RuntimeError, back_tick, [test_lib])
        # Update DYLD_LIBRARY_PATH and confirm that we can now
        # successfully delocate test_lib
        os.environ['DYLD_LIBRARY_PATH'] = hidden_dir
        delocate_path('subtree', 'deplibs')
        back_tick(test_lib) 
Example #7
Source File: conanfile.py    From conan-center-index with MIT License 6 votes vote down vote up
def package(self):
        self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
        with self._build_context():
            autotools = self._configure_autotools()
            autotools.install(args=self._make_args)

        tools.rmdir(os.path.join(self.package_folder, "bin", "share", "man"))
        tools.rmdir(os.path.join(self.package_folder, "bin", "share", "pkgconfig"))
        tools.rmdir(os.path.join(self.package_folder, "bin", "share", "verilator", "examples"))

        os.unlink(os.path.join(self.package_folder, "bin", "share", "verilator", "verilator-config-version.cmake"))
        os.rename(os.path.join(self.package_folder, "bin", "share", "verilator", "verilator-config.cmake"),
                  os.path.join(self.package_folder, "bin", "share", "verilator", "verilator-tools.cmake"))

        if self.settings.build_type == "Debug":
            tools.replace_in_file(os.path.join(self.package_folder, "bin", "share", "verilator", "verilator-tools.cmake"),
                                  "verilator_bin", "verilator_bin_dbg")

        shutil.move(os.path.join(self.package_folder, "bin", "share", "verilator", "include"),
                    os.path.join(self.package_folder))

        for fn in glob.glob(os.path.join(self.package_folder, "bin", "share", "verilator", "bin", "*")):
            print(fn, "->", "..")
            os.rename(fn, os.path.join(self.package_folder, "bin", os.path.basename(fn)))
        tools.rmdir(os.path.join(self.package_folder, "bin", "share", "verilator", "bin")) 
Example #8
Source File: conanfile.py    From conan-center-index with MIT License 6 votes vote down vote up
def package(self):
        self.copy(pattern="LICENSE", src=self._source_subfolder, dst="licenses")
        if self._is_msvc:
            self.copy(pattern='*.h', src=os.path.join(self._source_subfolder, 'include'), dst=os.path.join('include', 'lame'))
            self.copy(pattern='*.lib', src=os.path.join(self._source_subfolder, 'output'), dst='lib')
            self.copy(pattern='*.exe', src=os.path.join(self._source_subfolder, 'output'), dst='bin')
            if self.options.shared:
                self.copy(pattern='*.dll', src=os.path.join(self._source_subfolder, 'output'), dst='bin')
            name = 'libmp3lame.lib' if self.options.shared else 'libmp3lame-static.lib'
            shutil.move(os.path.join(self.package_folder, 'lib', name),
                        os.path.join(self.package_folder, 'lib', 'mp3lame.lib'))
        else:
            autotools = self._configure_autotools()
            autotools.install()
            tools.rmdir(os.path.join(self.package_folder, "bin"))
        tools.rmdir(os.path.join(self.package_folder, 'share'))
        la_file = os.path.join(self.package_folder, "lib", "libmp3lame.la")
        if os.path.isfile(la_file):
            os.unlink(la_file) 
Example #9
Source File: utils.py    From zmirror with MIT License 6 votes vote down vote up
def restore_config_file():
    os.remove(zmirror_file('config.py'))
    os.remove(zmirror_file('custom_func.py'))
    if os.path.exists(zmirror_file('config.py._unittest_raw')):
        shutil.move(zmirror_file('config.py._unittest_raw'), zmirror_file('config.py'))
    if os.path.exists(zmirror_file('custom_func.py._unittest_raw')):
        shutil.move(zmirror_file('custom_func.py._unittest_raw'), zmirror_file('custom_func.py'))

    try:
        os.remove(zmirror_file('ip_whitelist.txt'))
    except:
        pass
    try:
        os.remove(zmirror_file('ip_whitelist.log'))
    except:
        pass
    try:
        os.remove(zmirror_file('automatic_domains_whitelist.log'))
    except:
        pass 
Example #10
Source File: benchmark.py    From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 6 votes vote down vote up
def setup_logging(log_loc):
    if os.path.exists(log_loc):
        shutil.move(log_loc, log_loc + "_" + str(int(os.path.getctime(log_loc))))
    os.makedirs(log_loc)

    log_file = '{}/benchmark.log'.format(log_loc)
    LOGGER = logging.getLogger('benchmark')
    LOGGER.setLevel(logging.INFO)
    formatter = logging.Formatter('%(asctime)s %(levelname)s:%(name)s %(message)s')
    file_handler = logging.FileHandler(log_file)
    console_handler = logging.StreamHandler()
    file_handler.setFormatter(formatter)
    console_handler.setFormatter(formatter)

    LOGGER.addHandler(file_handler)
    LOGGER.addHandler(console_handler)
    return LOGGER 
Example #11
Source File: filemap.py    From neuropythy with GNU Affero General Public License v3.0 6 votes vote down vote up
def __init__(self, tarpath, basepath='', cache_path=None, tarball_name=None):
        OSPath.__init__(self, basepath, cache_path=cache_path)
        object.__setattr__(self, 'tarball_path', tarpath)
        object.__setattr__(self, 'base_path', basepath)
        if cache_path == tarpath:
            # we need to prep the path
            tarfl = os.path.split(tarpath)[1]
            cpath = os.path.join(cache_path, 'contents')
            tarpath = os.path.join(cache_path, tarfl)
            if os.path.isfile(cache_path):
                # we need to move things around
                td = tmpdir(delete=True)
                tmpfl = os.path.join(td,tarfl)
                shutil.move(cache_path, tmpfl)
                if not os.path.isdir(cpath): os.makedirs(cpath, mode=0o755)
                shutil.move(tmpfl, tarpath)
            object.__setattr__(self, 'tarball_path', tarpath)
            object.__setattr__(self, 'cache_path', cpath)
        # get the tarball 'name'
        flnm = os.path.split(self.tarball_path if tarball_name is None else tarball_name)[-1]
        tarball_name = flnm.split('.tar')[0]
        object.__setattr__(self, 'tarball_name', tarball_name) 
Example #12
Source File: angrysearch.py    From ANGRYsearch with GNU General Public License v2.0 6 votes vote down vote up
def replace_old_db_with_new(self):
        global con
        global DATABASE_PATH

        temp_db_path = TEMP_PATH + '/angry_database.db'

        dir_path = os.path.dirname(DATABASE_PATH)

        if not os.path.exists(temp_db_path):
            return
        if not os.path.exists(dir_path):
            os.makedirs(dir_path)

        if con:
            con.close()
        shutil.move(temp_db_path, DATABASE_PATH)

        con = sqlite3.connect(DATABASE_PATH, check_same_thread=False)
        con.create_function("regexp", 2, regexp) 
Example #13
Source File: utils.py    From pySmartDL with The Unlicense 6 votes vote down vote up
def combine_files(parts, dest, chunkSize = 1024 * 1024 * 4):
	'''
	Combines files.

	:param parts: Source files.
	:type parts: list of strings
	:param dest: Destination file.
	:type dest: string
    :param chunkSize: Fetching chunk size.
	:type chunkSize: int

	'''
	if len(parts) == 1:
		shutil.move(parts[0], dest)
	else:
		with open(dest, 'wb') as output:
			for part in parts:
				with open(part, 'rb') as input:
					data = input.read(chunkSize)
					while data:
						output.write(data)
						data = input.read(chunkSize)
				os.remove(part) 
Example #14
Source File: epr.py    From epr with MIT License 6 votes vote down vote up
def loadstate():
    global STATE, STATEFILE
    if os.getenv("HOME") is not None:
        STATEFILE = os.path.join(os.getenv("HOME"), ".epr")
        if os.path.isdir(os.path.join(os.getenv("HOME"), ".config")):
            configdir = os.path.join(os.getenv("HOME"), ".config", "epr")
            os.makedirs(configdir, exist_ok=True)
            if os.path.isfile(STATEFILE):
                if os.path.isfile(os.path.join(configdir, "config")):
                    os.remove(os.path.join(configdir, "config"))
                shutil.move(STATEFILE, os.path.join(configdir, "config"))
            STATEFILE = os.path.join(configdir, "config")
    elif os.getenv("USERPROFILE") is not None:
        STATEFILE = os.path.join(os.getenv("USERPROFILE"), ".epr")
    else:
        STATEFILE = os.devnull

    if os.path.exists(STATEFILE):
        with open(STATEFILE, "r") as f:
            STATE = json.load(f) 
Example #15
Source File: api.py    From d6tpipe with MIT License 6 votes vote down vote up
def move_repo(self, path):
        """

        Moves all files to another location and updates the config

        Args:
            path (pathlib.Path):

        Returns:
            bool:

        """

        Path(path).mkdir(parents=True, exist_ok=True)
        shutil.move(self.filerepo,path)
        self.configmgr.update({'filerepo': path})
        print('Moved repo to {}. Reloading api'.format(path))
        self.__init__(profile=self.profile, filecfg=self.cfg_filecfg)

        return True 
Example #16
Source File: template.py    From misp42splunk with GNU Lesser General Public License v3.0 6 votes vote down vote up
def _compile_module_file(template, text, filename, outputpath, module_writer):
    source, lexer = _compile(
        template, text, filename, generate_magic_comment=True
    )

    if isinstance(source, compat.text_type):
        source = source.encode(lexer.encoding or "ascii")

    if module_writer:
        module_writer(source, outputpath)
    else:
        # make tempfiles in the same location as the ultimate
        # location.   this ensures they're on the same filesystem,
        # avoiding synchronization issues.
        (dest, name) = tempfile.mkstemp(dir=os.path.dirname(outputpath))

        os.write(dest, source)
        os.close(dest)
        shutil.move(name, outputpath) 
Example #17
Source File: pipe.py    From d6tpipe with MIT License 6 votes vote down vote up
def import_files(self, files, subdir=None, move=False):
        """

        Import files to repo

        Args:
            files (list): list of files, eg from `glob.iglob('folder/**/*.csv')`
            subdir (str): sub directory to import into
            move (bool): move or copy

        """
        dstdir = self.dirpath/subdir if subdir else self.dirpath
        dstdir.mkdir(parents=True, exist_ok=True)
        if move:
            [shutil.move(ifile,dstdir/Path(ifile).name) for ifile in files]
        else:
            [shutil.copy(ifile,dstdir/Path(ifile).name) for ifile in files] 
Example #18
Source File: local.py    From S4 with GNU General Public License v3.0 6 votes vote down vote up
def put(self, key, sync_object, callback=None):
        path = os.path.join(self.path, key)
        self.ensure_path(path)

        BUFFER_SIZE = 4096
        fd, temp_path = tempfile.mkstemp()

        try:
            with open(temp_path, "wb") as fp_1:
                while True:
                    data = sync_object.fp.read(BUFFER_SIZE)
                    fp_1.write(data)
                    if callback is not None:
                        callback(len(data))
                    if len(data) < BUFFER_SIZE:
                        break
            shutil.move(temp_path, path)
        except Exception:
            os.remove(temp_path)
            raise
        finally:
            os.close(fd)

        self.set_remote_timestamp(key, sync_object.timestamp) 
Example #19
Source File: files.py    From pysploit-framework with GNU General Public License v2.0 6 votes vote down vote up
def move(src,dst):
    if type(src) == list:
        if type(dst) == list:
            try:
                for i in range(0,10000000):
                    if os.path.isfile(src[i]):
                        shutil.move(src[i], dst[i])
                    else:
                        shutil.copytree(src[i], dst[i]+'/'+src[i])
                        shutil.rmtree(src[i])
            except IndexError:
                pass
        else:
            for src_el in src:
                if os.path.isfile(src_el):
                    shutil.move(src_el,dst)
                else:
                    shutil.copytree(src_el,dst+'/'+src_el)
                    shutil.rmtree(src_el)
    else:
        if os.path.isfile(src):
            shutil.move(src,dst)
        else:
            shutil.copytree(src,dst+'/'+src)
            shutil.rmtree(src) 
Example #20
Source File: storage.py    From plugin.video.kmediatorrent with GNU General Public License v3.0 6 votes vote down vote up
def sync(self):
        '''Write the dict to disk'''
        if self.flag == 'r':
            return
        filename = self.filename
        tempname = filename + '.tmp'
        fileobj = open(tempname, 'wb' if self.file_format == 'pickle' else 'w')
        try:
            self.dump(fileobj)
        except Exception:
            os.remove(tempname)
            raise
        finally:
            fileobj.close()
        shutil.move(tempname, self.filename)    # atomic commit
        if self.mode is not None:
            os.chmod(self.filename, self.mode) 
Example #21
Source File: app.py    From llvm-zorg with Apache License 2.0 6 votes vote down vote up
def save_status(self):
        install_path = self.config["INSTALL_PATH"]
        data_path = os.path.join(install_path, "lab-status.json.new")
        file = open(data_path, 'w')
        flask.json.dump(self.config.status.todata(), file, indent=2)
        print >>file
        file.close()

        # Backup the current status.
        backup_path = os.path.join(install_path, "lab-status.json.bak")
        status_path = os.path.join(install_path, "lab-status.json")
        try:
            os.remove(backup_path)
        except:
            pass
        if os.path.exists(status_path):
            shutil.move(status_path, backup_path)
        shutil.move(data_path, status_path) 
Example #22
Source File: download.py    From lineflow with MIT License 6 votes vote down vote up
def cache_or_load_file(path, creator, loader):
    if os.path.exists(path):
        return loader(path)

    try:
        os.makedirs(_cache_root)
    except OSError:
        if not os.path.isdir(_cache_root):
            raise RuntimeError('cannot create cache directory')

    with tempdir() as temp_dir:
        filename = os.path.basename(path)
        temp_path = os.path.join(temp_dir, filename)
        content = creator(temp_path)
        if not os.path.exists(path):
            shutil.move(temp_path, path)

    return content 
Example #23
Source File: document.py    From toonapilib with MIT License 6 votes vote down vote up
def document():
    bootstrap()
    clean_up(('_build',
              os.path.join('docs', '_build'),
              os.path.join('docs', 'test_docs.rst'),
              os.path.join('docs', 'modules.rst')))
    success = execute_command('make -C docs html')
    if success:
        shutil.move(os.path.join('docs', '_build'), '_build')
        try:
            open_file(os.path.join('_build', 'html', 'index.html'))
        except Exception:
            LOGGER.warning('Could not execute UI portion. Maybe running headless?')
        LOGGER.info('%s Successfully built documentation %s',
                    emojize(':white_heavy_check_mark:'),
                    emojize(':thumbs_up:'))
    else:
        LOGGER.error('%s Documentation creation errors found! %s',
                     emojize(':cross_mark:'),
                     emojize(':crying_face:'))
    raise SystemExit(0 if success else 1) 
Example #24
Source File: examples.py    From simnibs with GNU General Public License v3.0 6 votes vote down vote up
def replace_gmsh():
    fn_gmsh = path2bin('gmsh')
    fn_gmsh_tmp = path2bin('gmsh_tmp')
    # move
    shutil.move(fn_gmsh, fn_gmsh_tmp)
    # replace
    if sys.platform == 'win32':
        fn_script = fn_gmsh[:4] + '.cmd'
        with open(fn_script, 'w') as f:
            f.write('echo "GMSH"')
    else:
        with open(fn_gmsh, 'w') as f:
            f.write('#! /bin/bash -e\n')
            f.write(f'"echo" "$@"')
        os.chmod(
            fn_gmsh,
            os.stat(fn_gmsh).st_mode |
            stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
        )
    yield
    shutil.move(fn_gmsh_tmp, fn_gmsh) 
Example #25
Source File: examples.py    From simnibs with GNU General Public License v3.0 6 votes vote down vote up
def replace_show_surface():
    fn_orig = os.path.abspath(
        os.path.join(
            os.path.dirname(__file__),
            '..', '..', 'matlab',
            'mesh_show_surface.m'
        )
    )
    fn_tmp = fn_orig + '.bk'
    shutil.move(fn_orig, fn_tmp)
    # replace
    with open(fn_orig, 'w') as f:
        f.write('function varargout = mesh_show_surface(m, varargin)\n')
        f.write('end')
    yield
    shutil.move(fn_tmp, fn_orig) 
Example #26
Source File: postinstall_simnibs.py    From simnibs with GNU General Public License v3.0 6 votes vote down vote up
def download_extra_coils(timeout=None):
    version = 'master'
    url = f'https://github.com/simnibs/simnibs-coils/archive/{version}.zip'
    with tempfile.NamedTemporaryFile('wb', delete=False) as tmpf:
        tmpname = tmpf.name
    reporthook = functools.partial(_download_manager, start_time=time.time(), timeout=timeout)
    urllib.request.urlretrieve(url, tmpf.name, reporthook=reporthook)
    with zipfile.ZipFile(tmpname) as z:
        z.extractall(os.path.join(SIMNIBSDIR, 'ccd-files'))
    os.remove(tmpname)
    src = os.path.join(SIMNIBSDIR, 'ccd-files', f'simnibs-coils-{version}')
    dest = os.path.join(SIMNIBSDIR, 'ccd-files')
    for f in glob.glob(os.path.join(src, '*')):
        d = os.path.join(dest, os.path.basename(f))
        if os.path.isdir(d):
            shutil.rmtree(d)
        if os.path.isfile(d):
            os.remove(d)
        shutil.move(f, d)
    shutil.rmtree(
        os.path.join(SIMNIBSDIR, 'ccd-files', f'simnibs-coils-{version}')) 
Example #27
Source File: release.py    From sanic-prometheus with MIT License 6 votes vote down vote up
def update_changelog(version, msg):
    today = datetime.date.today()
    wfh = open('CHANGELOG.rst.tmp', 'w')
    try:
        lines_count = 0
        for line in open('CHANGELOG.rst', 'r'):
            lines_count += 1
            if lines_count == 4:
                wfh.write(f'Version {version} (on {today: %b %d %Y})\n')
                wfh.write('-------------------------------\n')
                wfh.write(f'* {msg}')
                wfh.write('\n\n')
            wfh.write(line)
    finally:
        wfh.close()
        shutil.move('CHANGELOG.rst.tmp', 'CHANGELOG.rst') 
Example #28
Source File: Radiumkeylogger.py    From Radium with Apache License 2.0 6 votes vote down vote up
def MoveAttachments(f_name):
    arch_name = "C:\Users\Public\Intel\Logs\\" + f_name
    if f_name == 'Screenshots':
        files = os.listdir(arch_name)
        try:
            for i in range(10):
                try:
                    shutil.move(arch_name + "\\" + files[i], dir_zip)
                except Exception as e:
                    print e
        except Exception as e:
            print e
    else:
        try:
            shutil.move(arch_name, dir_zip)
        except Exception as e:
            print e

#Function to zip the files 
Example #29
Source File: template.py    From misp42splunk with GNU Lesser General Public License v3.0 6 votes vote down vote up
def _compile_module_file(template, text, filename, outputpath, module_writer):
    source, lexer = _compile(
        template, text, filename, generate_magic_comment=True
    )

    if isinstance(source, compat.text_type):
        source = source.encode(lexer.encoding or "ascii")

    if module_writer:
        module_writer(source, outputpath)
    else:
        # make tempfiles in the same location as the ultimate
        # location.   this ensures they're on the same filesystem,
        # avoiding synchronization issues.
        (dest, name) = tempfile.mkstemp(dir=os.path.dirname(outputpath))

        os.write(dest, source)
        os.close(dest)
        shutil.move(name, outputpath) 
Example #30
Source File: prepare_dota1_aug.py    From AerialDetection with Apache License 2.0 5 votes vote down vote up
def singel_move(src_dst_tuple):
    shutil.move(*src_dst_tuple)