From 8b8966a47a2976a069d56d422b267bca636ec27f Mon Sep 17 00:00:00 2001 From: Brian Date: Sun, 29 Sep 2019 00:07:21 +0100 Subject: [PATCH] Fix parsing param, update readme (wip) and requirements --- README.md | 37 +++++++++++++++++++++++-------------- main.py | 4 ++-- requirements.txt | 17 +++++------------ 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 38a79d8..0e04ff5 100644 --- a/README.md +++ b/README.md @@ -4,25 +4,29 @@ The application has only been tested on Python 3.7.3 x86_64 on Windows. However, I don't see why it wouldn't work on *NIX as well. Note that Windows' default conhost terminal emulator may have problem displaying unicode characters. I personally run it in PyCharm CE or Visual Studio Code Terminal. -1. Install dependencies requirements. +1. Create a [virtual environment](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/) and activate it (optional / recommended) + ``` + python3 -m venv /path/to/new/venv + *NIX: source /path/to/new/venv/bin/activate + Windows: C:\path\to\new\env\Scripts\activate + ``` +1. Install dependencies requirements. ```Shell pip install -r requirements.txt ``` If you don't like to install packages to global/user scopes, you can also setup [virtual environment](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/) -1. Changing the settings in `sync_settings.json`. Please validate the JSON files and make sure all the fields are populated with correct value. Incorrect settings are undefined behaviour which means anything can happens from functioning correctly to causing nuclear bomb. +1. Navigate to `conf/` directory and make a copy of each `.sample.json` files renaming each to remove `.sample` (ie, rename the copy to `sync_settings.json`). +Edit those files to populate the correct values. ## Run the code Run `main.py` in the terminal to start the application. The program accept three optional positional parameters -- Remote base ItemID (such as `ABC12345678DEFG!1234567`). If not provided, will use jobs in `sync_settings.json`. -- Remote base directory. leave empty or `/` for root. -- Local base directory. leave empty for working directory. For Windows, please only use `/`, such as `D:/downloads/OneDrive`. - -On launch, the program will interactively ask for confirmation before starting any action, unless overridden with `-y` or `--yes`. +- Remote ItemID (such as `87654321012`). This can be found on the URL when browsing on box.com website. User's root directory is `0`. If not provided, will use jobs in `sync_settings.json`. +- Local directory that will represent the remote directory. Leave empty or use `.` for working directory (not tested). See `--help` for more information. @@ -32,11 +36,11 @@ When file conflict occurs, if the file size is different, the program downloads `blacklist` currently accepts path to file or directory with [Unix shell-style wildcards](https://docs.python.org/3/library/fnmatch.html), all relative to root of remote. The same blacklist currently apply to every drive root. -## Explaining remote directory +## Explaining remote directory (to update) For example ``` -RemoteRoot of ABC12345678DEFG!1234567 +RemoteRoot of 87654321012 ├───A │ ├───A1.png │ └───A2.png @@ -62,25 +66,30 @@ If the following blacklist is applied, ``` the program will only concern these. ``` -RemoteRoot of ABC12345678DEFG!1234567 +RemoteRoot of 87654321012 ├───A │ └───A1.png └───B.jpg ``` -Launching the program with `./main.py ABC12345678DEFG!1234567 / D:/OneDrive` will results in +Launching the program with `./main.py 87654321012 D:/BoxFolder` will results in ``` D: -└───OneDrive +└───BoxFolder ├───A │ └───A1.png └───B.jpg ``` -Launching the program with `./main.py ABC12345678DEFG!1234567 A D:/OneDrive` will results in +Launching the program with `./main.py 87654321012 D:/BoxFolder` will results in ``` D: -└───OneDrive +└───BoxFolder └───A1.png ``` Note that the blacklist is still relative to remote root, not `A`. + +## Development: Making changes + +When installing / updating dependencies, update requirements.txt +`pip freeze > requirements.txt` diff --git a/main.py b/main.py index 8ce5536..d3d222e 100644 --- a/main.py +++ b/main.py @@ -24,7 +24,7 @@ def main(): parser = argparse.ArgumentParser() parser.add_argument("itemId", nargs='?', default=None, help="Item ID to download, use 0 for root") - parser.add_argument("localDirectory", nargs='?', default='', help="Local path of the item") + parser.add_argument("localDirectory", nargs='?', default='.', help="Local path of the item") parser.add_argument("-y", "--yes", help="skip confirmation dialogue", action="store_true") args = parser.parse_args() @@ -33,7 +33,7 @@ def main(): q = queue.Queue() if args.itemId is not None: - local = Path('args.localDirectory') + local = Path(args.localDirectory) folder = client.folder(args.itemId).get(['name', 'id', 'size', 'modified_at', 'path_collection']) q.put(Job(folder, local)) else: diff --git a/requirements.txt b/requirements.txt index 145bfab..e011b3e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,19 +1,12 @@ -astroid==2.2.5 +attrs==19.1.0 autopep8==1.4.4 -certifi==2019.6.16 +boxsdk==2.6.0 +certifi==2019.9.11 chardet==3.0.4 -colorama==0.4.1 idna==2.8 -isort==4.3.20 -lazy-object-proxy==1.4.1 -mccabe==0.6.1 -oauthlib==3.0.1 pycodestyle==2.5.0 -pylint==2.3.1 -PyYAML==5.1.1 requests==2.22.0 -requests-oauthlib==1.2.0 +requests-toolbelt==0.9.1 six==1.12.0 -typed-ast==1.4.0 -urllib3==1.25.3 +urllib3==1.25.6 wrapt==1.11.2