Skip to content
This repository has been archived by the owner on Oct 5, 2020. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cfbao/google-drive-trash-cleaner
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.1.2
Choose a base ref
...
head repository: cfbao/google-drive-trash-cleaner
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 5 commits
  • 2 files changed
  • 2 contributors

Commits on Jun 7, 2018

  1. prevent encoding errors when print

    implement `SafePrinter` to produce safe custom `print` functions
    resolve #7
    cfbao committed Jun 7, 2018

    Verified

    This commit was signed with the committer’s verified signature.
    cfbao Chenfeng Bao
    Copy the full SHA
    77c2a9a View commit details

Commits on Jul 3, 2018

  1. Copy the full SHA
    eb5828e View commit details

Commits on May 21, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2ebb124 View commit details

Commits on May 31, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    389c534 View commit details

Commits on Oct 5, 2020

  1. Deprecation notice (#16)

    cfbao authored Oct 5, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c0e074d View commit details
Showing with 59 additions and 2 deletions.
  1. +10 −2 README.md
  2. +49 −0 cleaner.py
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Google Drive Trash Cleaner

> :warning: ***This project is deprecated***.
>
> [Google Drive trash items will be automatically deleted after 30 days starting on October 13, 2020](https://gsuiteupdates.googleblog.com/2020/09/drive-trash-auto-delete-30-days.html).
This project hence no longer has a purpose, and will not be maintained.

Unlike many other cloud storage services, Google Drive doesn't auto delete files in trash/bin even after they've been there for a long time.
There isn't even a way to check when a file was trashed.
Emptying the entire trash folder is just too risky.
@@ -9,8 +15,10 @@ This script helps you safely cleanup Google Drive's trash by deleting only files
## Dependencies
To use the Python script directly
* Python 3.5+
* package *google-api-python-client*
run `pip install --upgrade google-api-python-client` to install
* Package *google-api-python-client* and *oauth2client*. Run
`pip install --upgrade google-api-python-client` and
`pip install --upgrade oauth2client`
to install

To use the Windows binary (download on the [releases](https://github.com/cfbao/google-drive-trash-cleaner/releases) page)
* 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")
49 changes: 49 additions & 0 deletions cleaner.py
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@
import httplib2
import os
import sys
import io
import builtins
import argparse
import time
import calendar
@@ -67,6 +69,53 @@ def save(self, pageToken):
with open(self.path, 'w', encoding='utf-8') as f:
f.write(str(pageToken))

class SafePrinter:
class _SafeTextWrapper:
def __init__(self, unsafeTextFile, error):
if not isinstance(unsafeTextFile, io.TextIOBase):
raise TypeError()
self.unsafeTextFile = unsafeTextFile
self.encoding = unsafeTextFile.encoding
self.error = error
def write(self, text):
self.unsafeTextFile.write(text.encode(self.encoding, self.error).decode(self.encoding, 'ignore'))
def flush(self):
self.unsafeTextFile.flush()

def __init__(self, defaultFile=None, error='backslashreplace'):
if error not in ['replace', 'xmlcharrefreplace', 'backslashreplace', 'namereplace']:
raise ValueError("`error` must be one of 'replace', 'xmlcharrefreplace', 'backslashreplace', 'namereplace'")
self.defaultFile = defaultFile or sys.stdout
self.error = error
self.wrappers = {id(self.defaultFile): SafePrinter._SafeTextWrapper(self.defaultFile, self.error)}

def get_print(self):
def print(*args, **kwargs):
file = kwargs.get('file') or self.defaultFile
if id(file) not in self.wrappers:
self.wrappers[id(file)] = SafePrinter._SafeTextWrapper(file, self.error)
kwargs['file'] = self.wrappers[id(file)]
builtins.print(*args, **kwargs)
return print

def clear(self):
delList = []
for id in self.wrappers:
if self.wrappers[id].unsafeTextFile.closed:
delList.append(id)
for id in delList:
del self.wrappers[id]

def purge(self):
self.wrappers.clear()
self.wrappers = {id(self.defaultFile): SafePrinter._SafeTextWrapper(self.defaultFile, self.error)}

try:
print = SafePrinter().get_print()
except TypeError:
sys.stderr.write('`SafePrinter` failed to initialize. Please contact the developer.\n')
sys.exit(-1)

def main():
flags = parse_cmdline()
logger = configure_logs(flags.logfile)