You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@steve.apache.org by hu...@apache.org on 2015/03/23 14:49:49 UTC

svn commit: r1668638 - in /steve/trunk/pysteve/cli: mkelection.py setup.py

Author: humbedooh
Date: Mon Mar 23 13:49:49 2015
New Revision: 1668638

URL: http://svn.apache.org/r1668638
Log:
first stab at creating some cli scripts

Added:
    steve/trunk/pysteve/cli/mkelection.py
    steve/trunk/pysteve/cli/setup.py

Added: steve/trunk/pysteve/cli/mkelection.py
URL: http://svn.apache.org/viewvc/steve/trunk/pysteve/cli/mkelection.py?rev=1668638&view=auto
==============================================================================
--- steve/trunk/pysteve/cli/mkelection.py (added)
+++ steve/trunk/pysteve/cli/mkelection.py Mon Mar 23 13:49:49 2015
@@ -0,0 +1,45 @@
+import os, sys, random, time
+
+path = os.path.abspath(os.getcwd() + "/..")
+sys.path.append(path)
+
+version = 2
+if sys.hexversion < 0x03000000:
+    import ConfigParser as configparser
+else:
+    import configparser
+    version = 3
+    
+config = configparser.RawConfigParser()
+config.read('../steve.cfg')
+
+homedir = config.get("general", "homedir")
+
+from lib import election, voter, constants
+import argparse
+
+parser = argparse.ArgumentParser(description='Command line options.')
+parser.add_argument('--id', dest='id', type=str, nargs=1,
+                   help='Election ID: If defined, attempt to create an election using this as the election ID (OPTIONAL)')
+parser.add_argument('--owner', required=True, dest='owner', nargs=1,
+                   help='Sets the owner of this election, as according to steve.cfg [REQUIRED]')
+parser.add_argument('--title', required=True, dest='title', nargs=1,
+                   help='Sets the title (name) of the election [REQUIRED]')
+parser.add_argument('--monitors', dest='monitors', nargs=1,
+                   help='Comma-separated list of email addresses to use for monitoring (OPTIONAL)')
+parser.add_argument('--public', dest='public', action='store_true',
+                   help='If set, create the election as a public (open) election where anyone can vote (OPTIONAL)')
+
+args = parser.parse_args()
+eid = args.id
+if not eid:
+    eid = ("%08x" % int(time.time() * random.randint(1,999999999999)))[0:8]
+print("Creating new election with ID %s" % eid)
+monitors = []
+if args.monitors:
+    monitors = args.monitors.split(",")
+election.createElection(eid, args.title, args.owner, monitors, 0, 0, args.public)
+
+print("Election created!")
+print("Election ID: %s" % eid)
+print("Election Admin URL: %s/edit_election.html?%s" % (config.get("general", "rooturl"), eid))

Added: steve/trunk/pysteve/cli/setup.py
URL: http://svn.apache.org/viewvc/steve/trunk/pysteve/cli/setup.py?rev=1668638&view=auto
==============================================================================
--- steve/trunk/pysteve/cli/setup.py (added)
+++ steve/trunk/pysteve/cli/setup.py Mon Mar 23 13:49:49 2015
@@ -0,0 +1,36 @@
+import os, sys, random, time
+
+path = os.path.abspath(os.getcwd() + "/..")
+sys.path.append(path)
+
+version = 2
+if sys.hexversion < 0x03000000:
+    import ConfigParser as configparser
+else:
+    import configparser
+    version = 3
+    
+print("Reading steve.cfg")
+config = configparser.RawConfigParser()
+config.read('../steve.cfg')
+
+homedir = config.get("general", "homedir")
+
+from lib import election, voter, constants
+
+print("Attempting to set up STeVe directories...")
+
+if os.path.isdir(homedir):
+    print("Creating election folder")
+    if os.path.exists(homedir + "/issues"):
+        print("Election folder already exists, nothing to do here..")
+        sys.exit(-1)
+    else:
+        try:
+            os.mkdir(homedir + "/issues")
+            print("All done!")
+        except Exception as err:
+            print("Could not create dir: %s" % err)
+else:
+    print("Home dir (%s) does not exist, please create it!" % homedir)
+    sys.exit(-1)
\ No newline at end of file