Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thealphadollar/gdrive_sync
This repository contains scripts that make GDrive tasks easier using command line functions and PyDrive wrapper for Google Drive.
https://github.com/thealphadollar/gdrive_sync
gdrive gdrive-sync google-drive pydrive-wrapper
Last synced: 10 days ago
JSON representation
This repository contains scripts that make GDrive tasks easier using command line functions and PyDrive wrapper for Google Drive.
- Host: GitHub
- URL: https://github.com/thealphadollar/gdrive_sync
- Owner: thealphadollar
- License: mit
- Created: 2018-02-17T15:16:57.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-08-16T19:44:10.000Z (about 5 years ago)
- Last Synced: 2024-10-11T20:16:31.022Z (26 days ago)
- Topics: gdrive, gdrive-sync, google-drive, pydrive-wrapper
- Language: Python
- Size: 282 KB
- Stars: 12
- Watchers: 2
- Forks: 4
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GDrive_Sync [![Build Status](https://travis-ci.org/thealphadollar/GDrive_Sync.svg?branch=master)](https://travis-ci.org/thealphadollar/GDrive_Sync)
This repository contains scripts that make GDrive tasks easier using command line functions and PyDrive wrapper for Google Drive.
GDrive_Sync aims at making life simpler when switching from Windows to Linux
This was developed with the aim to create a free and open source GDrive client to make things simpler and users won't
need to switch to other cloud file storing platforms or have to pay for commercial clients doing the same.## Operational Details
GDrive_Sync asks for permission from your Google Drive account to carry out the essential operations as are mentioned later
in the document.GDrive_Sync uses [PyDrive](https://github.com/googledrive/PyDrive) and [crontab](https://pypi.python.org/pypi/python-crontab) to interact with GDrive and Unix cron process manager respectively. It also requires
root permission for the "-start", "-stop" and "-status" argument since it needs to alter the CronTab files.[futurize](http://python-future.org/overview.html) library is used for the purpose of making the code compatible with both, python 2 and python 3.
## Installation And Usage
Current build works on Python 2 (Python 3 is supported but a [bug](https://github.com/thealphadollar/GDrive_Sync/issues/11) is there which does not allow connection to be established on systems using proxy).
### Dependencies
Please install pip before moving on if you don't have python-pip
`sudo apt-get update`
`sudo apt-get install python-pip`Once pip is installed, download the below dependencies (you don't need to follow the below steps if using pip installation method).
1. PyDrive
`pip2 install PyDrive`
2. crontab
`pip2 install python-crontab`
3. future
`pip2 install future`### Installing
The repository can be installed through pip or by manually cloning the repository.##### Using pip
1. Use the below command to install drive_sync using pip2 (till [python3 bug](https://github.com/thealphadollar/GDrive_Sync/issues/11) is resolved)
`pip2 install drive_sync`
This process also installs all the missing dependencies.
2. Open the crontab editor in terminal,
`crontab -e`
and add the [following lines](https://superuser.com/questions/784252/crontab-and-binaries-in-usr-local-bin) to it.
`PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin`
`LD_LIBRARY_PATH=/usr/local/lib`
3. To initiate the upload process from default directory.
`drive_sync -start`
This will open a web browser if its the first launch of GDrive_Sync. Later it'll be used to start the process with previously
associated GAccount unless "-reset" is used.
4. Now GDrive_Sync will be monitoring set upload/download folders. Use `-config` parameter to add/modify upload or download
directory.
5. To stop GDrive_Sync at any instance,
`drive_sync -stop`
6. To know if GDrive_Sync is active,
`./gdrive_sync/main.py -status`##### Manual Cloning
1. Clone the [repository](https://github.com/thealphadollar/GDrive_Sync.git),
`git clone https://github.com/thealphadollar/GDrive_Sync.git`
2. Open the folder and give
`./gdrive_sync/main.py -start`
This command adds `./gdrive_sync/main.py -start` to your cron jobs with periodicity of 5 minutes.
3. A link will open asking for GDrive access; allow for all.
4. Now GDrive_Sync will be monitoring set upload/download folders. Use `-config` parameter to add/modify upload or download
directory.
5. To stop GDrive_Sync at any instance,
`./gdrive_sync/main.py -stop`
6. To know if GDrive_Sync is active,
`./gdrive_sync/main.py -status`### What Cron Script Does?
The code for this is present in `gdrive_sync/cron_handle.py`
- Periodically checks (every 5 minutes) the upload folders for a file change.
- If a new file is found which is not being uploaded by any other instance of the same function, it marks it as being uploaded
and starts the upload process.
- status.json in every folder is used to monitor the "being_uploaded" status of each file in the folder.
- If Remove_Post_Upload is True in `config_dicts/config.json`, then the file is deleted post upload to GDrive. Otherwise,
it is moved to the set download directory.
- If Share_Link is True in `config_dicts/config.json` then a share link for each uploaded file is placed in the set download
directory.
- It is highly advisable to set your own download and upload directories.### Why Require GDrive Authentication?
GDrive_Sync requires Google Drive full read and write access.
It asks for "https://www.googleapis.com/auth/drive" which translates to,
"Full, permissive scope to access all of a user's files, excluding the Application Data folder. Request this scope only when it is strictly necessary."This is required in order to download and upload files as well as create directories along with creation of sharable link.
The author cannot modify/manipulate any personal data or Google Drive files. All the write/read access are provided solely to
the user granting the permission.
## ParametersThe parameters that can be used are:
* -reset
Reset account associated with GDrive_Sync and give it the read and write permissions to your Google Drive. Automatically executed at the
first run of GDrive_Sync.* -start
Start the automatic GDrive syncing of the folders set as upload directories.
* -stop
Stop the automatic GDrive syncing of the folders set as upload directories.
* -status
Shows whether GDrive is uploading automatically or not.
* -version
Shows the current version of the GDrive_Sync.
* -config
Gives option to edit the configuration file on which automatic upload and download works.
- Up_Directory: The directory where the files that are to be uploaded are given, relative to home directory.
(e.g. for "~/Documents/to_GDrive", input "Documents/to_GDrive")
(Default is "to_GDrive" directory in your Documents folder)
- Down_Directory: The directory where the files are downloaded, relative to home directory.
(e.g. for "~/Documents/from_GDrive", input "Documents/from_GDrive")
(Default is "from_GDrive" directory in you Documents folder)
- Remove_Post_Upload: [Y/N] 'Y' removes the local file post upload. 'N' moves the file to GDrive download folder
post upload.
(Default is 'N')
- Share_Link: [Y/N] 'Y' puts the shareable link of the file uploaded in share.txt in Up_Directory.
(Default is 'Y')
- Write_Permission: [Y/N] 'Y' gives the write permission in the sharable link.
(Default is 'N')Configuration is stored in config.json as a dictionary which can be manually edited as well.
* -ls [local/remote]
Lists all files and folders in your GDrive (default or when "remote" used).
Lists all files and folders in your downloads directory (when "local" used).* -ls_trash
Lists all files and folders in your GDrive trash.
* -ls_folder [folder_id]
Lists files and folders in the given folder id in your drive.
* -ls_files [folder_id/"root"]
Lists all files recursively present in the folder id given.
* -download [file_id1] [file_id2]
Downloads the given file from GDrive. Multiple files can be downloaded by putting file_ids one after the other.
Use "-d all" argument to download entire your entire GDrive.* -upload [file_add]
Upload file/folder corresponding to the address given to GDrive, for one time.
* -share [file_id]
Outputs the shareable link of the file.
* -remove [local/remote] [file_name/folder_name/file_id/folder_id]
Delete the mentioned file from GDrive download directory or GDrive remote. Please input file_id/folder_id if it's a
remote file. You can add multiple file_ids/folder_ids one after the other, e.g. -remove remote [file_id1] [file_id2]* -open [upload/download]
Opens the upload or download directory in file explorer.
## Contributing
Contributions to this project are highly encouraged. We will soon be having a contribution guide.
To begin, please have a look at the issues. They are simple and easy to implement/resolve.