在ubuntu上使用onedrive

linux,ubuntu 2019-12-21 5504 次浏览 次点赞


在ubuntu上使用onedrive

自从使用了onedrive过后就像发现宝贝似得,跨机器自动同步文件很是方便,特别是一些正在进行调试笔记、开发文档。所以在ubuntu也马上考虑使用onedrive。

I. dependences

通过apt安装如下依赖工具包。

# Install gcc and other C-level pre-requisites.
$ sudo apt-get install build-essential python3-dev libssl-dev inotify-tools python3-dbus
  • gcc
  • python3-dev

    $ python3 --version
    Python 3.5.2
  • libssl-dev
  • inotify-tools
  • python3-dbus (or probably libdbus-glib-1-dev)

安装pip3和setuptools。

# Download pip installation script from official site using wget.
$ wget -O- https://bootstrap.pypa.io/get-pip.py | sudo python3
# Upgrade the components (e.g., setuptools) to latest version.
$ sudo pip3 install -U pip setuptools

同时还需要手动下载ngrok,解压后导出环境变量NGROK

export NGROK=~/utils/ngrok

II. install

成功下载依赖过后通过通过clone源码安装onedrived。

$ git clone https://github.com/xybu/onedrived-dev.git
$ cd onedrived-dev
# Or use the built-in setuptools package from Python.
$ python3 ./setup.py install --us

III. config

成功安装onedrived后系config统会增加onedrivedonedrived-pref 两个应用工具。

$onedrived #tab 自动补全
onedrived       onedrived-pref  

需要通过onedrived-pref配置onedrive信息,选择交互模式执行命令添加账户onedrived-pref account add。该命令会生产onedrive登录链接并提示你浏览器打开。成功打开该链接后会自动引导从Microsoft登录onedrive,成功登录后会自动跳转到空白网页,并且生成包含登录token的url,我们拷贝该url到命令输入窗口完成认证。

$ onedrived-pref account add

NOTE: To better manage your OneDrive accounts, onedrived needs permission to access your account info (e.g., email
address to distinguish different accounts) and read/write your OneDrive files.

Paste this URL into your browser to sign in and authorize onedrived:

https://login.live.com/oauth20_authorize.srf?response_type=code&scope=wl.signin+wl.emails+wl.offline_access+
onedrive.readwrite&client_id=000000004010C916&redirect_uri=https%3A%2F%2Flogin.live.com%2Foauth20_desktop.srf

The authentication web page will finish with a blank page whose URL starts with
"https://login.live.com/oauth20_desktop.srf". Paste this URL here.
Paste URL here: https://login.live.com/oauth20_desktop.srf?code=<some_code_here>&lc=1033

Successfully authorized onedrived.
Successfully added account for Xiangyu Bu (xybu92@live.com, <account_id_token>)!

All OneDrive accounts associated with user "xb":

  #  Account ID          Owner Name    Email Address
---  ------------------  ------------  ---------------
  0  <account_id_token>  Xiangyu Bu    xybu92@live.com
提示:成功登录后的空白页会显示https://login.live.com/oauth20_desktop.srf?code=xxxxxxx-4041-b23e-baac-xxxxxxxxxx&lc=2052 格式的认证信息。

完成登录认证后还需要去通过 onedrived-pref drive set配置onedrive本地路径和配置文件路径。

$ onedrived-pref drive set
Reading drives information from OneDrive server...

All available Drives of authorized accounts:

  #  Account Email    Drive ID          Type      Quota                        Status
---  ---------------  ----------------  --------  ---------------------------  --------
  0  <some_email>     <some_drive_id>   personal  5.3 GB Used / 33.0 GB Total  active

Please enter row number of the Drive to add or modify (CTRL+C to abort): 0

Going to add/edit Drive "<some_drive_id>" of account "<some_email>"...
Enter the directory path to sync with this Drive [/home/xb/OneDrive]:  
Syncing with directory "/home/xb/OneDrive"? [y/N]: y
Enter the path to ignore file for this Drive [/home/xb/.config/onedrived/ignore_v2.txt]: 

Successfully configured Drive <some_drive_id> of account <some_email> (<some_user_id>):
  Local directory: /home/xb/OneDrive
  Ignore file path: /home/xb/.config/onedrived/ignore_v2.txt

之后便可以通过通过daemon模式启动onedrive完成同步。

$onedrived-pref config set logfile_path ~/onedrived.log
提示:如上~/onedrived.log为onedrive日志文件,首次启动强烈建议通过该日志分析异常。
$onedrived start
$onedrived stop

IV. troubleshootings

Error reading ngrok API

[2019-12-21 13:31:18,605] ERROR: MainThread: Error reading ngrok API: ngrok API did not return any tunnel.. Retry in 1sec.

参考如上dependences手动下载ngrok,解压后导出环境变量NGROK

onedrivesdk install failed

Writing /tmp/easy_install-mch5gxnb/onedrivesdk-2.0/setup.cfg
Running onedrivesdk-2.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-mch5gxnb/onedrivesdk-2.0/egg-dist-tmp-hlme4ic3
error: [Errno 20] Not a directory: '/tmp/easy_install-mch5gxnb/onedrivesdk-2.0/setup.py/../NOTICE.rst'

参考 https://github.com/xybu/onedrived-dev/issues/128 修改onedrived-dev根目录下requirements.txt文件中的onedrivesdk版本<2.0

$cat requirements.txt 
#onedrivesdk
onedrivesdk<2   #patch

ImportError: cannot import name 'loosebidict' from 'bidict'

Traceback (most recent call last):
  File "/home/lijie/.local/lib/python3.8/site-packages/onedrived-2.0.0-py3.8.egg/onedrived/od_models/bidict.py", line 2, in <module>
    from bidict import loosebidict
ImportError: cannot import name 'loosebidict' from 'bidict' (/home/lijie/.local/lib/python3.8/site-packages/bidict-0.21.2-py3.8.egg/bidict/__init__.py)

During handling of the above exception, another exception occurred:
AttributeError: module 'bidict' has no attribute 'OVERWRITE'

bidic 版本过高,这里删除后安装pip3 install bidict==0.19.0 版本。


本文由 Jay 创作,采用 知识共享署名 3.0,可自由转载、引用,但需署名作者且注明文章出处,点赞15

7 条评论

  1. Carrillo
    Carrillo

    博主我又出现问题了,今天手贱restart了一下就启动不了了

    ~$ onedrived start
    /home/admin1/.local/lib/python3.8/site-packages/onedrived/od_models/bidict.py:6: UserWarning: bidict.OVERWRITE has been deprecated, use bidict.DROP_OLD instead.
    on_dup_val = bidict.OVERWRITE
    Starting onedrived ... FAILED

    1. lijie
      lijie

      看起来只是一个警告,确认下是否是这里引起的,再次pip list 检查版本号,不行的话就按照提示替换 bidict.OVERWRITE到bidict.DROP_OLD试试。

  2. Carrillo
    Carrillo

    版本:Ubuntu 20.04
    最后ImportError,bidct降到0.19.0还是报错

    Traceback (most recent call last):
    File "/home/admin1/.local/lib/python3.8/site-packages/onedrived/od_models/bidict.py", line 2, in
    from bidict import loosebidict
    ImportError: cannot import name 'loosebidict' from 'bidict' (/home/admin1/.local/lib/python3.8/site-packages/bidict/__init__.py)

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/usr/local/bin/onedrived", line 33, in
    sys.exit(load_entry_point('onedrived==2.0.0', 'console_scripts', 'onedrived')())
    File "/usr/local/bin/onedrived", line 25, in importlib_load_entry_point
    return next(matches).load()
    File "/usr/lib/python3.8/importlib/metadata.py", line 77, in load
    module = import_module(match.group('module'))
    File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
    File "", line 1014, in _gcd_import
    File "", line 991, in _find_and_load
    File "", line 975, in _find_and_load_unlocked
    File "", line 671, in _load_unlocked
    File "", line 783, in exec_module
    File "", line 219, in _call_with_frames_removed
    File "/home/admin1/.local/lib/python3.8/site-packages/onedrived/od_main.py", line 15, in
    from . import od_repo
    File "/home/admin1/.local/lib/python3.8/site-packages/onedrived/od_repo.py", line 16, in
    from .od_models.path_filter import PathFilter as _PathFilter
    File "/home/admin1/.local/lib/python3.8/site-packages/onedrived/od_models/__init__.py", line 1, in
    from . import account_profile, bidict, drive_config, path_filter, pretty_api, webhook_notification
    File "/home/admin1/.local/lib/python3.8/site-packages/onedrived/od_models/bidict.py", line 5, in
    class loosebidict(bidict.bidict):
    File "/home/admin1/.local/lib/python3.8/site-packages/onedrived/od_models/bidict.py", line 6, in loosebidict
    on_dup_val = bidict.OVERWRITE
    AttributeError: module 'bidict' has no attribute 'OVERWRITE'

    请问如何解决,非常感谢博主!

    1. lijie
      lijie

      pip3.8 list 确认下版本号,不行的话先确认 pip uninstall删除。

      1. Carrillo
        Carrillo

        使用
        ~$ python3 -m pip install bidict==0.19.0
        降级,这个问题解决了,感谢

      2. Carrillo
        Carrillo

        pip后的版本号21.0.1,这要怎么操作

  3. lijie
    lijie

    在ubuntu20.04 出现 bidct 0.21.2依赖错误,降级后正常。

添加新评论