• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python send2trash.send2trash函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中send2trash.send2trash函数的典型用法代码示例。如果您正苦于以下问题:Python send2trash函数的具体用法?Python send2trash怎么用?Python send2trash使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了send2trash函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: remove

    def remove(self, force=False):
        """
        Removes the Container of Applications (dmgs, zips, pkgs).

        This method can only be called after install() has run succesfully.

        Args:
            force: If set, Installable will be removed even if it has not been
                installed. Defaults to 'False'

        Raises:
            NotInstalledException: If Installable().install has not been called
                successfully and force is 'False'
        """

        if not self.installed and not force:
            logger.debug("Cant remove %s!" % self)
            raise NotInstalledException()

        try:
            send2trash.send2trash(self.path)
            self.removed = True
            logger.info("Moved %s to trash." % self)
        except OSError as ose:
            logger.exception(ose)
开发者ID:laerador,项目名称:dmginstall,代码行数:25,代码来源:install.py


示例2: execute_repair

	def execute_repair(self):
		repairedfiles=[]
		recreatedfiles=[]
		if self.len_verified_actions>0:
			for f,retcode in self.verifiedfiles_repairable:
				yield f
				retval = self.runpar([self.par_cmd,"r",f])
				if retval == 0:
					if not self.keep_old and os.path.isfile(f+".1"):
						send2trash(f+".1")
					repairedfiles.append([ f , retval ])
			for f,retcode in self.verifiedfiles_err:
				yield f
				pars = glob.glob(glob.escape(f)+'*.par2')
				for p in pars:
					send2trash(p)
				recreatedfiles.append([ f , self.runpar([self.par_cmd,"c","-r"+self.percentage,"-n"+self.nr_parfiles,f]) ])

		self.recreate = sorted(recreatedfiles)
		self.recreate_err = sorted([f for f,err in recreatedfiles if err !=0])
		self.fixes = sorted([f for f,err in repairedfiles if err ==0])
		self.fixes_err = sorted([f for f,err in repairedfiles if err !=0])

		self.len_all_err = self.len_all_err + len(self.recreate_err) + len(self.fixes_err)

		return
开发者ID:brenthuisman,项目名称:par2deep,代码行数:26,代码来源:par2deep.py


示例3: deleteLocalFile

 def deleteLocalFile(self, localPath, remotePath):
     #logging.warn('delete local file %s' % localPath)
     head, tail = os.path.split(localPath)
     self.outputQueue.put(messages.Status('Deleting %s' % tail))
     send2trash(localPath)
     self.state.removeObjectSyncRecord(remotePath)
     self.outputQueue.put(self._get_working_message())
开发者ID:Sybrand,项目名称:digital-panda,代码行数:7,代码来源:upload.py


示例4: run

 def run(self, dirs):
     if sublime.ok_cancel_dialog("Delete Folder?", "Delete"):
         try:
             for d in dirs:
                 send2trash.send2trash(d)
         except:
             sublime.status_message("Unable to delete folder")
开发者ID:40a,项目名称:Chocolatey-Packages,代码行数:7,代码来源:side_bar.py


示例5: import_file

def import_file(_file, destination, album_from_folder, trash, allow_duplicates):
    """Set file metadata and move it to destination.
    """
    if not os.path.exists(_file):
        log.warn('Could not find %s' % _file)
        print('{"source":"%s", "error_msg":"Could not find %s"}' % \
            (_file, _file))
        return
    # Check if the source, _file, is a child folder within destination
    elif destination.startswith(os.path.dirname(_file)):
        print('{"source": "%s", "destination": "%s", "error_msg": "Source cannot be in destination"}' % (_file, destination))
        return


    media = Media.get_class_by_file(_file, [Text, Audio, Photo, Video])
    if not media:
        log.warn('Not a supported file (%s)' % _file)
        print('{"source":"%s", "error_msg":"Not a supported file"}' % _file)
        return

    if album_from_folder:
        media.set_album_from_folder()

    dest_path = FILESYSTEM.process_file(_file, destination,
        media, allowDuplicate=allow_duplicates, move=False)
    if dest_path:
        print('%s -> %s' % (_file, dest_path))
    if trash:
        send2trash(_file)

    return dest_path or None
开发者ID:jmathai,项目名称:elodie,代码行数:31,代码来源:elodie.py


示例6: backup

    def backup(self):
        nbacks = self.pm.profile['numBackups']
        if not nbacks or devMode:
            return
        dir = self.pm.backupFolder()
        path = self.pm.collectionPath()

        # do backup
        fname = time.strftime("backup-%Y-%m-%d-%H.%M.%S.apkg", time.localtime(time.time()))
        newpath = os.path.join(dir, fname)
        data = open(path, "rb").read()
        b = self.BackupThread(newpath, data)
        b.start()

        # find existing backups
        backups = []
        for file in os.listdir(dir):
            # only look for new-style format
            m = re.match("backup-\{4}-.+.apkg", file)
            if not m:
                continue
            backups.append(file)
        backups.sort()

        # remove old ones
        while len(backups) > nbacks:
            fname = backups.pop(0)
            path = os.path.join(dir, fname)
            send2trash(path)
开发者ID:jdennis,项目名称:anki,代码行数:29,代码来源:main.py


示例7: backup

 def backup(self):
     nbacks = self.pm.profile['numBackups']
     if not nbacks:
         return
     dir = self.pm.backupFolder()
     path = self.pm.collectionPath()
     # find existing backups
     backups = []
     for file in os.listdir(dir):
         m = re.search("backup-(\d+).apkg", file)
         if not m:
             # unknown file
             continue
         backups.append((int(m.group(1)), file))
     backups.sort()
     # get next num
     if not backups:
         n = 1
     else:
         n = backups[-1][0] + 1
     # do backup
     newpath = os.path.join(dir, "backup-%d.apkg" % n)
     z = zipfile.ZipFile(newpath, "w", zipfile.ZIP_DEFLATED)
     z.write(path, "collection.anki2")
     z.writestr("media", "{}")
     z.close()
     # remove if over
     if len(backups) + 1 > nbacks:
         delete = len(backups) + 1 - nbacks
         delete = backups[:delete]
         for file in delete:
             send2trash(os.path.join(dir, file[1]))
开发者ID:gbraad,项目名称:anki,代码行数:32,代码来源:main.py


示例8: clean_empty_dirs

def clean_empty_dirs():
    #print 'cleaning dirs...'
    def get_subdirs(path):
        for root, dirs, files in os.walk(path):
            return [os.path.join(root, x) for x in dirs]
        return []

    def has_subs(path):
        for root, dirs, files in os.walk(path):
            files = [x for x in files if not x.startswith('.')]
            return len(dirs)+len(files) != 0
        return False

    for show_dir in get_subdirs(tv_shows_dir):
        for subdir in get_subdirs(show_dir):
            if not has_subs(subdir):
                #print 'removing directory',subdir
                if not DEBUG:
                    send2trash(subdir)
                continue
            for subdir2 in get_subdirs(subdir):
                if not has_subs(subdir2):
                    #print 'removing directory',subdir2
                    if not DEBUG:
                        send2trash(subdir2)
开发者ID:vackraord,项目名称:CMi,代码行数:25,代码来源:sort_eps.py


示例9: delete_file

    def delete_file(self, path):
        """Delete file at path."""
        path = path.strip('/')
        os_path = self._get_os_path(path)
        rm = os.unlink
        if os.path.isdir(os_path):
            listing = os.listdir(os_path)
            # Don't delete non-empty directories.
            # A directory containing only leftover checkpoints is
            # considered empty.
            cp_dir = getattr(self.checkpoints, 'checkpoint_dir', None)
            for entry in listing:
                if entry != cp_dir:
                    raise web.HTTPError(400, u'Directory %s not empty' % os_path)
        elif not os.path.isfile(os_path):
            raise web.HTTPError(404, u'File does not exist: %s' % os_path)

        if self.delete_to_trash:
            self.log.debug("Sending %s to trash", os_path)
            # Looking at the code in send2trash, I don't think the errors it
            # raises let us distinguish permission errors from other errors in
            # code. So for now, just let them all get logged as server errors.
            send2trash(os_path)
            return

        if os.path.isdir(os_path):
            self.log.debug("Removing directory %s", os_path)
            with self.perm_to_403():
                shutil.rmtree(os_path)
        else:
            self.log.debug("Unlinking file %s", os_path)
            with self.perm_to_403():
                rm(os_path)
开发者ID:gnestor,项目名称:notebook,代码行数:33,代码来源:filemanager.py


示例10: _send_path_to_trash

 def _send_path_to_trash(self, local_item_name, local_path):
     try:
         send2trash(local_path)
         self.items_store.delete_item(item_name=local_item_name, parent_path=self.remote_path)
         self.logger.debug('Delete untouched local item "%s" as it seems deleted remotely.', local_path)
     except (IOError, OSError) as e:
         self.logger.error('An error occurred when deleting untouched local item "%s": %s.', local_path, e)
开发者ID:GitGrezly,项目名称:onedrive-d,代码行数:7,代码来源:merge_task.py


示例11: run

  def run(self, edit):        
    f = self.view.file_name()
    if (f is None):
      return

    send2trash.send2trash(f)
    self.view.window().run_command('close')
开发者ID:nottombrown,项目名称:DeleteCurrentFile,代码行数:7,代码来源:DeleteCurrentFile.py


示例12: remove

 def remove(self, name):
     p = self.profileFolder()
     if os.path.exists(p):
         send2trash(p)
     self.db.execute("delete from profiles where name = ?",
                     name.encode("utf8"))
     self.db.commit()
开发者ID:chajadan,项目名称:anki,代码行数:7,代码来源:profiles.py


示例13: check_recycle

def check_recycle(name, verbose=True):
    """ 
    places old file in recycle bin, if it exists.
    this should work for any system, but requires the send2trash module
    (see https://pypi.python.org/pypi/Send2Trash)
    
    input: 
        name    = file name, with extension (must be in current working dir)
        verbose = optional input (default=True) which will print messages
                  to the command window
    """
    # import send2trash module:
    # it's bad practice to import within a function, but the use of
    # check_recycle is optional, since check_delete exists. Thus, I don't
    # want the import of myFileOperations to break simply because someone
    # does not have the optional send2trash module installed...
    from send2trash import send2trash

    if verbose:
        try:
            send2trash(name)
            print "\nold file sent to recycle bin"
            print 'saving new "%s"\n' % (name)
        except:
            print '\nno file found, saving new file "%s"\n' % (name)
    else:
        try:
            send2trash(name)
        except:
            pass
开发者ID:ucdavis-kanvinde-group,项目名称:abaqus-odb-tools,代码行数:30,代码来源:myFileOperations.py


示例14: remove_file

    def remove_file(self, file, message):
        to_trash = get_setting(self.window.active_view(), 'jekyll_send_to_trash', False)

        if to_trash:
            message = message + (
                '\n\nYou seem to be using the `jekyll_send_to_trash` setting, so you '
                'can retrieve this file later in your system Trash or Recylcing Bin.'
            )
        else:
            message = message + (
                '\n\nThis action is permanent and irreversible since you are not using '
                'the `jekyll_send_to_trash` setting. Are you sure you want to continue?'
            )

        delete = sublime.ok_cancel_dialog(message, 'Confirm Delete')

        if delete is True:
            self.window.run_command('close_file')
            self.window.run_command('refresh_folder_list')

            if to_trash:
                send2trash(file)

            else:
                os.remove(file)

        else:
            return
开发者ID:nighthawk,项目名称:sublime-jekyll,代码行数:28,代码来源:jekyll.py


示例15: deleteFile

def deleteFile(path):
    for foldername, subfolders, filenames in os.walk(path):
        for filename in filenames:
            filePath = os.path.join(foldername, filename)
            if os.path.getsize(filePath) > MaxSize:
                print(filename + " is more than 100MB")
                send2trash.send2trash(filePath)
开发者ID:tramxme,项目名称:Automate_Python,代码行数:7,代码来源:DeletingUnneededFiles.py


示例16: run

	def run(self, paths = [], confirmed = 'False'):
		print '--------------'
		print 'deleting paths'
		print paths
		print 'confirmed'
		print confirmed
		if confirmed == 'False' and s.get('confirm_before_deleting', True):
			print 'confirmed == False and confirm_before_deleting == True'
			self.confirm([item.path() for item in SideBarSelection(paths).getSelectedItems()], [item.pathWithoutProject() for item in SideBarSelection(paths).getSelectedItems()])
		else:
			print 'trying send to trash'
			try:
				for item in SideBarSelection(paths).getSelectedItemsWithoutChildItems():
					if s.get('close_affected_buffers_when_deleting_even_if_dirty', False):
						item.close_associated_buffers()
						print 'closed associated buffers'
					print 'send2trash'
					send2trash(item.path())
				SideBarProject().refresh();
				print 'file deleted'
				print 'file exists?'+str(os.path.exists(item.path()))
			except:
				print 'something failed'
				print 'trying Permanent deletion'
				import functools
				self.window.run_command('hide_panel');
				self.window.show_input_panel("Permanently Delete:", SideBarSelection(paths).getSelectedItems()[0].path(), functools.partial(self.on_done, SideBarSelection(paths).getSelectedItems()[0].path()), None, None)
开发者ID:aokolovskis,项目名称:config,代码行数:27,代码来源:SideBar.py


示例17: extensionchange

def extensionchange():
    global numExfilFiles, numFiles, dT, eD,gpath
    currentFile=0
    while currentFile<=numFiles:
        shutil.copy2(gpath+"\\"+str(currentFile)+"combinedExfil.txt", gpath+"\\X"+str(currentFile)+"combinedExfil.txt.wav")#There are modules for reading wav files, have not added wav exfil support if reading file is required
        send2trash(gpath+"\\"+str(currentFile)+"combinedExfil.txt")
    numExfilFiles=numFiles
开发者ID:DhvanilN,项目名称:Prototype,代码行数:7,代码来源:Prototype.py


示例18: main

def main(root_path):
    for root, dirs, files in os.walk(root_path):
        log_info('Processing Path ' + root)
        for file in files:
            process_file(root +'/' + file)
    if delete_invalid_archives and len(files_to_delete) > 0:
        sys.stdout.write('\n' + '*' * 80)
        sys.stdout.write('\n* WARNING THE FOLLOWING FILES WILL BE DELETED:')
        sys.stdout.write('\n' + '*' * 80)
        for file_name in files_to_delete:
            sys.stdout.write('\n* WARNING: Ready to DELETE'+ file_name)
        sys.stdout.write('\n' + '*' * 80)
        sys.stdout.write('\n')
        answer = query_yes_no('DELETE ALL ' + str(len(files_to_delete)) + ' (APPARENTLY) INVALID FILES?', default="no")  
        if answer:
            try:
                import send2trash
            except ImportError:
                send2trash_available = False
            else:
                send2trash_available = True
            if send2trash_available and query_yes_no('Send to trash', default="yes"):
                for file_name in files_to_delete:
                    log_info('Sending to Trash ' + file_name)
                    send2trash.send2trash(file_name)
            else:
                for file_name in files_to_delete:
                    log_info('DELETING! ' + file_name)
                    os.remove(file_name)
        else:     
            log_info('NO file deletion has occurred')
    
    sys.stdout.write("\nStephen's Archive Re-Touch Utility Complete\n")
开发者ID:StephenGenusa,项目名称:touch-archive-datetime,代码行数:33,代码来源:touch_archives.py


示例19: delete

 def delete(self, ref):
     locker = self.unlock_ref(ref)
     os_path = self._abspath(ref)
     if not self.exists(ref):
         return
     # Remove the \\?\ for SHFileOperation on win
     if os_path[:4] == '\\\\?\\':
         # http://msdn.microsoft.com/en-us/library/cc249520.aspx
         # SHFileOperation don't handle \\?\ paths
         if len(os_path) > 260:
             # Rename to the drive root
             info = self.move(ref, '/')
             new_ref = info.path
             try:
                 send2trash(self._abspath(new_ref)[4:])
             except:
                 log.debug('Cant use trash for ' + os_path
                              + ', delete it')
                 self.delete_final(new_ref)
             return
         else:
             os_path = os_path[4:]
     log.trace('Send ' + os_path + ' to trash')
     try:
         send2trash(os_path)
     except:
         log.debug('Cant use trash for ' + os_path
                              + ', delete it')
         self.delete_final(ref)
     finally:
         # Dont want to unlock the current deleted
         self.lock_ref(ref, locker & 2)
开发者ID:Bindupriya,项目名称:nuxeo-drive,代码行数:32,代码来源:local_client.py


示例20: import_file

def import_file(_file, destination, album_from_folder, trash):
    """Set file metadata and move it to destination.
    """
    if not os.path.exists(_file):
        if constants.debug:
            print 'Could not find %s' % _file
        print '{"source":"%s", "error_msg":"Could not find %s"}' % \
            (_file, _file)
        return

    media = Media.get_class_by_file(_file, [Audio, Photo, Video])
    if not media:
        if constants.debug:
            print 'Not a supported file (%s)' % _file
        print '{"source":"%s", "error_msg":"Not a supported file"}' % _file
        return

    if media.__name__ == 'Video':
        FILESYSTEM.set_date_from_path_video(media)

    if album_from_folder:
        media.set_album_from_folder()

    dest_path = FILESYSTEM.process_file(_file, destination,
        media, allowDuplicate=False, move=False)
    if dest_path:
        print '%s -> %s' % (_file, dest_path)
    if trash:
        send2trash(_file)
开发者ID:noonat,项目名称:elodie,代码行数:29,代码来源:elodie.py



注:本文中的send2trash.send2trash函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sendMail.sendToMe函数代码示例发布时间:2022-05-27
下一篇:
Python semver.parse函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap