Python守护进程来观察文件夹和更新数据库 [英] Python daemon to watch a folder and update a database

查看:294
本文介绍了Python守护进程来观察文件夹和更新数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是专门用于管理MP3文件,但它应该很容易适用于任何目录结构与很多文件。

This is specifically geared towards managing MP3 files, but it should easily work for any directory structure with a lot of files.

我想找到或写一个守护进程(最好在Python中),它将观察一个包含许多子文件夹的文件夹,这些子文件夹应该都包含X个MP3文件。任何时候一个文件被添加,更新或删除,它应该反映在数据库(最好是PostgreSQL)。我愿意接受如果一个文件被简单地移动,相应的行被删除和重新创建,但更新现有的行将使我最幸福。

I want to find or write a daemon (preferably in Python) that will watch a folder with many subfolders that should all contain X number of MP3 files. Any time a file is added, updated or deleted, it should reflect that in a database (preferably PostgreSQL). I am willing to accept if a file is simply moved that the respective rows are deleted and recreated anew but updating existing rows would make me the happiest.

Stack Overflow问题 管理大量音乐收藏 有一点点我想要的。

The Stack Overflow question Managing a large collection of music has a little of what I want.

我基本上只是想要一个数据库,然后我可以做任何我想要的。我现在最新的数据库是我的 iTunes.xml 文件,但我不想依赖太多,因为我不总是想依靠iTunes来进行音乐管理。我看到很多项目,有一些我想要的,但在一种格式,我无法访问或只是比我想要的更复杂。如果有一些媒体播放器可以观看一个文件夹,并更新一个容易访问的数据库,那么我都是为它。

I basically just want a database that I can then do whatever I want to with. My most up-to-date database as of now is my iTunes.xml file, but I don't want to rely on that too much as I don't always want to rely on iTunes for my music management. I see plenty of projects out there that do a little of what I want but in a format that either I can't access or is just more complex than I want. If there is some media player out there that can watch a folder and update a database that is easily accessible then I am all for it.

我倾向于

推荐答案

另一个答案已经建议 pyinotify for Linux,让我添加 watch_directory (对于Windows中的可能性的一个很好的讨论是此处,该模块的示例)和 fsevents (不幸的是,我不认为有一个单一的跨平台模块提供了一个统一的接口,以获得目录更改通知事件的各种系统特定的方式)。

Another answer already suggested pyinotify for Linux, let me add watch_directory for Windows (a good discussion of the possibilities in Windows is here, the module's an example) and fsevents on the Mac (unfortunately I don't think there's a single cross-platform module offering a uniform interface to these various system-specific ways to get directory-change notification events).

一旦你设法得到这样的事件,更新一个合适的SQL数据库很简单!)

Once you manage to get such events, updating an appropriate SQL database is simple!-)

这篇关于Python守护进程来观察文件夹和更新数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆