Skip to content

Commit

Permalink
Adding CLI documentation and updating dev and google packages (#2)
Browse files Browse the repository at this point in the history
* Adding CLI documentation and updating dev and google packages

* Fixing url formatting in README

* Adding some details to CLI doc

* Adding installation doc

* Updating CLI documentation
  • Loading branch information
eduardogr authored Jan 22, 2023
1 parent 6e2bc45 commit 235e2ab
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 21 deletions.
117 changes: 117 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Library and cli to manage and interact with your Google Drive, sheets and docs

0. [Introduction](#introduction)
0. [Obtaining credentials for Google APIs](#wrench-obtaining-credentials-for-google-apis)
0. [Installing google-drive CLI](#installing-google-drive-cli)
0. [CLI Documentation](#cli-documentation)
0. [Contributing](#family-contributing)
0. [License](#page_with_curl-license)

Expand Down Expand Up @@ -62,6 +64,121 @@ To generate this we have the make target google-auth, so, you just have to tun

:angel: So, you don't have to worry about that :smiley:


# Installing google-drive CLI

## Using make

```
make install
```

## Using pip

```
pip install google-drive
```

### With specific version

Look for available versions with:

```
pip install google-drive==
```

And select one and run:

```
pip install google-drive==<VERSION>
```

# CLI Documentation

## google-drive --help

Shows the help message

### Usage

```
> google-drive --help
Usage: google-drive [OPTIONS] COMMAND [ARGS]...
Options:
--help Show this message and exit.
Commands:
get Get file metadata
login Perform a login with google oauth
ls List directory contents
mkdir Make directory
```

## google-drive login

Perform a login with google oauth.

### Usage

```
> google-drive login <path-to-credentials-file.json>
```

## google-drive ls

List directory contents

### Usage

```
> google-drive ls <directory>/<maybe-some-subdir> <path-to-credentials-file.json>
- (<GOOGLE_DOC_ID_1>, <FILENAME_1>, <FILE_MIMETYPE_1>)
- (<GOOGLE_DOC_ID_2>, <FILENAME_2>, <FILE_MIMETYPE_2>)
- (<GOOGLE_DOC_ID_3>, <FILENAME_3>, <FILE_MIMETYPE_3>)
...
- (<GOOGLE_DOC_ID_N>, <FILENAME_N>, <FILE_MIMETYPE_N>)
```

## google-drive get

Get file metadata

### Usage

```
> google-drive get <GOOGLE_DOC_ID> <path-to-credentials-file.json>
File Metadata:
==
id: <GOOGLE_DOC_ID>
name: <FILENAME>
parents: ['<GOOGLE_DOC__PARENT_ID>']
mime_type: <FILE_MIMETYPE>
export_links:
- application/rtf: https://docs.google.com/feeds/download/documents/export/Export?id=<GOOGLE_DOC_ID>&exportFormat=rtf
- application/vnd.oasis.opendocument.text: https://docs.google.com/feeds/download/documents/export/Export?id=<GOOGLE_DOC_ID>&exportFormat=odt
- text/html: https://docs.google.com/feeds/download/documents/export/Export?id=<GOOGLE_DOC_ID>&exportFormat=html
- application/pdf: https://docs.google.com/feeds/download/documents/export/Export?id=<GOOGLE_DOC_ID>&exportFormat=pdf
- application/epub+zip: https://docs.google.com/feeds/download/documents/export/Export?id=<GOOGLE_DOC_ID>&exportFormat=epub
- application/zip: https://docs.google.com/feeds/download/documents/export/Export?id=<GOOGLE_DOC_ID>&exportFormat=zip
- application/vnd.openxmlformats-officedocument.wordprocessingml.document: https://docs.google.com/feeds/download/documents/export/Export?id=<GOOGLE_DOC_ID>&exportFormat=docx
- text/plain: https://docs.google.com/feeds/download/documents/export/Export?id=<GOOGLE_DOC_ID>&exportFormat=txt
```

## google-drive mkdir

Make directory

### Usage

```
> google-drive mkdir <DIR_NAME> <path-to-credentials-file.json>
(<GOOGLE_DOC_ID>, <DIR_NAME>, application/vnd.google-apps.folder)
```

# Using googledrive as API SDK

## :family: Contributing

[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
Expand Down
27 changes: 15 additions & 12 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@

## Project management

- [ ] Add documentation
- [X] Add CLI documentation
- [ ] Add API documentation
- [ ] Add examples of usage the api.py from a piece of code.
- [ ] Add pull requests and issues templates
- [X] Add CONTRIBUTING

## Functionalities

- [X] Implement `get` to get file metadata
- [ ] Extending `ls` for an ID file.
- [ ] Extending `mkdir` for a path folder.
- [ ] Implement `analysis` to extract data from the google drive.
- [ ] Implement `cat` for a google doc file.
- [ ] Implement `touch` for create an empty google doc, spreadsheet, presentation, form, ...
- [ ] Implement `cp` for a google doc file. From source path to destiny path.
- [ ] Implement `mv` for a google doc file. From source path to destiny path.
- [ ] Implement open_file help function for spreadsheets files. This will retrieve an object that will allow us manage that file; reading (readlines); updating; removing, ...
- [ ] Implement readlines help function for spreadsheets files reading.
- [ ] Nice print for cli output.
- [X][CLI] Implement `get` to get file metadata
- [ ][CLI] Extending `ls` for an ID file.
- [ ][CLI] Extending `mkdir` for a path folder.
- [ ][CLI] Implement `rmdir` for a path folder.
- [ ][CLI] Implement `analysis` to extract data from the google drive.
- [ ][CLI] Implement `cat` for a google doc file.
- [ ][CLI] Implement `touch` for create an empty google doc, spreadsheet, presentation, form, ...
- [ ][CLI] Implement `cp` for a google doc file. From source path to destiny path.
- [ ][CLI] Implement `mv` for a google doc file. From source path to destiny path.
- [ ][API] Implement open_file help function for spreadsheets files. This will retrieve an object that will allow us manage that file; reading (readlines); updating; removing, ...
- [ ][API] Implement readlines help function for spreadsheets files reading.
- [ ][CLI] Nice print for cli output.
- [ ][CLI] Add logger with different levels of logging: {ERROR, WARNING, INFO, DEBUG}
4 changes: 3 additions & 1 deletion googledrive/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,16 @@ class GoogleDrive(GoogleService):
MIMETYPE_FOLDER = 'application/vnd.google-apps.folder'
MIMETYPE_DOCUMENT = 'application/vnd.google-apps.document'
MIMETYPE_SPREADSHEET = 'application/vnd.google-apps.spreadsheet'
MIMETYPE_PDF = 'application/pdf'

FIELDS_BASIC_FILE_METADATA = 'id, name, parents, mimeType'
FIELDS_FILE_METADATA = f'{FIELDS_BASIC_FILE_METADATA}, exportLinks'

QUERY_IS_FOLDER = f"mimeType='{MIMETYPE_FOLDER}'"
QUERY_IS_DOCUMENT = f"mimeType='{MIMETYPE_DOCUMENT}'"
QUERY_IS_SPREADSHEET = f"mimeType='{MIMETYPE_SPREADSHEET}'"
QUERY_IS_FILE = f"({QUERY_IS_SPREADSHEET} or {QUERY_IS_DOCUMENT})"
QUERY_IS_PDF = f"mimeType='{MIMETYPE_PDF}'"
QUERY_IS_FILE = f"({QUERY_IS_FOLDER} or {QUERY_IS_SPREADSHEET} or {QUERY_IS_DOCUMENT} or {QUERY_IS_PDF})"

#
# Simple structures for cached responses
Expand Down
12 changes: 6 additions & 6 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# linter
pylint==2.4.4
pylint==2.16.0b1

# format python code to PEP 8 stlye guide
autopep8==1.5
autopep8==2.0.1

# test runner
pytest==5.4.1
pytest-cov==2.8.1
pytest==7.2.1
pytest-cov==4.0.0

# upgraded Python shell for dev env
ipython==7.13.0
ipython==7.23.1

codecov==2.1.3
codecov==2.1.12
4 changes: 2 additions & 2 deletions requirements/prod.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
google-api-python-client==1.8.0
google-auth-httplib2==0.0.3
google-api-python-client==2.6.0
google-auth-httplib2==0.1.0
google-auth-oauthlib==0.4.1

dataclasses==0.6

0 comments on commit 235e2ab

Please sign in to comment.