diff --git a/docs/config.example.yaml b/docs/config.example.yaml index 4739515..4041c84 100644 --- a/docs/config.example.yaml +++ b/docs/config.example.yaml @@ -6,12 +6,13 @@ sync: global-exclude: - .DS_Store - Thumbs.db + - desktop.ini conflict-handling: local-changes: ask remote-deleted: ask - default-local-dir: /path/to/your/files// + default-local-dir: /path/to/your/files// #E.g. /home/user/hsr// repositories: InfSi1: @@ -19,3 +20,6 @@ sync: exclude: - '*.exe' - 'Archiv' + OO: + remote-dir: Informatik\Fachbereich\Objektorientierte_Programmierung\OO + diff --git a/docs/install.md b/docs/install.md index a26323d..f047ecd 100644 --- a/docs/install.md +++ b/docs/install.md @@ -9,6 +9,43 @@ Führe folgende Befehle als root aus! ## Für Linux-Distributionen: +###Sync +1. Install dependencies + + ``` + $ sudo apt-get install git python3-setuptools gcc python3-dev libffi-dev libssl-dev python3-pip -y + ``` + +2. Clone repo + + ``` + $ git clone https://github.com/openhsr/connect.git + $ cd connect + ``` + +3. Build & install + + ``` + $ sudo python3 ./setup.py install + ``` + +4. Set up sync settings + + ``` + $ openhsr-connect edit + ``` + + Enter HSR information, modify config file for your classes ([See example configuration](https://github.com/openhsr/connect/blob/master/docs/config.example.yaml)) + +5. Profit! + + ``` + $ openhsr-connect sync + ``` + + Sync the specified directories with the script server. + + ### Drucker Damit CUPS das E-Mail-Backend nutzen kann muss dieses verlinkt werden. @@ -42,7 +79,55 @@ if [ $? -eq 0 ]; then lpadmin -x openhsr-connect fi ``` -## Für Mac OS X: +## Für macOS: + +### Sync + +1. Install [Homebrew](http://brew.sh/) + + ``` + $/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + ``` + + +2. Install Python 3 + + ``` + $ brew install python3 + ``` + +3. Clone repo + + ``` + $ git clone https://github.com/openhsr/connect.git + $ cd connect + ``` + + +4. Build & install + + ``` + $ python3 ./setup.py install + ``` + + +5. Set up sync settings + + ``` + $ openhsr-connect edit + ``` + + Enter HSR information, modify config file for your classes ([See example configuration](https://github.com/openhsr/connect/blob/master/docs/config.example.yaml)) + If you get a decoding error and the application crashes after entering your email address, make sure you have your encoding set to 'Western (ISO Latin 1)' and not UTF-8. You can change this setting under Terminal->Preferences->Profiles->Advanced->Text encoding. + +6. Profit! + + ``` + $ openhsr-connect sync + ``` + + Sync the specified directories with the script server. + ### Drucker Damit CUPS das E-Mail-Backend nutzen kann muss dieses verlinkt werden. ```bash @@ -75,3 +160,70 @@ if [ $? -eq 0 ]; then lpadmin -x openhsr-connect fi ``` + +##Für Windows (Not officially supported) + +### Sync +1. Download Python 3.x + + Latest is 3.5.2 as of creation of this guide. [Download website](https://www.python.org/downloads/release/python-352/), [Installer](https://www.python.org/ftp/python/3.5.2/python-3.5.2-amd64.exe)) + Install and make sure to install the py launcher as well (this setting should automatically be set in the advanced installation options). + +2. Install git + + [Download link](https://git-scm.com/download/win) + +3. Clone repo + + Open admin command prompt + + ``` + $ git clone https://github.com/openhsr/connect.git + $ cd connect + ``` + + +4. Build & install + + ``` + $ py -3 setup.py install + ``` + + +5. Add Python Scripts folder to $PATH + + For x64 Python this path is ```C:\Program Files\Python35\Scripts``` by default. If you're not sure how to add this to Path, check [this link](http://www.computerhope.com/issues/ch000549.htm) + +6. Set up sync settings + + ``` + $ openhsr-connect edit + ``` + + Enter HSR information, modify config file for your classes (See example [here](https://github.com/openhsr/connect/blob/master/docs/config.example.yaml)) + +7. Profit! + + ``` + $ openhsr-connect sync + ``` + + Sync the specified directories with the script server. + +##Bash on Ubuntu on Windows (Not officially supported) +### Sync +It's probably easier to just use it in Windows if you're on Windows but here's how you'd get it to work on BoUoW: + +Follow steps 1-3 from the Ubuntu/Debian section, then: + +Download & install keyrings.alt + +``` +$ cd +$ curl https://pypi.python.org/packages/27/d0/9207bf58de11735fe2239deaecb9eae1084e2887077a700ac8aa27bd8159/keyrings.alt-1.1.1.tar.gz | tar xz +$ cd keyrings.alt-1.1.1 +$ sudo python3 ./setup.py install +``` + +Continue with step 4 from the Linux-Distributionen section. + diff --git a/openhsr_connect/configuration.py b/openhsr_connect/configuration.py index bbe6fb4..33caeb1 100644 --- a/openhsr_connect/configuration.py +++ b/openhsr_connect/configuration.py @@ -5,6 +5,7 @@ import keyring from .exceptions import PasswordException, ConfigurationException import jsonschema +import errno logger = logging.getLogger('openhsr_connect.config') PATH_CONFIG = '~/.config/openhsr-connect.yaml' @@ -19,6 +20,7 @@ global-exclude: - .DS_Store - Thumbs.db + - desktop.ini conflict-handling: local-changes: ask # ask | keep | overwrite | makeCopy @@ -103,10 +105,27 @@ def create_default_config(config_path): username = input('Dein HSR-Benutzername: ') mail = input('Deine HSR-Email (VORNAME.NACHNAME@hsr.ch): ') config = DEFAULT_CONFIG.format(username=username, mail=mail) - with open(config_path, 'w') as f: + + + with safe_open_w(config_path) as f: f.write(config) +def safe_open_w(path): + """ + Open file path and create parent directories if necessary as open() doesn't create them on Windows + """ + try: + os.makedirs(os.path.dirname(path)) + except OSError as e: + if e.errno == errno.EEXIST and os.path.isdir(os.path.dirname(path)): + pass + else: + raise + + return open(path, 'w') + + def load_config(raise_if_incomplete=False): """ Loads the user configuration and creates the default configuration if it does not yet exist. @@ -117,6 +136,7 @@ def load_config(raise_if_incomplete=False): if not os.path.exists(config_path): if raise_if_incomplete: raise ConfigurationException('Configuration does not yet exist!') + create_default_config(config_path) config = None