|
| 1 | +''' |
| 2 | +Copyright 2021 Robert Schroll |
| 3 | +
|
| 4 | +This program is free software: you can redistribute it and/or modify |
| 5 | +it under the terms of the GNU General Public License as published by |
| 6 | +the Free Software Foundation, either version 3 of the License, or |
| 7 | +(at your option) any later version. |
| 8 | +
|
| 9 | +This program is distributed in the hope that it will be useful, |
| 10 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +GNU General Public License for more details. |
| 13 | +
|
| 14 | +You should have received a copy of the GNU General Public License |
| 15 | +along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | +''' |
| 17 | + |
| 18 | +import argparse |
| 19 | +import subprocess |
| 20 | +import sys |
| 21 | +import textwrap |
| 22 | + |
| 23 | +from .constants import TEMPLATE_PATH |
| 24 | + |
| 25 | +def main(): |
| 26 | + parser = argparse.ArgumentParser(description="Load the templates from a Remarkable device for use with rmrl") |
| 27 | + parser.add_argument('ip', nargs='?', default='10.11.99.1', help=""" |
| 28 | + IP address of Remarkable device. Defaults to the value used when |
| 29 | + plugged in via USB. Possible values can be found under Settings > |
| 30 | + Help > Copyrights and licenses, under the GPLv3 Compliance section.""") |
| 31 | + args = parser.parse_args() |
| 32 | + |
| 33 | + print(textwrap.dedent(f""" |
| 34 | + About to connect to your Remarkable device at {args.ip}. |
| 35 | +
|
| 36 | + If this is the first time SSHing into your Remarkable device, you may |
| 37 | + see a warning that the authenticity of the host can't be established. |
| 38 | + This is expected; type 'yes' to continue. |
| 39 | +
|
| 40 | + If you have not set up SSH keys on your Remarkable device, you will be |
| 41 | + prompted to enter a password. This is NOT your lock screen passcode. |
| 42 | + It can be found under Settings > Help > Copyrights and licences, under |
| 43 | + the GPLv3 Compliance section. |
| 44 | + """).strip()) |
| 45 | + print("") |
| 46 | + |
| 47 | + TEMPLATE_PATH.mkdir(parents=True, exist_ok=True) |
| 48 | + try: |
| 49 | + completed = subprocess.run(['scp', f'root@{args.ip}:/usr/share/remarkable/templates/*.svg', TEMPLATE_PATH], |
| 50 | + stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr) |
| 51 | + except FileNotFoundError: |
| 52 | + print("Could not find the 'scp' program.") |
| 53 | + print("This should be installed as part of SSH.") |
| 54 | + return 1 |
| 55 | + |
| 56 | + if completed.returncode == 0: |
| 57 | + print("") |
| 58 | + print(f"Templates copied to {TEMPLATE_PATH}") |
| 59 | + else: |
| 60 | + print("") |
| 61 | + print(f"Error: Got return code of {completed.returncode}") |
| 62 | + print("The cause may be indicated in the output above.") |
| 63 | + return completed.returncode |
| 64 | + |
| 65 | +if __name__ == '__main__': |
| 66 | + sys.exit(main()) |
0 commit comments