在Brive中保存文档时重写/作为_

时间:2013-01-17 16:20:02

标签: python google-drive-api

我下载了使用云端硬盘API下载您的Google文档的Brive。如果它有斜杠并且崩溃了应用程序,我遇到了文件名不能保存的问题。如何修改model.py文件以将/重写为_

model.py

brive.py

我想我只需要在第74行重写“file_name”或“path”。

backend.py

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'

1 个答案:

答案 0 :(得分:1)

您可以使用the_str.replace('/', '_')将其中的'/'转换为包含'_'的路径。