


python version of imitation windows scheduled task tool_python
这篇文章主要介绍了python版本的仿windows计划任务工具,计划任务工具根据自己设定的具体时间,频率,命令等属性来规定所要执行的计划,当然功能不是很全大家可以补充
计划任务工具-windows
计划任务工具根据自己设定的具体时间,频率,命令等属性来规定所要执行的计划。
效果图
代码
# -*- coding: utf-8 -*- """ Module implementing App. """ from PyQt4.QtGui import QMainWindow from PyQt4.QtCore import pyqtSignature import time,os import QtUtil import shutil import time from v.Ui_App import Ui_MainWindow class App(QMainWindow, Ui_MainWindow): """ Class documentation goes here. """ def __init__(self, parent = None): """ Constructor """ QMainWindow.__init__(self, parent) self.setupUi(self) # 创建'res/command'文件夹 if os.path.exists('res/command'): pass else: os.mkdir('res/command') # self.startDate.textFromDateTime() @pyqtSignature("") def on_run_btn_clicked(self): """ 创建任务. """ # 在查询栏显示的内容 cmd = self.taskRun.toPlainText() # 构建'res/command/01.txt'文件 if not os.path.exists('res/command/01.txt'): m = open('res/command/01.txt','w') m.close() p = str(self.modifier.text()) # 判断日期是否正确 if self.endDate.text() <= self.startDate.text(): QtUtil.showOkDialog(self, u'日期出错', u'结束日期要大于开始日期') elif not p.isdigit(): QtUtil.showOkDialog(self, u'频率出错', u'运行频率必须为整数') else: # 如果任务条件不完整,则创建失败 if self.taskName.text()=='' or self.modifier.text()=='' or cmd=='': QtUtil.showOkDialog(self, u'创建失败', u'任务内容缺失') else: # 读取'res/command'下所有文件的文件名到filename for root, dirs, files in os.walk('res/command'): for file in files: filename = open('res/filename.txt','a') filename.write('/') # filename.truncate() filename.write(str(file)) filename.close() filename1 = open('res/filename.txt') fn = filename1.read() filename1.close() print fn print '/' + str(self.taskName.text()) + '.cmd' # 如果任务名在filename中能找到,则说明任务已经存在 if '/' + str(self.taskName.text()) + '.cmd' in fn: QtUtil.showOkDialog(self, u'创建失败', u'任务已存在') else: # 任务内容 if self.schedule.currentText() == 'monthly': print 'monthly' run = 'schtasks /create /tn '+ self.taskName.text() + ' /tr '+os.getcwd()+'/res/command/'+self.taskName.text()+'.bat /sc ' + self.schedule.currentText() + ' /d ' +self.modifier.text() + ' /m ' + self.month.currentText() + ' /st ' + self.timeEdit.text() + ' /sd ' + self.startDate.text() + ' /ed ' + self.endDate.text() elif self.schedule.currentText() == 'once': print 'once' run = 'schtasks /create /tn '+ self.taskName.text() + ' /tr '+os.getcwd()+'/res/command/'+self.taskName.text()+'.bat /sc ' + self.schedule.currentText() + ' /st ' + self.timeEdit.text() + ' /sd ' + self.startDate.text() if self.startDate.text() < time.strftime('%Y/%m/%d') or (self.timeEdit.text() <= time.strftime('%H:%M:%S') and self.startDate.text() == time.strftime('%Y/%m/%d')) : QtUtil.showOkDialog(self, u'时间错误', u'设置时间早于当前时间') return else: print 'not monthly' run = 'schtasks /create /tn '+ self.taskName.text() + ' /tr '+os.getcwd()+'/res/command/'+self.taskName.text()+'.bat /sc ' + self.schedule.currentText() + ' /mo ' +self.modifier.text() + ' /st ' + self.timeEdit.text() + ' /sd ' + self.startDate.text() + ' /ed ' + self.endDate.text() # 创建命令文件 fd = open('res/command/'+self.taskName.text()+'.bat','w') fd.write(cmd) fd.close() # 创建任务文件 f = open('res/command/'+self.taskName.text()+'.cmd','w') f.write(run) f.close() # 创建任务 os.system(os.getcwd()+'\\res\command\\'+str(self.taskName.text())+'.cmd') QtUtil.showOkDialog(self, u'创建成功', u'创建成功') @pyqtSignature("") def on_delete_btn_clicked(self): """ 删除任务. """ # 强制删除删除框内任务 x=os.system('schtasks /delete /tn '+str(self.taskDelete.text()).decode('gbk')+' /f') # 如果已经任务已经删除,则报任务不存在 if x==1: QtUtil.showOkDialog(self, u'删除失败', u'任务名错误或不存在该任务') else: os.remove('res/filename.txt') if os.path.exists('res/command/'+self.taskDelete.text()+'.cmd'): os.remove('res/command/'+str(self.taskDelete.text())+'.bat') os.remove('res/command/'+str(self.taskDelete.text())+'.cmd') # 读取'res/command'下所有文件的文件名到filename for root, dirs, files in os.walk('res/command'): for file in files: filename = open('res/filename.txt','a') filename.write('/') # filename.truncate() filename.write(str(file)) filename.close() filename1 = open('res/filename.txt') fn = filename1.read() filename1.close() # 删除任务,并删除命令文件与任务文件 QtUtil.showOkDialog(self, u'删除成功', u'删除成功') @pyqtSignature("") def on_query_btn_clicked(self): """ 查询任务. """ # 调整 936 为 437 美国编码,才可运行 os.system('chcp 437') # 查询任务 os.system('schtasks /query') # 在生成新log文件前先删除以前的log文件 if os.path.exists('res/log.txt'): os.remove('res/log.txt') # 遍历'res/command'的所有文件,将所有文件内容复制到log文件中 for root, dirs, files in os.walk('res/command'): for file in files: dir = str(root)+'/'+str(file) f = open(dir,'r') scripts = f.read() new_path_filename = 'res/log.txt' f = open(new_path_filename, 'a') f.write(scripts) f.write('\n') f.close() # 读取log文件 if os.path.exists('res/log.txt'): fd=open('res/log.txt') info = fd.read() fd.close() # 在查询窗口显示log文件内容 self.taskQuery.setText(str(info)) else: QtUtil.showOkDialog(self, u'失败', u'不存在任务') @pyqtSignature("") def on_delall_btn_clicked(self): """ 清空任务. """ os.system('schtasks /delete /tn * /f') if os.path.exists('res/log.txt'): os.remove('res/log.txt') if os.path.exists('res/filename.txt'): os.remove('res/filename.txt') shutil.rmtree('res/command') os.mkdir('res/command') QtUtil.showOkDialog(self, u'成功', u'任务清空')
“任务名称”填写任务的名字,计划类型选择时间,频率填写次数,在计划类型中除了monthly之外的其他类型都填写频率,monthly时日期填写日期号数,月份也只在选择monthly时候需要选择,其他时候不用选择,月份中*号问任意月,接着填写开始时间、开始日期、结束日期,结束日期要大于开始日期,最后填写所要执行的命令,则任务创建成功。,创建任务后随时可以查阅任务,点击查询任务即可,删除任务只要填上要删除的任务名称,点击删除任务即可,清空任务为删除所有任务。
The above is the detailed content of python version of imitation windows scheduled task tool_python. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Golang is better than Python in terms of performance and scalability. 1) Golang's compilation-type characteristics and efficient concurrency model make it perform well in high concurrency scenarios. 2) Python, as an interpreted language, executes slowly, but can optimize performance through tools such as Cython.

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

In Laravel development, dealing with complex model relationships has always been a challenge, especially when it comes to multi-level BelongsToThrough relationships. Recently, I encountered this problem in a project dealing with a multi-level model relationship, where traditional HasManyThrough relationships fail to meet the needs, resulting in data queries becoming complex and inefficient. After some exploration, I found the library staudenmeir/belongs-to-through, which easily installed and solved my troubles through Composer.

Python is better than C in development efficiency, but C is higher in execution performance. 1. Python's concise syntax and rich libraries improve development efficiency. 2.C's compilation-type characteristics and hardware control improve execution performance. When making a choice, you need to weigh the development speed and execution efficiency based on project needs.
