CLI tool for syncing GitHub repositories from ITCPR Cloud
Project description
ITCPR Cloud CLI
A command-line tool for syncing GitHub repositories from ITCPR Cloud to your local machine. Manage your repositories with secure device-based authentication and automated synchronization.
Features
- 🔐 Device-based authentication with ITCPR Cloud
- 📦 Automatic repository synchronization
- 🔄 Manual or continuous sync modes
- 💾 Local SQLite database for metadata tracking
- 🔒 Secure token storage using OS keyring
- 🛡️ Safe git operations with conflict detection
Installation
From PyPI (Recommended)
pip install itcpr
Or use pip3 or python3 -m pip if needed.
From Source
To install from source for development or contribution:
git clone https://github.com/ITCPR/cloud-cli
cd cloud-cli
pip install -e .
Or use pip3 or python3 -m pip if needed.
Uninstall
To remove the CLI tool:
pip uninstall itcpr
Note: This will remove the CLI tool but will not delete:
- Configuration files (
~/.itcpr/config.toml) - Local repository database (
~/.itcpr/repos.db) - Stored device tokens (in OS keyring)
To completely remove all data:
# Uninstall the package
pip uninstall itcpr
# Remove configuration and data
rm -rf ~/.itcpr
# Remove stored tokens from OS keyring
# On macOS: Use Keychain Access app to remove "itcpr" entries
# On Linux: Use your keyring manager (e.g., seahorse, kwallet)
# On Windows: Use Credential Manager
Requirements
- Python 3.10+
- Git (system installation)
- Access to api.itcpr.org (API) and cloud.itcpr.org (frontend)
Prerequisites
Important: Before using the CLI, you must:
- Visit cloud.itcpr.org
- Connect your GitHub account
- Ensure your repositories are assigned to your device
Once your GitHub account is connected and repositories are assigned, you can proceed with the CLI login.
Quick Start
1. Login
Authenticate your device with ITCPR Cloud:
itcpr login
Note: Make sure you've connected your GitHub account at cloud.itcpr.org before logging in.
This will:
- Open your browser to the device login page
- Display a device code
- Wait for approval
- Store credentials securely
2. Check Status
View your assigned repositories:
itcpr status
3. List Repositories
See all repositories assigned to your device:
itcpr repos
4. Clone a Repository
Clone a repository to your local machine:
itcpr clone paperport-itcpr
Or specify a custom path:
itcpr clone paperport-itcpr --path ~/projects/paperport
5. Sync Repositories
Sync all cloned repositories:
itcpr sync
Run continuous sync (watches for changes):
itcpr sync --watch
With custom interval:
itcpr sync --watch --interval 120 # Sync every 2 minutes
6. Logout
Clear stored credentials:
itcpr logout
Commands
itcpr login
Starts the device authentication flow. Opens your browser to the device login page at cloud.itcpr.org/device and polls the API for approval.
Prerequisite: Ensure your GitHub account is connected at cloud.itcpr.org before logging in.
itcpr logout
Revokes device token and clears local metadata.
itcpr status
Shows:
- Logged-in user information
- Device ID
- Assigned repositories
- Local repositories with sync status
itcpr repos
Lists all repositories assigned to this device with their clone status.
itcpr clone <repo>
Clones a repository from GitHub using short-lived installation tokens.
Options:
--path, -p: Custom local path for the repository
itcpr sync
Synchronizes all cloned repositories. By default, performs a one-time sync.
Options:
--watch, -w: Run continuous sync loop (watches for changes)--interval, -i: Sync interval in seconds (watch mode only, default: 60)
Per-Repository Configuration (itcpr.yml):
You can configure per-repository sync behavior by creating an itcpr.yml file in the repository root:
sync:
enabled: true # Enable/disable sync for this repo (default: true)
auto_commit: true # Auto-commit local changes (default: true)
auto_push: true # Auto-push local commits (default: true)
branch: main # Optional: specific branch to sync
ignore: # Optional: patterns to ignore
- "*.log"
- "temp/"
Note: To use itcpr.yml configuration files, install the optional YAML dependency:
pip install itcpr[yaml]
# OR
pip install PyYAML
How It Works
Authentication Flow
- Device requests an authentication code from the backend
- User approves the device in browser at
cloud.itcpr.org/device - Device token is stored securely in OS keyring
- Token is used for all subsequent API requests
Repository Synchronization
The sync process follows these steps:
- Fetches latest changes from the remote repository
- Detects uncommitted local changes
- Automatically commits local changes (if enabled)
- Pulls remote changes with rebase
- Pushes local commits (if enabled and permitted)
- Aborts on merge conflicts (requires manual resolution)
Security
- No Personal Access Tokens: Only uses backend-issued short-lived GitHub installation tokens
- Device Tokens: Revocable device authentication
- OS Keyring: Credentials stored securely using system keyring
- Safe Git Operations: Never force-pushes, detects conflicts
Configuration
Global Configuration
The CLI stores configuration and data in ~/.itcpr/:
- Configuration:
~/.itcpr/config.toml- Global settings - Repository Database:
~/.itcpr/repos.db- SQLite database for repository metadata
Per-Repository Configuration (itcpr.yml)
Each repository can have its own itcpr.yml file in the repository root to control sync behavior:
sync:
enabled: true # Enable/disable sync for this repo
auto_commit: true # Automatically commit local changes
auto_push: true # Automatically push local commits
branch: main # Optional: sync specific branch
ignore: [] # Optional: file patterns to ignore
Example: Disable auto-push for a repository
sync:
auto_push: false
Example: Disable sync entirely for a repository
sync:
enabled: false
Development & Mock Mode
The CLI includes a built-in mock mode for testing and development when the API is unavailable.
Automatic Mock Mode
When the API at api.itcpr.org is unavailable, the CLI automatically falls back to mock API responses:
- If the backend returns 404 or is unreachable, mock responses are used automatically
- You'll see a warning: "⚠️ Backend unavailable, using mock mode for testing"
Manual Mock Mode
You can also enable mock mode explicitly:
# Using environment variable
export ITCPR_MOCK_MODE=true
itcpr login
# Or set in config file (~/.itcpr/config.toml)
# mock_mode = true
Mock Features:
- Auto-approves device login after 2 seconds
- Provides sample user and repository data
- Generates mock GitHub tokens
- All commands work in mock mode for testing purposes
Troubleshooting
"Not logged in" error
Run itcpr login to authenticate your device. Make sure you've connected your GitHub account at cloud.itcpr.org first. If the backend is unavailable, mock mode will activate automatically for testing.
"Repository not assigned" error
The repository must be assigned to your device in ITCPR Cloud. Make sure you've:
- Connected your GitHub account at cloud.itcpr.org
- Assigned the repository to your device in the ITCPR Cloud dashboard
If the issue persists, contact an administrator.
Merge Conflicts
If a merge conflict is detected during sync:
- Resolve conflicts manually in the repository
- Commit the resolution
- Run
itcpr syncagain
Git Command Not Found
Ensure Git is installed and available in your PATH:
git --version
If Git is not installed, install it using your system's package manager.
Token Storage Issues
On Linux, you may need to install a keyring backend:
# For GNOME
sudo apt-get install python3-keyring
# For KDE
sudo apt-get install python3-keyring kdewallet
On macOS and Windows, the keyring should work out of the box.
Development
Project Structure
cloud-cli/
├── itcpr/
│ ├── __init__.py # Package initialization
│ ├── cli.py # CLI commands
│ ├── auth.py # Authentication
│ ├── api.py # API client
│ ├── gitops.py # Git operations
│ ├── sync.py # Sync logic
│ ├── config.py # Configuration
│ ├── storage.py # SQLite storage
│ └── utils.py # Utilities
├── setup.py # Setup script
├── pyproject.toml # Project metadata
└── README.md # This file
Development Setup
# Install in development mode
pip install -e .
# Run CLI
itcpr --help
Contributing
Contributions are welcome! Please ensure your code follows the project's style guidelines and includes appropriate tests.
API Endpoints
The CLI communicates with these backend endpoints:
POST /api/device/start- Start device authenticationGET /api/device/poll- Poll for authentication approvalPOST /api/device/revoke- Revoke device tokenGET /api/agent/me- Get device/user informationGET /api/agent/repos- Get assigned repositoriesPOST /api/agent/token- Get GitHub installation token
License
MIT License - see LICENSE file for details.
Support
For issues, questions, or feature requests, please contact ITCPR support or open an issue on GitHub.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file itcpr-2.1.1.tar.gz.
File metadata
- Download URL: itcpr-2.1.1.tar.gz
- Upload date:
- Size: 21.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec813374af474533ead1f68b462fb1d948ff0e4593914d42c700fbdd8fbd1bb2
|
|
| MD5 |
15b823475c32ae7018fdeafd503b8ac8
|
|
| BLAKE2b-256 |
f2972e753c77d7dc80f2e293065ed4faf084cdd27522e0ba3881caa89a47921d
|
File details
Details for the file itcpr-2.1.1-py3-none-any.whl.
File metadata
- Download URL: itcpr-2.1.1-py3-none-any.whl
- Upload date:
- Size: 20.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1dcfa82f0423dc92a6e87084541d027df46bc988f27755c34ad2b741d02d0e1e
|
|
| MD5 |
843887c82bcbea3f1cec3a89e526d6d7
|
|
| BLAKE2b-256 |
27171413726cf3ac59108a333880bed2b78310e096573705962b9da99c37be12
|