{ "cells": [ { "cell_type": "markdown", "source": [ "Quick Start\n", "===========\n", "\n", "This is a quick introduction to PyOS, see [the restaurants example](restaurants.ipynb) for a more complete example." ], "metadata": { "collapsed": false } }, { "cell_type": "code", "source": [ "from pyos.pyos import *\n", "from mincepy.testing import Car" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n", "is_executing": false } }, "execution_count": 1, "outputs": [ { "name": "stdout", "text": [ "Welcome to\n", "\n", " ____ ____ \n", " / __ \\/ __ /\n", " ____ __ __/ / / / /_ \n", " / __ \\/ / / / / / /\\__ \\ \n", " / /_/ / /_/ / /_/ /___/ / \n", " / .___/\\__, /\\____//____/ \n", "/_/ /____/ v0.5.1 \n", "\n" ], "output_type": "stream" } ] }, { "cell_type": "markdown", "source": [ "Our ``Car`` class has two members, ``make`` and ``colour``, so let's save a couple in the current directory:" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "source": [ "pwd()" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n", "is_executing": false } }, "execution_count": 2, "outputs": [ { "data": { "text/plain": "Path('/martin/')" }, "metadata": {}, "output_type": "execute_result", "execution_count": 2 } ] }, { "cell_type": "code", "execution_count": 3, "outputs": [ { "data": { "text/plain": "" }, "metadata": {}, "output_type": "execute_result", "execution_count": 3 } ], "source": [ "ls()" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n", "is_executing": false } } }, { "cell_type": "code", "execution_count": 4, "outputs": [ { "data": { "text/plain": "* mincepy|Car 0 Apr 09 21:32 ferrari\n* mincepy|Car 0 Apr 09 21:32 skoda" }, "metadata": {}, "output_type": "execute_result", "execution_count": 4 } ], "source": [ "ferrari = Car('ferrari', 'red')\n", "save(ferrari, 'ferrari')\n", "skoda = Car('skoda', 'green')\n", "save(skoda, 'skoda')\n", "ls -l ()" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n", "is_executing": false } } }, { "cell_type": "markdown", "source": [ "Let's have a look at the cars:" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } } }, { "cell_type": "code", "execution_count": 5, "outputs": [ { "data": { "text/plain": "┌──────────────┬────────────────────────┐\n│ATTRS │┌─┬──────┐ │\n│ ││0│colour│ │\n│ ││1│make │ │\n│ │└─┴──────┘ │\n│IGNORE_MISSING│True │\n│TYPE_ID │5e075d6244572f823ed93274│\n│colour │red │\n│make │ferrari │\n│obj_id │5e8f78308ae3ac1077bfc304│\n└──────────────┴────────────────────────┘\n┌──────────────┬────────────────────────┐\n│ATTRS │┌─┬──────┐ │\n│ ││0│colour│ │\n│ ││1│make │ │\n│ │└─┴──────┘ │\n│IGNORE_MISSING│True │\n│TYPE_ID │5e075d6244572f823ed93274│\n│colour │green │\n│make │skoda │\n│obj_id │5e8f78308ae3ac1077bfc306│\n└──────────────┴────────────────────────┘" }, "metadata": {}, "output_type": "execute_result", "execution_count": 5 } ], "source": [ "ls | cat" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n", "is_executing": false } } }, { "cell_type": "markdown", "source": [ "We see some additional properties of the objects used to store them in the database but our colours and makes are there.\n", "Now, let's move them to their own folder..." ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n", "is_executing": false } } }, { "cell_type": "code", "execution_count": 6, "outputs": [ { "data": { "text/plain": "garage/" }, "metadata": {}, "output_type": "execute_result", "execution_count": 6 } ], "source": [ "mv('ferrari', 'skoda', 'garage/')\n", "ls()" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n", "is_executing": false } } }, { "cell_type": "markdown", "source": [ "...and set some metadata" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } } }, { "cell_type": "code", "execution_count": 7, "outputs": [ { "data": { "text/plain": "┌──────────┬────────────────────────┐\n│reg │VD394 │\n│_directory│/martin/garage/ │\n│name │ferrari │\n│obj_id │5e8f78308ae3ac1077bfc304│\n└──────────┴────────────────────────┘" }, "metadata": {}, "output_type": "execute_result", "execution_count": 7 } ], "source": [ "meta -s ('garage/ferrari', reg='VD394') # '-s' for set\n", "meta -s ('garage/skoda', reg='N317')\n", "meta('garage/ferrari') # This gets our metadata" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n", "is_executing": false } } }, { "cell_type": "markdown", "source": [ "The metadata can be used to search:" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } } }, { "cell_type": "code", "execution_count": 8, "outputs": [ { "data": { "text/plain": "Path('/martin/garage/ferrari')" }, "metadata": {}, "output_type": "execute_result", "execution_count": 8 } ], "source": [ "find(meta=dict(reg='VD394')) | locate" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n", "is_executing": false } } }, { "cell_type": "markdown", "source": [ "Finally, let's clean up." ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } } }, { "cell_type": "code", "execution_count": 9, "outputs": [ { "data": { "text/plain": "" }, "metadata": {}, "output_type": "execute_result", "execution_count": 9 } ], "source": [ " rm -r ('garage/')\n", " ls()" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n", "is_executing": false } } } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" }, "pycharm": { "stem_cell": { "cell_type": "raw", "source": [], "metadata": { "collapsed": false } } } }, "nbformat": 4, "nbformat_minor": 0 }