我下载了Brive,它使用 Drive API 下载您的 Google 文档。如果文件名有斜线并使应用程序崩溃,我会遇到文件名无法保存的问题。如何修改 model.py 文件以重写/
为_
?
我想我只需要在第 74 行重写“file_name”或“path”。
def save(self, user, document):
self._mkdir(user.login)
prefix = self._root_dir + user.login + os.sep
for file_name, content in document.contents.items():
path = prefix + file_name
Log.debug(u'Writing {}\'s {} to {}'.format(
user.login, document.title, path
))
f = open(path, 'w')
f.write(content)
f.close()
这是错误:
[ 2013-01-17 T 06:17:08 Z ] Saving coral.lopez's doc "Lunchbox Monster High 4/7/12" (id: 1GyiuKFZeargO8KfzKS5H9V3PVbgTJufw2PwLaILzRVw)
[ 2013-01-17 T 06:17:08 Z ] Unexpected shutdown, deleting /home/davidneudorfer/google_docs_backup/2013-01-17T061021Z/ folder
### Unexpected error when saving coral.lopez's documents (doc id: 1GyiuKFZeargO8KfzKS5H9V3PVbgTJufw2PwLaILzRVw) ###
Traceback (most recent call last):
File "brive.py", line 114, in <module>
main()
File "brive.py", line 92, in main
user.save_documents(backend)
File "/home/davidneudorfer/Brive/model.py", line 79, in save_documents
self._save_single_document(backend, document)
File "/home/davidneudorfer/Brive/model.py", line 105, in _save_single_document
backend.save(self, document)
File "/home/davidneudorfer/Brive/backend.py", line 78, in save
f = open(path, 'w')
IOError: [Errno 2] No such file or directory: u'/home/davidneudorfer/google_docs_backup/2013-01-17T061021Z/coral.lopez/Lunchbox Monster High 4/7/12_1GyiuKFZeargO8KfzKS5H9V3PVbgTJufw2PwLaILzRVw.odt'