|
| 1 | +--- |
| 2 | +jupyter: |
| 3 | + jupytext: |
| 4 | + text_representation: |
| 5 | + extension: .md |
| 6 | + format_name: markdown |
| 7 | + format_version: '1.2' |
| 8 | + jupytext_version: 1.7.1 |
| 9 | + kernelspec: |
| 10 | + display_name: Python 3 |
| 11 | + language: python |
| 12 | + name: python3 |
| 13 | +--- |
| 14 | + |
| 15 | +# Jupyter magic commands |
| 16 | + |
| 17 | +Commands are provided by the *pythonhere* extension |
| 18 | + |
| 19 | +```python |
| 20 | +%load_ext pythonhere |
| 21 | +``` |
| 22 | + |
| 23 | +## connect-there |
| 24 | +**Connect to remote interpreter via SSH.** |
| 25 | + |
| 26 | +Command takes single optional argument: location of connection config.<br> |
| 27 | +If argument is not provided, values are loaded from the **there.env** file. |
| 28 | + |
| 29 | +Config values could be overridden by environment variables with same names. |
| 30 | + |
| 31 | +```python |
| 32 | +import os |
| 33 | +os.environ["THERE_PORT"] = "8022" |
| 34 | +``` |
| 35 | + |
| 36 | +```python |
| 37 | +%connect-there there.env |
| 38 | +``` |
| 39 | + |
| 40 | +### there.env example |
| 41 | +``` |
| 42 | +# PythonHere device IP address |
| 43 | +THERE_HOST=127.0.0.1 |
| 44 | +
|
| 45 | +# Port, as set in PythonHere app Settings section |
| 46 | +THERE_PORT=8023 |
| 47 | +
|
| 48 | +# Username, as set in PythonHere app Settings section |
| 49 | +THERE_USERNAME=admin |
| 50 | +
|
| 51 | +# Password, as set in PythonHere app Settings section |
| 52 | +THERE_PASSWORD=xxx |
| 53 | +``` |
| 54 | + |
| 55 | + |
| 56 | +## %there group of commands |
| 57 | + |
| 58 | +```python |
| 59 | +%there --help |
| 60 | +``` |
| 61 | + |
| 62 | +Default action for *%there*, if command is not specified - execute python code. |
| 63 | + |
| 64 | + |
| 65 | +## there |
| 66 | +**Execute python code on the remote side.**<br> |
| 67 | + |
| 68 | +```python |
| 69 | +%%there |
| 70 | +import this |
| 71 | +``` |
| 72 | + |
| 73 | +## kv |
| 74 | + |
| 75 | +```python |
| 76 | +%there kv --help |
| 77 | +``` |
| 78 | + |
| 79 | +If option `--clear-style` is provided,<br> all previous rules, that was loaded with *%%there kv* command, |
| 80 | +are unloaded before command execution. |
| 81 | + |
| 82 | +If root widget is defined, it will replace App's current root. |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | +```python |
| 87 | +%%there kv |
| 88 | +Image: |
| 89 | + source: "../app/data/logo/logo-128.png" |
| 90 | + canvas.before: |
| 91 | + PushMatrix |
| 92 | + Rotate: |
| 93 | + angle: 45 |
| 94 | + origin: self.center |
| 95 | + canvas.after: |
| 96 | + PopMatrix |
| 97 | +``` |
| 98 | + |
| 99 | +## shell |
| 100 | + |
| 101 | +```python |
| 102 | +%there shell --help |
| 103 | +``` |
| 104 | + |
| 105 | +```python |
| 106 | +%%there shell |
| 107 | +pwd |
| 108 | +``` |
| 109 | + |
| 110 | +```python |
| 111 | +%%there shell |
| 112 | +for i in 1 2 3 |
| 113 | +do |
| 114 | + echo -n "$i" |
| 115 | +done |
| 116 | +``` |
| 117 | + |
| 118 | +<!-- #region hideCode=false --> |
| 119 | +Listen to Android system logs in the background and show last two lines of output: |
| 120 | +<!-- #endregion --> |
| 121 | + |
| 122 | +```python |
| 123 | +%%there -bl 2 shell |
| 124 | +logcat |
| 125 | +``` |
| 126 | + |
| 127 | +## upload |
| 128 | + |
| 129 | +```python |
| 130 | +%there upload --help |
| 131 | +``` |
| 132 | + |
| 133 | +*upload* root directory is application current working directory. |
| 134 | + |
| 135 | +```python |
| 136 | +!touch some.ico script.py |
| 137 | +!mkdir -p dir1/dir2 |
| 138 | +``` |
| 139 | + |
| 140 | +```python |
| 141 | +%there upload some.ico script.py dir1 ../ |
| 142 | +``` |
| 143 | + |
| 144 | +```python |
| 145 | +%%there shell |
| 146 | +find |
| 147 | +``` |
| 148 | + |
| 149 | +## log |
| 150 | + |
| 151 | +```python |
| 152 | +%there log --help |
| 153 | +``` |
| 154 | + |
| 155 | +```{note} |
| 156 | +Since the command blocks and never ends, it is useful to run with --backgroud (-b) option |
| 157 | +``` |
| 158 | + |
| 159 | +```python |
| 160 | +%there -bl 1 log |
| 161 | +``` |
| 162 | + |
| 163 | +```python |
| 164 | +%%there |
| 165 | +from kivy.logger import Logger |
| 166 | +Logger.info("Hello from the future cell") |
| 167 | +``` |
| 168 | + |
| 169 | +## screeenshot |
| 170 | + |
| 171 | +```python |
| 172 | +%there screenshot --help |
| 173 | +``` |
| 174 | + |
| 175 | +* Wait for half of a second before a command execution,<br> |
| 176 | +* make a screenshot, |
| 177 | +* display a result constrained to 200px width, |
| 178 | +* and save image to a local file: |
| 179 | + |
| 180 | +```python |
| 181 | +%there -d .5 screenshot -w 200 -o /tmp/screenshot_test.png |
| 182 | +``` |
0 commit comments