From 4d27ce5256505c6c58ca018e15566b1c82cc7171 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= <hugo@hornquist.se>
Date: Sat, 22 Sep 2018 00:22:09 +0200
Subject: [PATCH] Add setup.py. Move machine.py into library.

Moved machine.py into a library, and made main a procedure. setup.py
installs it both as a library, and as a binary. The binary is called
time-machine and is usually placed in /usr/bin/.
---
 setup.py                              | 18 ++++++++++++++++++
 time_machine/__init__.py              |  1 +
 machine.py => time_machine/machine.py |  6 +++++-
 3 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 setup.py
 create mode 100644 time_machine/__init__.py
 rename machine.py => time_machine/machine.py (98%)

diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..d0db3aa
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,18 @@
+#!/usr/bin/env python2
+
+from setuptools import setup
+
+setup(name = "time_machine",
+      version = "0.1",
+      author = "Hugo Hornquist",
+      author_email = "hugo@lysator.liu.se",
+      description = "A program for measuring times.",
+      license = "MIT",
+      url = "https://git.lysator.liu.se/hugo/time-machine",
+      packages = ["time_machine"],
+      entry_points = {
+          "console_scripts": [
+              "time-machine = time_machine.machine:main"
+          ]
+      }
+      )
diff --git a/time_machine/__init__.py b/time_machine/__init__.py
new file mode 100644
index 0000000..23fbec0
--- /dev/null
+++ b/time_machine/__init__.py
@@ -0,0 +1 @@
+name = "time_machine"
diff --git a/machine.py b/time_machine/machine.py
similarity index 98%
rename from machine.py
rename to time_machine/machine.py
index f25fb3c..5d5e5c1 100644
--- a/machine.py
+++ b/time_machine/machine.py
@@ -109,7 +109,8 @@ def wait_btn():
     return g.wait_for_edge(btn_pin, g.RISING, bouncetime=500)
     #g.wait_for_edge(btn_pin, g.RISING)
 
-if __name__ == "__main__":
+def main():
+    global state, pins
     while True:
         if state == States.no_hafv:
             print
@@ -149,3 +150,6 @@ if __name__ == "__main__":
             lcd_info("Avvakta")
             state = States.no_hafv
             time.sleep(1)
+
+if __name__ == "__main__":
+    main()
-- 
GitLab