Skip to content

Commit

Permalink
update ReadMe & better support for relative path
Browse files Browse the repository at this point in the history
  • Loading branch information
cfbao committed Jul 3, 2017
1 parent cc011f2 commit 8406090
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
47 changes: 38 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,41 @@ To use the Windows binary (download on the [releases](https://github.com/cfbao/g
* Windows update [KB2999226](https://support.microsoft.com/en-gb/help/2999226/update-for-universal-c-runtime-in-windows "Update for Universal C Runtime in Windows")

## How-to
Download [cleaner.py](./cleaner.py) (or cleaner.exe) and place it in an empty local folder.

The first time you run it, you will be prompted with Google authorization page asking you to grant permission. Once authorized, an authorization token will be saved in `.credentials\google-drive-trash-cleaner.json` under your home directory (`%UserProfile%` on Windows). You don't need to manually authorize again until you delete this file or revoke permission on your Google account page.

By default, the script tries to retrieve the list of files trashed more than 30 days ago. This may take some time on the first run, because it searches your Google Drive activity history from the very beginning. The script prints the retrieved list of files on screen, and ask you to confirm whether you want to delete them. Once confirmed, these files are permanently deleted from Google Drive, and a new file named `page_token` is saved in the local folder cleaner.py<span>/</span>cleaner.exe is in.

`page_token` contains a single number that indicates the appropriate starting position in your Google Drive activity history for future searches. Therefore, future runs of the script will be much faster, and `page_token` will be successively updated.

There are a few command line options that allows for some customizations. Run `cleaner -h` to learn about them.
Download `cleaner`([.py](./cleaner.py) or [.exe](https://github.com/cfbao/google-drive-trash-cleaner/releases)), place it in an empty local folder, and run it from command line.

By default, `cleaner` retrieves a list of all files trashed more than 30 days ago, and prints their info on screen.
You're asked whether you want to delete them.
If confirmed, these files are permanently deleted from Google Drive.

### Google authorization
The first time you run `cleaner`, you will be prompted with a Google authorization page asking you for permission to view and manage your Google Drive files.
Once authorized, a credential file will be saved in `.credentials\google-drive-trash-cleaner.json` under your home directory (`%UserProfile%` on Windows).
You don't need to manually authorize `cleaner` again until you delete this credential file or revoke permission on your Google [account](https://myaccount.google.com/permissions "Apps connected to your account") page.
You can specify a custom location for the credential file by using the command line option `--credfile`. This is helpful if you're using multiple Google accounts with `cleaner`.

### `page_token` file
`cleaner` finds out when your files were trashed by scanning through your Google Drive activity history.
On first run, it must start from the very beginning to ensure no files are missed, so it might take some time.
After first run, `cleaner` saves a file named `page_token` in its own parent folder.
This file contains a single number indicating an appropriate starting position in your Google Drive activity history for future scans,
so they can be much faster than the first one. Each run of `cleaner` updates `page_token` as appropriate.
You can specify a custom location or name for the `page_token` file by using the command line option `--ptokenfile`.

### More options
More command line options are available. You can read about them by running `cleaner --help`.
```
usage: cleaner.py [-h] [-a] [-v] [-d #] [-t SECS] [--logfile PATH]
[--ptokenfile PATH] [--credfile PATH]
optional arguments:
-h, --help show this help message and exit
-a, --auto Automatically delete older trashed files in Google
Drive without prompting user for confirmation
-v, --view Only view which files are to be deleted without
deleting them
-d #, --days # Number of days files can remain in Google Drive trash
before being deleted. Default is 30
-t SECS, --timeout SECS
Specify timeout period in seconds. Default is 300
--logfile PATH Path to log file. Default is no logs
```
12 changes: 9 additions & 3 deletions cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ class TimeoutError(Exception):

class PageTokenFile:
def __init__(self, filePath):
os.makedirs(os.path.dirname(filePath), exist_ok=True)
dir = os.path.dirname(filePath)
if dir.strip():
os.makedirs(dir, exist_ok=True)
self.path = filePath

def get(self):
Expand Down Expand Up @@ -129,7 +131,9 @@ def configure_logs(logPath):
if not logPath:
return logger
logPath = logPath.strip('"')
os.makedirs(os.path.dirname(logPath), exist_ok=True)
dir = os.path.dirname(logPath)
if dir.strip():
os.makedirs(dir, exist_ok=True)
open(logPath, 'a').close()
fileHandler = logging.FileHandler(
logPath, mode='a', encoding='utf-8')
Expand All @@ -151,7 +155,9 @@ def get_credentials(flags):
Returns:
Credentials, the obtained credential.
"""
os.makedirs(os.path.dirname(flags.credfile), exist_ok=True)
dir = os.path.dirname(flags.credfile)
if dir.strip():
os.makedirs(dir, exist_ok=True)
store = Storage(flags.credfile)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
Expand Down

0 comments on commit 8406090

Please sign in to comment.