itcpr 2.0.2__tar.gz → 2.0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ include README.md
2
+ include LICENSE
3
+ recursive-include itcpr *.py
4
+
itcpr-2.0.4/PKG-INFO ADDED
@@ -0,0 +1,338 @@
1
+ Metadata-Version: 2.4
2
+ Name: itcpr
3
+ Version: 2.0.4
4
+ Summary: CLI tool for syncing GitHub repositories from ITCPR Cloud
5
+ Home-page: https://github.com/ITCPR/itcpr
6
+ Author: ITCPR
7
+ Author-email: ITCPR <info@itcpr.org>
8
+ License: MIT
9
+ Keywords: itcpr,github,git,sync,cli,repository
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ Requires-Dist: click>=8.0.0
20
+ Requires-Dist: requests>=2.28.0
21
+ Requires-Dist: keyring>=23.0.0
22
+ Requires-Dist: tomli-w>=1.0.0
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest; extra == "dev"
25
+ Requires-Dist: black; extra == "dev"
26
+ Requires-Dist: flake8; extra == "dev"
27
+ Dynamic: author
28
+ Dynamic: home-page
29
+ Dynamic: requires-python
30
+
31
+ # ITCPR CLI
32
+
33
+ A production-ready CLI tool for syncing GitHub repositories from ITCPR Cloud to your local machine.
34
+
35
+ ## Features
36
+
37
+ - 🔐 Device-based authentication with cloud.itcpr.org
38
+ - 📦 Automatic repository synchronization
39
+ - 🔄 Manual or continuous sync modes
40
+ - 💾 Local SQLite database for metadata tracking
41
+ - 🔒 Secure token storage using OS keyring
42
+ - 🛡️ Safe git operations with conflict detection
43
+
44
+ ## Installation
45
+
46
+ ### From PyPI (Recommended)
47
+
48
+ ```bash
49
+ pip install itcpr
50
+ # OR
51
+ pip3 install itcpr
52
+ # OR
53
+ python3 -m pip install itcpr
54
+ ```
55
+
56
+ ### From Source
57
+
58
+ If you want to install from source or contribute:
59
+
60
+ ```bash
61
+ git clone <repository-url>
62
+ cd cloud-cli
63
+ pip install -e .
64
+ # OR
65
+ pip3 install -e .
66
+ # OR
67
+ python3 -m pip install -e .
68
+ ```
69
+
70
+ ### Uninstall
71
+
72
+ To remove the CLI tool:
73
+
74
+ ```bash
75
+ pip uninstall itcpr
76
+ ```
77
+
78
+ **Note:** This will remove the CLI tool but will **not** delete:
79
+ - Configuration files (`~/.itcpr/config.toml`)
80
+ - Local repository database (`~/.itcpr/repos.db`)
81
+ - Stored device tokens (in OS keyring)
82
+
83
+ To completely remove all data:
84
+
85
+ ```bash
86
+ # Uninstall the package
87
+ pip uninstall itcpr
88
+ # OR
89
+ pip3 uninstall itcpr
90
+ # OR
91
+ python3 -m pip uninstall itcpr
92
+
93
+ # Remove configuration and data
94
+ rm -rf ~/.itcpr
95
+
96
+ # Remove stored tokens (OS keyring)
97
+ # On macOS: Use Keychain Access app to remove "itcpr" entries
98
+ # On Linux: Use your keyring manager (e.g., seahorse, kwallet)
99
+ # On Windows: Use Credential Manager
100
+ ```
101
+
102
+ ### Requirements
103
+
104
+ - Python 3.10+
105
+ - Git (system installation)
106
+ - Access to cloud.itcpr.org
107
+
108
+ ## Quick Start
109
+
110
+ ### 1. Login
111
+
112
+ Authenticate your device with ITCPR Cloud:
113
+
114
+ ```bash
115
+ itcpr login
116
+ ```
117
+
118
+ This will:
119
+ - Open your browser to the device login page
120
+ - Display a device code
121
+ - Wait for approval
122
+ - Store credentials securely
123
+
124
+ ### 2. Check Status
125
+
126
+ View your assigned repositories:
127
+
128
+ ```bash
129
+ itcpr status
130
+ ```
131
+
132
+ ### 3. List Repositories
133
+
134
+ See all repositories assigned to your device:
135
+
136
+ ```bash
137
+ itcpr repos
138
+ ```
139
+
140
+ ### 4. Clone a Repository
141
+
142
+ Clone a repository to your local machine:
143
+
144
+ ```bash
145
+ itcpr clone paperport-itcpr
146
+ ```
147
+
148
+ Or specify a custom path:
149
+
150
+ ```bash
151
+ itcpr clone paperport-itcpr --path ~/projects/paperport
152
+ ```
153
+
154
+ ### 5. Sync Repositories
155
+
156
+ Sync all cloned repositories:
157
+
158
+ ```bash
159
+ itcpr sync
160
+ ```
161
+
162
+ Run continuous sync (watches for changes):
163
+
164
+ ```bash
165
+ itcpr sync --watch
166
+ ```
167
+
168
+ With custom interval:
169
+
170
+ ```bash
171
+ itcpr sync --watch --interval 120 # Sync every 2 minutes
172
+ ```
173
+
174
+ ### 6. Logout
175
+
176
+ Clear stored credentials:
177
+
178
+ ```bash
179
+ itcpr logout
180
+ ```
181
+
182
+ ## Commands
183
+
184
+ ### `itcpr login`
185
+
186
+ Starts device authentication flow. Opens browser to `cloud.itcpr.org/device` and polls for approval.
187
+
188
+ ### `itcpr logout`
189
+
190
+ Revokes device token and clears local metadata.
191
+
192
+ ### `itcpr status`
193
+
194
+ Shows:
195
+ - Logged-in user information
196
+ - Device ID
197
+ - Assigned repositories
198
+ - Local repositories with sync status
199
+
200
+ ### `itcpr repos`
201
+
202
+ Lists all repositories assigned to this device with their clone status.
203
+
204
+ ### `itcpr clone <repo>`
205
+
206
+ Clones a repository from GitHub using short-lived installation tokens.
207
+
208
+ Options:
209
+ - `--path, -p`: Custom local path for the repository
210
+
211
+ ### `itcpr sync`
212
+
213
+ One-shot synchronization of all cloned repositories.
214
+
215
+ Options:
216
+ - `--watch, -w`: Run continuous sync loop
217
+ - `--interval, -i`: Sync interval in seconds (watch mode only, default: 60)
218
+
219
+ ## How It Works
220
+
221
+ ### Authentication
222
+
223
+ 1. Device requests authentication code from backend
224
+ 2. User approves device in browser at `cloud.itcpr.org/device`
225
+ 3. Device token is stored securely in OS keyring
226
+ 4. Token is used for all API requests
227
+
228
+ ### Repository Sync
229
+
230
+ 1. Fetches latest changes from remote
231
+ 2. Detects uncommitted local changes
232
+ 3. Commits local changes if any
233
+ 4. Pulls remote changes with rebase
234
+ 5. Pushes local commits if permitted
235
+ 6. Aborts on merge conflicts (requires manual resolution)
236
+
237
+ ### Security
238
+
239
+ - **No Personal Access Tokens**: Only uses backend-issued short-lived GitHub installation tokens
240
+ - **Device Tokens**: Revocable device authentication
241
+ - **OS Keyring**: Credentials stored securely using system keyring
242
+ - **Safe Git Operations**: Never force-pushes, detects conflicts
243
+
244
+ ## Configuration
245
+
246
+ Configuration is stored in `~/.itcpr/config.toml`.
247
+
248
+ Repository metadata is stored in `~/.itcpr/repos.db` (SQLite).
249
+
250
+ ## Troubleshooting
251
+
252
+ ### "Not logged in" error
253
+
254
+ Run `itcpr login` to authenticate your device.
255
+
256
+ ### "Repository not assigned" error
257
+
258
+ The repository must be assigned to your device in ITCPR Cloud. Contact an administrator.
259
+
260
+ ### Merge conflicts
261
+
262
+ If a merge conflict is detected during sync:
263
+ 1. Resolve conflicts manually in the repository
264
+ 2. Commit the resolution
265
+ 3. Run `itcpr sync` again
266
+
267
+ ### Git command not found
268
+
269
+ Ensure Git is installed and available in your PATH:
270
+ ```bash
271
+ git --version
272
+ ```
273
+
274
+ ### Token storage issues
275
+
276
+ On Linux, you may need to install a keyring backend:
277
+ ```bash
278
+ # For GNOME
279
+ sudo apt-get install python3-keyring
280
+
281
+ # For KDE
282
+ sudo apt-get install python3-keyring kdewallet
283
+ ```
284
+
285
+ ## Development
286
+
287
+ ### Project Structure
288
+
289
+ ```
290
+ cloud-cli/
291
+ ├── itcpr/
292
+ │ ├── __init__.py # Package initialization
293
+ │ ├── cli.py # CLI commands
294
+ │ ├── auth.py # Authentication
295
+ │ ├── api.py # API client
296
+ │ ├── gitops.py # Git operations
297
+ │ ├── sync.py # Sync logic
298
+ │ ├── config.py # Configuration
299
+ │ ├── storage.py # SQLite storage
300
+ │ └── utils.py # Utilities
301
+ ├── setup.py # Setup script
302
+ ├── pyproject.toml # Project metadata
303
+ └── README.md # This file
304
+ ```
305
+
306
+ ### Running Tests
307
+
308
+ ```bash
309
+ # Install in development mode
310
+ pip install -e .
311
+ # OR
312
+ pip3 install -e .
313
+ # OR
314
+ python3 -m pip install -e .
315
+
316
+ # Run CLI
317
+ itcpr --help
318
+ ```
319
+
320
+ ## API Endpoints
321
+
322
+ The CLI communicates with these backend endpoints:
323
+
324
+ - `POST /api/device/start` - Start device authentication
325
+ - `GET /api/device/poll` - Poll for authentication approval
326
+ - `POST /api/device/revoke` - Revoke device token
327
+ - `GET /api/agent/me` - Get device/user information
328
+ - `GET /api/agent/repos` - Get assigned repositories
329
+ - `POST /api/agent/token` - Get GitHub installation token
330
+
331
+ ## License
332
+
333
+ MIT License
334
+
335
+ ## Support
336
+
337
+ For issues and questions, contact ITCPR support or open an issue on GitHub.
338
+
itcpr-2.0.4/README.md ADDED
@@ -0,0 +1,308 @@
1
+ # ITCPR CLI
2
+
3
+ A production-ready CLI tool for syncing GitHub repositories from ITCPR Cloud to your local machine.
4
+
5
+ ## Features
6
+
7
+ - 🔐 Device-based authentication with cloud.itcpr.org
8
+ - 📦 Automatic repository synchronization
9
+ - 🔄 Manual or continuous sync modes
10
+ - 💾 Local SQLite database for metadata tracking
11
+ - 🔒 Secure token storage using OS keyring
12
+ - 🛡️ Safe git operations with conflict detection
13
+
14
+ ## Installation
15
+
16
+ ### From PyPI (Recommended)
17
+
18
+ ```bash
19
+ pip install itcpr
20
+ # OR
21
+ pip3 install itcpr
22
+ # OR
23
+ python3 -m pip install itcpr
24
+ ```
25
+
26
+ ### From Source
27
+
28
+ If you want to install from source or contribute:
29
+
30
+ ```bash
31
+ git clone <repository-url>
32
+ cd cloud-cli
33
+ pip install -e .
34
+ # OR
35
+ pip3 install -e .
36
+ # OR
37
+ python3 -m pip install -e .
38
+ ```
39
+
40
+ ### Uninstall
41
+
42
+ To remove the CLI tool:
43
+
44
+ ```bash
45
+ pip uninstall itcpr
46
+ ```
47
+
48
+ **Note:** This will remove the CLI tool but will **not** delete:
49
+ - Configuration files (`~/.itcpr/config.toml`)
50
+ - Local repository database (`~/.itcpr/repos.db`)
51
+ - Stored device tokens (in OS keyring)
52
+
53
+ To completely remove all data:
54
+
55
+ ```bash
56
+ # Uninstall the package
57
+ pip uninstall itcpr
58
+ # OR
59
+ pip3 uninstall itcpr
60
+ # OR
61
+ python3 -m pip uninstall itcpr
62
+
63
+ # Remove configuration and data
64
+ rm -rf ~/.itcpr
65
+
66
+ # Remove stored tokens (OS keyring)
67
+ # On macOS: Use Keychain Access app to remove "itcpr" entries
68
+ # On Linux: Use your keyring manager (e.g., seahorse, kwallet)
69
+ # On Windows: Use Credential Manager
70
+ ```
71
+
72
+ ### Requirements
73
+
74
+ - Python 3.10+
75
+ - Git (system installation)
76
+ - Access to cloud.itcpr.org
77
+
78
+ ## Quick Start
79
+
80
+ ### 1. Login
81
+
82
+ Authenticate your device with ITCPR Cloud:
83
+
84
+ ```bash
85
+ itcpr login
86
+ ```
87
+
88
+ This will:
89
+ - Open your browser to the device login page
90
+ - Display a device code
91
+ - Wait for approval
92
+ - Store credentials securely
93
+
94
+ ### 2. Check Status
95
+
96
+ View your assigned repositories:
97
+
98
+ ```bash
99
+ itcpr status
100
+ ```
101
+
102
+ ### 3. List Repositories
103
+
104
+ See all repositories assigned to your device:
105
+
106
+ ```bash
107
+ itcpr repos
108
+ ```
109
+
110
+ ### 4. Clone a Repository
111
+
112
+ Clone a repository to your local machine:
113
+
114
+ ```bash
115
+ itcpr clone paperport-itcpr
116
+ ```
117
+
118
+ Or specify a custom path:
119
+
120
+ ```bash
121
+ itcpr clone paperport-itcpr --path ~/projects/paperport
122
+ ```
123
+
124
+ ### 5. Sync Repositories
125
+
126
+ Sync all cloned repositories:
127
+
128
+ ```bash
129
+ itcpr sync
130
+ ```
131
+
132
+ Run continuous sync (watches for changes):
133
+
134
+ ```bash
135
+ itcpr sync --watch
136
+ ```
137
+
138
+ With custom interval:
139
+
140
+ ```bash
141
+ itcpr sync --watch --interval 120 # Sync every 2 minutes
142
+ ```
143
+
144
+ ### 6. Logout
145
+
146
+ Clear stored credentials:
147
+
148
+ ```bash
149
+ itcpr logout
150
+ ```
151
+
152
+ ## Commands
153
+
154
+ ### `itcpr login`
155
+
156
+ Starts device authentication flow. Opens browser to `cloud.itcpr.org/device` and polls for approval.
157
+
158
+ ### `itcpr logout`
159
+
160
+ Revokes device token and clears local metadata.
161
+
162
+ ### `itcpr status`
163
+
164
+ Shows:
165
+ - Logged-in user information
166
+ - Device ID
167
+ - Assigned repositories
168
+ - Local repositories with sync status
169
+
170
+ ### `itcpr repos`
171
+
172
+ Lists all repositories assigned to this device with their clone status.
173
+
174
+ ### `itcpr clone <repo>`
175
+
176
+ Clones a repository from GitHub using short-lived installation tokens.
177
+
178
+ Options:
179
+ - `--path, -p`: Custom local path for the repository
180
+
181
+ ### `itcpr sync`
182
+
183
+ One-shot synchronization of all cloned repositories.
184
+
185
+ Options:
186
+ - `--watch, -w`: Run continuous sync loop
187
+ - `--interval, -i`: Sync interval in seconds (watch mode only, default: 60)
188
+
189
+ ## How It Works
190
+
191
+ ### Authentication
192
+
193
+ 1. Device requests authentication code from backend
194
+ 2. User approves device in browser at `cloud.itcpr.org/device`
195
+ 3. Device token is stored securely in OS keyring
196
+ 4. Token is used for all API requests
197
+
198
+ ### Repository Sync
199
+
200
+ 1. Fetches latest changes from remote
201
+ 2. Detects uncommitted local changes
202
+ 3. Commits local changes if any
203
+ 4. Pulls remote changes with rebase
204
+ 5. Pushes local commits if permitted
205
+ 6. Aborts on merge conflicts (requires manual resolution)
206
+
207
+ ### Security
208
+
209
+ - **No Personal Access Tokens**: Only uses backend-issued short-lived GitHub installation tokens
210
+ - **Device Tokens**: Revocable device authentication
211
+ - **OS Keyring**: Credentials stored securely using system keyring
212
+ - **Safe Git Operations**: Never force-pushes, detects conflicts
213
+
214
+ ## Configuration
215
+
216
+ Configuration is stored in `~/.itcpr/config.toml`.
217
+
218
+ Repository metadata is stored in `~/.itcpr/repos.db` (SQLite).
219
+
220
+ ## Troubleshooting
221
+
222
+ ### "Not logged in" error
223
+
224
+ Run `itcpr login` to authenticate your device.
225
+
226
+ ### "Repository not assigned" error
227
+
228
+ The repository must be assigned to your device in ITCPR Cloud. Contact an administrator.
229
+
230
+ ### Merge conflicts
231
+
232
+ If a merge conflict is detected during sync:
233
+ 1. Resolve conflicts manually in the repository
234
+ 2. Commit the resolution
235
+ 3. Run `itcpr sync` again
236
+
237
+ ### Git command not found
238
+
239
+ Ensure Git is installed and available in your PATH:
240
+ ```bash
241
+ git --version
242
+ ```
243
+
244
+ ### Token storage issues
245
+
246
+ On Linux, you may need to install a keyring backend:
247
+ ```bash
248
+ # For GNOME
249
+ sudo apt-get install python3-keyring
250
+
251
+ # For KDE
252
+ sudo apt-get install python3-keyring kdewallet
253
+ ```
254
+
255
+ ## Development
256
+
257
+ ### Project Structure
258
+
259
+ ```
260
+ cloud-cli/
261
+ ├── itcpr/
262
+ │ ├── __init__.py # Package initialization
263
+ │ ├── cli.py # CLI commands
264
+ │ ├── auth.py # Authentication
265
+ │ ├── api.py # API client
266
+ │ ├── gitops.py # Git operations
267
+ │ ├── sync.py # Sync logic
268
+ │ ├── config.py # Configuration
269
+ │ ├── storage.py # SQLite storage
270
+ │ └── utils.py # Utilities
271
+ ├── setup.py # Setup script
272
+ ├── pyproject.toml # Project metadata
273
+ └── README.md # This file
274
+ ```
275
+
276
+ ### Running Tests
277
+
278
+ ```bash
279
+ # Install in development mode
280
+ pip install -e .
281
+ # OR
282
+ pip3 install -e .
283
+ # OR
284
+ python3 -m pip install -e .
285
+
286
+ # Run CLI
287
+ itcpr --help
288
+ ```
289
+
290
+ ## API Endpoints
291
+
292
+ The CLI communicates with these backend endpoints:
293
+
294
+ - `POST /api/device/start` - Start device authentication
295
+ - `GET /api/device/poll` - Poll for authentication approval
296
+ - `POST /api/device/revoke` - Revoke device token
297
+ - `GET /api/agent/me` - Get device/user information
298
+ - `GET /api/agent/repos` - Get assigned repositories
299
+ - `POST /api/agent/token` - Get GitHub installation token
300
+
301
+ ## License
302
+
303
+ MIT License
304
+
305
+ ## Support
306
+
307
+ For issues and questions, contact ITCPR support or open an issue on GitHub.
308
+
@@ -0,0 +1,4 @@
1
+ """ITCPR Agent - CLI tool for syncing GitHub repositories."""
2
+
3
+ __version__ = "2.0.4"
4
+
@@ -0,0 +1,73 @@
1
+ """API client for cloud.itcpr.org."""
2
+
3
+ import requests
4
+ from typing import List, Dict, Any, Optional
5
+ from .auth import Auth
6
+ from .utils import get_logger, print_error
7
+
8
+ logger = get_logger(__name__)
9
+
10
+ class APIClient:
11
+ """Client for ITCPR Cloud API."""
12
+
13
+ def __init__(self, auth: Auth):
14
+ self.auth = auth
15
+ self.api_base = auth.api_base
16
+
17
+ def _get_headers(self) -> Dict[str, str]:
18
+ """Get request headers with authentication."""
19
+ headers = {"Content-Type": "application/json"}
20
+ token = self.auth.get_token()
21
+ if token:
22
+ headers["Authorization"] = f"Bearer {token}"
23
+ return headers
24
+
25
+ def _request(self, method: str, endpoint: str, **kwargs) -> requests.Response:
26
+ """Make authenticated API request."""
27
+ url = f"{self.api_base}{endpoint}"
28
+ headers = self._get_headers()
29
+ headers.update(kwargs.pop("headers", {}))
30
+
31
+ try:
32
+ response = requests.request(method, url, headers=headers, timeout=30, **kwargs)
33
+ return response
34
+ except requests.RequestException as e:
35
+ logger.error(f"API request failed: {e}")
36
+ raise
37
+
38
+ def get_me(self) -> Dict[str, Any]:
39
+ """Get current user/device information."""
40
+ response = self._request("GET", "/api/agent/me")
41
+ response.raise_for_status()
42
+ return response.json()
43
+
44
+ def get_repos(self) -> List[Dict[str, Any]]:
45
+ """Get list of assigned repositories."""
46
+ response = self._request("GET", "/api/agent/repos")
47
+ response.raise_for_status()
48
+ data = response.json()
49
+ return data.get("repos", [])
50
+
51
+ def get_github_token(self, repo_name: Optional[str] = None) -> str:
52
+ """Get short-lived GitHub installation token."""
53
+ payload = {}
54
+ if repo_name:
55
+ payload["repo"] = repo_name
56
+
57
+ response = self._request("POST", "/api/agent/token", json=payload)
58
+ response.raise_for_status()
59
+ data = response.json()
60
+ return data.get("token")
61
+
62
+ def validate_token(self) -> bool:
63
+ """Validate current device token."""
64
+ try:
65
+ self.get_me()
66
+ return True
67
+ except requests.HTTPError as e:
68
+ if e.response.status_code == 401:
69
+ return False
70
+ raise
71
+ except Exception:
72
+ return False
73
+