-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
限制程序只有一个下载进程的改动
houtianze edited this page Feb 15, 2015
·
1 revision
我的小linux服务器每分钟检查一次网盘里是否有新文件,如果有就开始下载,这样就有一个问题:如果正在下的文件很大,比如说电影,下载时又启动了一个新进程。 因此需要增加进程检查的功能。
def syncdown(self, remotedir = '', localdir = '', deletelocal = False):
''' Usage: syncdown [remotedir] [localdir] [deletelocal] - \
sync down from the remote direcotry to the local directory
remotedir - the remote directory at Baidu Yun (after app's direcotry) to sync from. \
if not specified, it defaults to the root directory
localdir - the local directory to sync to if not specified, it defaults to the current directory.
deletelocal - delete local files that are not inside Baidu Yun direcotry, default is False
'''
pid = str(os.getpid()) #新增
pidfile = "/var/bypy.pid" #新增
if os.path.isfile(pidfile): #新增
print "%s already exists, exiting" % pidfile #新增
sys.exit() #新增
else: #新增
file(pidfile, 'w').write(pid) #新增
result = ENoError
rpath = get_pcs_path(remotedir)
. . . .
elif os.path.isdir(p):
subresult = removedir(p, self.Verbose)
if subresult != ENoError:
result = subresult
os.unlink(pidfile) #新增
return result
`
只改了syncdown