Working with HDC Project Files in the Command Line Interface

Version 1.5 by Susan Evans on 2023/07/10 22:20

The Pilot Command Line Interface (pilotcli) is a binary executable program that provides a convenient way for users to perform file actions and platform-related tasks programmatically. The Pilot Command Line Interface can be downloaded and run on on your local Linux and Linux subsystems (as Windows user, see for instance the Windows Subsystem for Linux installation guide) to support large file uploads. For convenience, pilotcli is also pre-deployed and installed in the users JupyterHub accessible via worskpace tools.

Data Stewardship

Users are reminded to abide by the Platform Terms of Use and any Project-specific restrictions when using the Command Line Interface to access data and code.

Using the Pilot Command Line Interface in JupyterHub

To get started with the Pilot Command Line Interface in the HDC JupyterHub workspace tool, see the article Using JupyterHub in HDC and refer to the remaining sections in this article for a full description of the pilotcli commands.

Downloading the Pilot Command Line Interface

If you wish to use the Pilot Command Line Interface to upload large files from your local environment, it is necessary to download Pilot Command Line Interface tool on your Linux system. The recommended Linux version is Ubuntu 20.04.

  • Download the pilotcli tool here.

After download, please grant execution permission to the binary file so that Pilot Command Line Interface can be used. To grant permission to the binary file, use the following command in the downloaded pilotcli directory.

$ chmod +x ./pilotcli

If you have sudo permission, you can make the Pilot Command Line Interface more accessible in any directory by moving it to the /usr/local/bin directory:

$ mv ./pilotcli /usr/local/bin

Without sudo permission, you can still use the Pilot Command Line Interface in a different directory by referring the Command Line Interface path. For example, use a command line Interface in the Downloads folder:

$ ~/Downloads/pilotcli

Pilot Command Line Interface Command Summary

Commands are organized into main groups:

  1. User - User related actions such as login and logout
  2. Project Project related actions, including list Project Names and Codes for all Projects accessible by the logged-in user.
  3. File - Actions on files. User could use file action commands to list files/folders, upload files/folders, list/export attribute, and download files as well.
  4. Dataset - Actions related to datasets.

User Commands: pilotcli user

Help

$ pilotcli user --help
Usage: pilotcli user [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

Commands:
  login   For user to login.
  logout  For user to logout.

Command: login

  • Options: -u --username, -p --password
  • Usage: Allows users to log into the platform through pilotcli. After login, the user must be actively using the Pilot Command Line Interface to remain logged in, or they will be logged out automatically after the session is idle for five minutes.
  • Prerequisites: None.
$ pilotcli user login --help
Usage: pilotcli user login [OPTIONS]

  For user to login.

Options:
  --help  Show this message and exit.

Example

User login:

1) Use the output device validation link or QR code to launch authentication validation:

$ pilotcli user login
Please, access https://iam.hdc.humanbrainproject.eu/realms/hdc/device?user_code=XXXX-XXXX to proceed
 ▄▄▄▄▄▄▄  ▄▄ ▄  ▄  ▄ ▄▄▄▄    ▄ ▄▄▄▄▄▄▄
 █ ▄▄▄ █ ▄ ▄▄▀█ █▀▀▀▄▀█▀  ▀██▄ █ ▄▄▄ █
 █ ███ █ ██▄   ▀▀▄▀▄▄█▄ ▄ ▀▀▀▄ █ ███ █
 █▄▄▄▄▄█ █▀▄▀█▀▄▀█▀▄ █ ▄ ▄ █▀█ █▄▄▄▄▄█
 ▄▄▄▄▄▄▄ ▀█▀█▄▄█▄  █▀█ ▄▀▄▄  █ ▄ █▀▄▄▄
 █ ▄▄▄ █ █▄█▄██ ▀  ▀█▀▀█ ▀▄█▄█▄▄▄█▀▄█  
 █ ███ █ █▀█  ▄▀██▄█▀▀█▄▀▀█▄▀█ ▀ ▀▄▀██
 █▄▄▄▄▄█ ▄▀▄ ██▄▀▀▄  ▀▀▄  ▄▄▀▀▀▄ █▄▄▄█
                                      

Waiting validation finish...

2) Grant access by clicking Yes:

Pilot CLI authentication.png

3) Device Login Successful message will appear and your authentication browser window can be closed.

4) The output of the Command Line Tool will also be updated (see line 14 below) to notify you about the successful login:

$ pilotcli user login
Please, access https://iam.hdc.humanbrainproject.eu/realms/hdc/device?user_code=XXXX-XXXX to proceed
 ▄▄▄▄▄▄▄  ▄▄ ▄  ▄  ▄ ▄▄▄▄    ▄ ▄▄▄▄▄▄▄
 █ ▄▄▄ █ ▄ ▄▄▀█ █▀▀▀▄▀█▀  ▀██▄ █ ▄▄▄ █
 █ ███ █ ██▄   ▀▀▄▀▄▄█▄ ▄ ▀▀▀▄ █ ███ █
 █▄▄▄▄▄█ █▀▄▀█▀▄▀█▀▄ █ ▄ ▄ █▀█ █▄▄▄▄▄█
 ▄▄▄▄▄▄▄ ▀█▀█▄▄█▄  █▀█ ▄▀▄▄  █ ▄ █▀▄▄▄
 █ ▄▄▄ █ █▄█▄██ ▀  ▀█▀▀█ ▀▄█▄█▄▄▄█▀▄█  
 █ ███ █ █▀█  ▄▀██▄█▀▀█▄▀▀█▄▀█ ▀ ▀▄▀██
 █▄▄▄▄▄█ ▄▀▄ ██▄▀▀▄  ▀▀▄  ▄▄▀▀▀▄ █▄▄▄█
                                      

Waiting validation finish...
Welcome to Command Line Tool!

Command: logout

  • Options: -y --yes
  • Usage: Allows users to log out of the platform through pilotcli.
  • Prerequisites: User login is required, otherwise an error is returned: ‘The current login session is invalid. Please login to continue.'.
$ pilotcli user logout --help
Usage: pilotcli user logout [OPTIONS]

  For user to logout.

Options:
  -y, --yes  Input Y/yes to confirm you want to logout, otherwise input N/no
             to remain logged in.

  --help     Show this message and exit.

Examples

User logout:

$ pilotcli user logout
Are you sure you want to logout? [y/N]: y
Logged out successfully. Bye!

User logout canceled:

$ pilotcli user logout
Are you sure you want to logout? [y/N]: n
Logout canceled!

User logout with option to skip additional confirmation:

$ pilotcli user logout -y
Logged out successfully. Bye!

Project Commands: pilotcli project

Help

$ pilotcli project --help
Usage: pilotcli project [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

Commands:
  list  List accessible projects.

Command: list

  • Options: None
  • Usage: List all Projects to which the user has access
  • Prerequisite: User login is required, otherwise an error is returned: ‘The current login session is invalid. Please login to continue.'
$ pilotcli project list --help
Usage: pilotcli project list [OPTIONS]

  List accessible projects.

Options:
  --page INTEGER                  The page to be listed  [default: 0]
  --page-size INTEGER             number of objects per page  [default: 10]
  --order [asc|desc]              sorting order  [default: desc]
  --order-by [created_at|name|code]
                                  sorting column  [default: created_at]
  -d, --detached                  whether run in detached mode
  --help                          Show this message and exit.

Examples

Get a list of all Projects the user has access to:

$ pilotcli project list
              Project Name                            Project Code              
---------------------------------------------------------------------------
          Test Project 02-13             |           test230213byshan          
              Test1_Audit                |              test1audit             
              Test20221109               |             test20220109            
           Indoc Test Project            |           indoctestproject          

Page: 0, Number of projects: 4

By default, the table will only display the first ten elements. If the user has access to more than ten Projects, you will be prompted to use your arrow keys to select one of two options to either view the next ten items (next page), or to exit (exit). The selected option is indicated by two arrows and can be confirmed by hitting enter:

Page: 0, Number of projects: 10

What do you want? (Use arrow keys)
 » next page
   exit

File Commands: pilotcli file

Help

$ pilotcli file --help
Usage: pilotcli file [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

Commands:
  attribute-export  Export attribute template from a given Project.
  attribute-list    List attribute templates of a given Project.
  list              List files and folders inside a given Project/folder.
  resume            Resume the upload process with given manifest file.
  sync              Download files/folders from a given Project/folder/file...
  upload            Upload files/folders to a given Project path.

Command: attribute-list

  • Options: -p --project-code
  • Usage: List all attributes from a specified Project.
  • Prerequisite:
  • User login is required, otherwise an error is returned: ‘The current login session is invalid. Please login to continue.’
  • Requires the Project code, which can be retrieved via pilotcli project list.
$ pilotcli file attribute-list --help
Usage: pilotcli file attribute-list [OPTIONS]

  List attribute templates of a given Project.

Options:
  -p, --project-code TEXT  Project Code
  --help                   Show this message and exit.

Examples

List attributes from a given Project by providing the Project Code at the prompt. In this example, “cli” is the corresponding Project Code:

$ pilotcli file attribute-list
ProjectCode: cli

Manifest1
--------------------------------------------------------------------------
|    Attribute Name    |       Type      |        Value         | Optional |
--------------------------------------------------------------------------
|        attr1         | multiple_choice |    a1,a2,a3,a4,a5    |  False   |
--------------------------------------------------------------------------
|        attr2         |       text      |         None         |  False   |
--------------------------------------------------------------------------
|        attr3         | multiple_choice |    t1,t2,t3,t4,t5    |   True   |
--------------------------------------------------------------------------

Manifest2
--------------------------------------------------------------------------
|    Attribute Name    |       Type      |        Value         | Optional |
--------------------------------------------------------------------------
|        attr1         | multiple_choice |     a1,a2,a3,a4      |   True   |
--------------------------------------------------------------------------
|        attr2         |       text      |         None         |  False   |
--------------------------------------------------------------------------
|        attr3         | multiple_choice |       t1,t2,t3       |   True   |
--------------------------------------------------------------------------
All Attributes fetched successfully.

List attributes from given a Project and provide the Project Code “cli” as an option in the same line -p cli:

$ pilotcli file attribute-list -p cli

Manifest1
--------------------------------------------------------------------------
|    Attribute Name    |       Type      |        Value         | Optional |
--------------------------------------------------------------------------
|        attr1         | multiple_choice |    a1,a2,a3,a4,a5    |  False   |
--------------------------------------------------------------------------
|        attr2         |       text      |         None         |  False   |
--------------------------------------------------------------------------
|        attr3         | multiple_choice |    t1,t2,t3,t4,t5    |   True   |
--------------------------------------------------------------------------

Manifest2
--------------------------------------------------------------------------
|    Attribute Name    |       Type      |        Value         | Optional |
--------------------------------------------------------------------------
|        attr1         | multiple_choice |     a1,a2,a3,a4      |   True   |
--------------------------------------------------------------------------
|        attr2         |       text      |         None         |  False   |
--------------------------------------------------------------------------
|        attr3         | multiple_choice |       t1,t2,t3       |   True   |
--------------------------------------------------------------------------
All Attributes fetched successfully.

Command: attribute-export

  • Options: -p --project-code, -n --attribute-name
  • Usage: Export an attribute template as JSON-file from a given Project
  • Prerequisite:

    • User login is required, otherwise an error is returned: "The current login session is invalid. Please login to continue."
    • Project must be accessible to the user, otherwise an error is returned: "Project Code not found in list. Please verify and try again."
    • Requires the Project code, which can be retrieved via pilotcli project list.
    • Requires the Attribute template name. If the attribute template name does not exist or is spelled incorrectly, an error is returned: "Attribute 'sample-template' not found in Project. Please verify and try again."
    • pilotcli must have the permission to write a file in the directory, otherwise an error is returned.
$ pilotcli file attribute-export --help
Usage: pilotcli file attribute-export [OPTIONS]

  Export attribute template from a given Project.

Options:
  -p, --project-code TEXT    Project Code
  -n, --attribute-name TEXT  Attribute Template Name
  --help                     Show this message and exit.

Examples

Export an attribute template from a given Project. The user is prompted to provide the Project Code (“cli”) and the Attribute Template Name (“Manifest1”):

$ pilotcli file attribute-export
ProjectCode: cli
AttributeName: Manifest1

Manifest1
--------------------------------------------------------------------------
|    Attribute Name    |       Type      |        Value         | Optional |
--------------------------------------------------------------------------
|        attr1         | multiple_choice |    a1,a2,a3,a4,a5    |  False   |
--------------------------------------------------------------------------
|        attr2         |       text      |         None         |  False   |
--------------------------------------------------------------------------
|        attr3         | multiple_choice |    t1,t2,t3,t4,t5    |   True   |
--------------------------------------------------------------------------
Template saved successfully: cli_Manifest1_template.json
Attribute definition saved successfully: cli_Manifest1_definition.json

Export an attribute template from a given Project using options to provide both the Project Code (-p cli) and the Attribute Template Name (-n Manifest1), “cli” and “Manifest1” in this case, respectively:

$ pilotcli file attribute-export -p cli -n Manifest1

Manifest1
--------------------------------------------------------------------------
|    Attribute Name    |       Type      |        Value         | Optional |
--------------------------------------------------------------------------
|        attr1         | multiple_choice |    a1,a2,a3,a4,a5    |  False   |
--------------------------------------------------------------------------
|        attr2         |       text      |         None         |  False   |
--------------------------------------------------------------------------
|        attr3         | multiple_choice |    t1,t2,t3,t4,t5    |   True   |
--------------------------------------------------------------------------
Template saved successfully: cli_Manifest1_template.json
Attribute definition saved successfully: cli_Manifest1_definition.json

Command: list

  • Options: -z --zone
  • Usage: List files and folders in the specified directory within the Platform. Folders will be displayed in blue and files will be displayed in white (or black, depending on the background of your terminal). If no zone (i.e. Green Room or Core) is specified, Green Room will be used as default.
  • Prerequisite:

    • User login is required, otherwise an error is returned: "The current login session is invalid. Please login to continue."
    • Project must be accessible to the user, otherwise an error is returned: "Project Code not found in list. Please verify and try again."
    • Requires the Project code, which can be retrieved via pilotcli project list.
$ pilotcli file list --help
Usage: pilotcli file list [OPTIONS] PATHS

  List files and folders inside a given Project/folder.

Options:
  -z, --zone TEXT      Target Zone (i.e., core/greenroom)  [default:
                       greenroom]  [default: greenroom]

  --page INTEGER       The page to be listed  [default: 0]
  --page-size INTEGER  number of objects per page  [default: 10]
  -d, --detached       whether run in detached mode
  --help               Show this message and exit.

Examples

List folders in the directory “admin” in the Project with the Project Code “indoctestproject”. Since no zone was specified, the corresponding directory in the Green Room will be queried:

$ pilotcli file list indoctestproject/admin
test_folder1 test_folder2 file1 file2 file3

To list the corresponding elements in the “indoctestproject/admin” directory in the Projects' Core, the zone needs to be specified (-z core):

$ pilotcli file list indoctestproject/admin -z core
folder1 folder2 test_folder.zip file.txt sample.txt large-file.json

Command: upload

  • Options: -p --project, -a --attribute, -t --tag, -z --zone, -m --upload-message, -s --source-file, --zip, -td --thread, -o --output path
  • Usage: Upload files/folders to the given project, with optional tags and attributes, to the target folder.
  • Prerequisite:

    • User login is required, otherwise an error is returned: "The current login session is invalid. Please login to continue."
    • Project must be accessible to the user, otherwise an error is returned: "Project Code not found in list. Please verify and try again."
    • When uploading file to the Project Core, the user must have access to the Core (Project Contributors cannot upload files/folders to the Project Core).
$ pilotcli file upload --help
Usage: pilotcli file upload [OPTIONS] [PATHS]...

  Upload files/folders to a given Project path.

Options:
  -p, --project-path TEXT    Project folder path starting from Project code.
                             (i.e., indoctestproject/user/folder)  [required]

  -a, --attribute TEXT       File Attribute Template used for annotating files
                             during upload.

  -t, --tag TEXT             Add a tag to the file. This option could be used
                             multiple times for adding multiple tags.

  -z, --zone TEXT            Target Zone (i.e., core/greenroom)  [default:
                             greenroom]  [default: greenroom]

  -m, --upload-message TEXT  The message used to comment on the purpose of
                             uploading your processed file  [default: ]

  -s, --source-file TEXT     The Project path of the source file of your
                             processed files.

  --zip                      Upload folder as a compressed zip file.
  -td, --thread INTEGER      The number of thread for upload a file  [default:
                             1]

  -o, --output-path TEXT     The output path for the manifest file of
                             resumable upload  [default: ./manifest.json]

  --help                     Show this message and exit.

Examples

Upload a file (or folder) to a specified directory of a Project’s Green Room, in this case the file located at ./sample_folder/sample_file1 will be uploaded to the folder “admin” in the Project with the Project Code “cli” (-p cli/admin):

$ pilotcli file upload ./sample_folder/sample_file1 -p cli/admin
Starting upload of: ./sample_folder/sample_file1
Pre-upload complete.
uploader: admin container_id: 18061 total_size: 1048576 total_chunks: 1 uniq_identifier: e958247c-ce05-48b2-9038-78b774836256-1627498771 resumable_relative_path admin/
                                                                  
Upload job is finalizing, please wait...
Upload job complete.
All files uploaded successfully.

In case the specified destination directory does not exist yet, you will be prompted to confirm its creation by entering “y”, or to abort the command by entering “N”:

Target folder does not exist. Would you like to create a new folder? [y/N]: y

In order to upload a file (or folder) to a destination directory in a Project's Core, core must be specified as corresponding zone (-z core) and you will be required to provide a message to that should describe the files` content and why you are uploading it directly into the Core (-m "sample message"). Moreover, you will be reminded about the Terms of Use of the Platform and additional considerations regarding the direct upload of data into the Core zone, and are prompted to confirm your intention to proceed with the upload by entering “y” or “Yes”:


-


Copyright © 2023 Indoc Research.

HealthDataCloud is powered by Pilot technology, a product of Indoc Research.{{/code}}
)))