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

Commit

Permalink
Merge branch 'v1.0.18'
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBerdik committed May 9, 2020
2 parents a56e9af + d3fb45b commit bd47be6
Show file tree
Hide file tree
Showing 9 changed files with 387 additions and 284 deletions.
548 changes: 271 additions & 277 deletions InfiniDrive.py

Large diffs are not rendered by default.

55 changes: 48 additions & 7 deletions libs/driveAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,47 @@ def get_root_folder_id(service):
else:
return folders[0]['id']

# Checks if an InfiniDrive upload with the given name exists. Returns true if file with names exists, else false.
def file_with_name_exists(service, file_name):
query = "(mimeType='application/vnd.google-apps.folder') and (trashed=False) and ('" + get_root_folder_id(service) + "' in parents) and name='" + str(file_name) + "'"
page_token = None
filesList = list()
while True:
param = {}

if page_token:
param['pageToken'] = page_token

results = service.files().list(q=query, fields="nextPageToken, files(name)", **param).execute()
filesList += results.get('files', [])

page_token = results.get('nextPageToken')
if not page_token:
break

return len(filesList) > 0

# Given a file name, returns the file ID.
def get_file_id_from_name(service, file_name):
query = "(mimeType='application/vnd.google-apps.folder') and (trashed=False) and ('" + get_root_folder_id(service) + "' in parents) and name='" + str(file_name) + "'"
page_token = None
filesList = list()
while True:
param = {}

if page_token:
param['pageToken'] = page_token

results = service.files().list(q=query, fields="nextPageToken, files(id)", **param).execute()
filesList += results.get('files', [])

page_token = results.get('nextPageToken')
if not page_token:
break

if len(filesList) == 0: return ''
return [file.get('id') for file in filesList][0]

#Creates a folder and returns its ID
def create_folder(service, file_path):
folder_metadata = {
Expand Down Expand Up @@ -109,28 +150,28 @@ def list_files(service):
if page_token:
param['pageToken'] = page_token

results = service.files().list(q=query, fields="nextPageToken, files(id, name)", **param).execute()
results = service.files().list(q=query, fields="nextPageToken, files(name)", **param).execute()
filesList += results.get('files', [])

page_token = results.get('nextPageToken')
if not page_token:
break

filesList = [[folder.get('name'), folder.get('id')] for folder in filesList]
filesList = [[folder.get('name')] for folder in filesList]
filesList.sort()
return filesList

# Deletes the file with the given ID.
def delete_file(service, file_id):
service.files().delete(fileId=file_id).execute()
def delete_file(service, file_name):
service.files().delete(fileId=get_file_id_from_name(service, file_name)).execute()

# Renames the file with the given ID.
def rename_file(service, file_id, new_name):
# Renames the file with the given name.
def rename_file(service, old_name, new_name):
file = {'name': new_name}

# Rename the file.
service.files().update(
fileId=file_id,
fileId=get_file_id_from_name(service, old_name),
body=file,
fields='name').execute()

Expand Down
25 changes: 25 additions & 0 deletions libs/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
def print_help(version):
print("\n ,,, ,,,")
print(" &@@@@@@@@@@@@@ @@@@@@@@@@@@@@")
print(" @@@@@@@# %@@@@@# @@@@@@@@@@@@@@@@@@@@")
print(" @@@@@@ #@@@ &@@@@@@@ @@@@@@")
print(" @@@@@ @@@@ @@@@@@@ @@@@@")
print(" @@@@ @@@@@@@@@ @@@@@")
print("@@@@@ @@@@@@@ @@@@")
print("@@@@@ @@@@@@ @@@@#")
print("@@@@@ @@@@@@ @@@@,")
print("&@@@@ &@@@@@@@@ *@@@@")
print(" @@@@@ @@@@@@@ @@@ @@@@@")
print(" @@@@@ *@@@@@@# @@@ @@@@@")
print(" @@@@@@# @@@@@@@@ @@@@# @@@@@@")
print(" *@@@@@@@@@@@@@@@@@@ @@@@@@@@%@@@@@@@@")
print(" #@@@@@@@@@@@@ *@@@@@@@@@@@*\n")
print("InfiniDrive v" + version + " - An unlimited Google Drive storage solution")
print("Based on a project by David Berdik, Steven Myrick, and Noah Greenberg")
print("Developed and maintained by David Berdik and Maitree Rawat\n")
print(">> help - Displays this help command.")
print(">> upload <file path OR http/https URL> <optional: file name> - Uploads specified file to Google Drive")
print(">> list - Lists the names of all InfiniDrive files")
print(">> rename <current file name> <new file name> - Renames the file with the specified name to the specified new name")
print(">> download <file name> <file path> - Downloads the contents of the specified file name to the specified file path")
print(">> delete <file name> <optional flag: force-delete> - Deletes the specified InfiniDrive file")
43 changes: 43 additions & 0 deletions libs/requirements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class requirements:
def __init__(self):
if self.check_imports() and self.check_credentials():
return
quit()

def check_imports(self):
try:
import array, gc, libs.driveAPI as driveAPI, math, os, requests, sys, time
from binascii import crc32
from io import BytesIO
from libs.bar import getpatchedprogress
from PIL import Image
from progress.bar import ShadyBar
from progress.spinner import Spinner
from tabulate import tabulate
from libs.uploadHandler import handle_upload_fragment
except (ModuleNotFoundError, ImportError) as error:
print('\nOops! ', end = ' ')
print(error)
print('\nOne or more InfiniDrive dependencies are not installed on your system.')
print('Using pip, you can install these dependencies using one of the following commands from the root InfiniDrive directory:')
print('\t1. pip install -r requirements.txt\n\t2. python -m pip install -r requirements.txt')
print('\nMore information is available in \'README.md\' as well as online at https://github.com/DavidBerdik/InfiniDrive')
return False
return True

def check_credentials(self):
import os
if not os.path.exists('credentials.json'):
print('InfiniDrive could not start because you have not provided a \'credentials.json\' file.')
print('Please do so and try again. Instructions for doing this are available in \'README.md\'')
print('as well as online at https://github.com/DavidBerdik/InfiniDrive')
return False
elif not os.path.exists('token.pickle'):
print('Please complete account authentication using the following URL.')
print('You can then run your previous command again.\n')
import libs.driveAPI as driveAPI
driveAPI.get_service()
return False
return True

requirements()
Binary file removed testfiles/test-bitmap.bmp
Binary file not shown.
Binary file removed testfiles/test-file.dat
Binary file not shown.
Binary file removed testfiles/testdoc1.docx
Binary file not shown.
Binary file removed testfiles/testdoc2.docx
Binary file not shown.
Binary file removed testfiles/testdoc3.docx
Binary file not shown.

0 comments on commit bd47be6

Please sign in to comment.