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/20 21:09:42 UTC

svn commit: r1668140 - in /steve/trunk/pytest/www/cgi-bin: lib/voter.py rest_admin.py rest_voter.py

Author: humbedooh
Date: Fri Mar 20 20:09:42 2015
New Revision: 1668140

URL: http://svn.apache.org/r1668140
Log:
- add a voter tool lib (mainly for getting/setting UIDs)
- remove unused karma code

Added:
    steve/trunk/pytest/www/cgi-bin/lib/voter.py
Modified:
    steve/trunk/pytest/www/cgi-bin/rest_admin.py
    steve/trunk/pytest/www/cgi-bin/rest_voter.py

Added: steve/trunk/pytest/www/cgi-bin/lib/voter.py
URL: http://svn.apache.org/viewvc/steve/trunk/pytest/www/cgi-bin/lib/voter.py?rev=1668140&view=auto
==============================================================================
--- steve/trunk/pytest/www/cgi-bin/lib/voter.py (added)
+++ steve/trunk/pytest/www/cgi-bin/lib/voter.py Fri Mar 20 20:09:42 2015
@@ -0,0 +1,40 @@
+import hashlib, json, random
+from __main__ import homedir
+
+def get(election, basedata, uid):
+    elpath = os.path.join(homedir, "issues", election)
+    with open(elpath + "/voters.json", "r") as f:
+        voters = json.loads(f.read())
+        f.close()
+        xhash = hashlib.sha512(basedata['hash'] + uid)
+        for voter in voters:
+            if voters[voter] == xhash:
+                return voter
+    return None
+        
+def add(election, basedata, email):
+    uid = hashlib.sha512(email + basedata['hash'] + time.time() + random.randint(1,99999999))
+    xhash = hashlib.sha512(basedata['hash'] + uid)
+    elpath = os.path.join(homedir, "issues", election)
+    with open(elpath + "/voters.json", "r") as f:
+        voters = json.loads(f.read())
+        f.close()
+    with open(elpath + "/voters.json", "w") as f:
+        f.write(json.dumps(voters))
+        f.close()
+    return uid, xhash
+
+def remove(election, basedata, email):
+    uid = hashlib.sha512(email + basedata['hash'] + time.time() + random.randint(1,99999999))
+    xhash = hashlib.sha512(basedata['hash'] + uid)
+    elpath = os.path.join(homedir, "issues", election)
+    with open(elpath + "/voters.json", "r") as f:
+        voters = json.loads(f.read())
+        f.close()
+    if email in voters:
+        del voters[email]
+    with open(elpath + "/voters.json", "w") as f:
+        f.write(json.dumps(voters))
+        f.close()
+    return uid, xhash
+

Modified: steve/trunk/pytest/www/cgi-bin/rest_admin.py
URL: http://svn.apache.org/viewvc/steve/trunk/pytest/www/cgi-bin/rest_admin.py?rev=1668140&r1=1668139&r2=1668140&view=diff
==============================================================================
--- steve/trunk/pytest/www/cgi-bin/rest_admin.py (original)
+++ steve/trunk/pytest/www/cgi-bin/rest_admin.py Fri Mar 20 20:09:42 2015
@@ -29,8 +29,7 @@ sys.path.append(path)
 sys.path.append(os.path.basename(sys.argv[0]))
 if 'SCRIPT_FILENAME' in os.environ:
     sys.path.insert(0, os.path.basename(os.environ['SCRIPT_FILENAME']))
-    
-from lib import response
+
 
 # Fetch config (hack, hack, hack)
 config = configparser.RawConfigParser()
@@ -43,6 +42,8 @@ form = cgi.FieldStorage();
 
 whoami = os.environ['REMOTE_USER'] if 'REMOTE_USER' in os.environ else None
 
+from lib import response, voter
+
 if not whoami:
     response.respond(403, {'message': 'Could not verify your identity: No auth scheme found'})
 elif not config.has_option('karma', whoami):

Modified: steve/trunk/pytest/www/cgi-bin/rest_voter.py
URL: http://svn.apache.org/viewvc/steve/trunk/pytest/www/cgi-bin/rest_voter.py?rev=1668140&r1=1668139&r2=1668140&view=diff
==============================================================================
--- steve/trunk/pytest/www/cgi-bin/rest_voter.py (original)
+++ steve/trunk/pytest/www/cgi-bin/rest_voter.py Fri Mar 20 20:09:42 2015
@@ -30,9 +30,6 @@ sys.path.append(path)
 sys.path.append(os.path.basename(sys.argv[0]))
 if 'SCRIPT_FILENAME' in os.environ:
     sys.path.insert(0, os.path.basename(os.environ['SCRIPT_FILENAME']))
-    
-from lib import response
-
 
 # Fetch config (hack, hack, hack)
 config = configparser.RawConfigParser()
@@ -43,11 +40,9 @@ homedir = config.get("general", "homedir
 pathinfo = os.environ['PATH_INFO'] if 'PATH_INFO' in os.environ else None
 form = cgi.FieldStorage();
 
+from lib import response, voter
 
 
-# TODO: Authentication goes here
-karma = 5 # assume admin karma for now
-
 # Figure out what to do and where
 if pathinfo:
     l = pathinfo.split("/")



Re: svn commit: r1668140 - in /steve/trunk/pytest/www/cgi-bin: lib/voter.py rest_admin.py rest_voter.py

Posted by ke...@apache.org.
> Agree Python FTW!

+1.

Heck, +1000!

--k

Re: svn commit: r1668140 - in /steve/trunk/pytest/www/cgi-bin: lib/voter.py rest_admin.py rest_voter.py

Posted by ke...@apache.org.
> Agree Python FTW!

+1.

Heck, +1000!

--k

Re: svn commit: r1668140 - in /steve/trunk/pytest/www/cgi-bin: lib/voter.py rest_admin.py rest_voter.py

Posted by "Mattmann, Chris A (3980)" <ch...@jpl.nasa.gov>.
Agree Python FTW!

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Chris Mattmann, Ph.D.
Chief Architect
Instrument Software and Science Data Systems Section (398)
NASA Jet Propulsion Laboratory Pasadena, CA 91109 USA
Office: 168-519, Mailstop: 168-527
Email: chris.a.mattmann@nasa.gov
WWW:  http://sunset.usc.edu/~mattmann/
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adjunct Associate Professor, Computer Science Department
University of Southern California, Los Angeles, CA 90089 USA
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++






-----Original Message-----
From: "Alan D. Cabrera" <li...@toolazydogs.com>
Reply-To: "dev@steve.apache.org" <de...@steve.apache.org>
Date: Sunday, March 22, 2015 at 9:41 PM
To: "dev@steve.apache.org" <de...@steve.apache.org>
Cc: "commits@steve.apache.org" <co...@steve.apache.org>
Subject: Re: svn commit: r1668140 - in /steve/trunk/pytest/www/cgi-bin:
lib/voter.py rest_admin.py rest_voter.py

>
>> On Mar 20, 2015, at 1:09 PM, humbedooh@apache.org wrote:
>> 
>> Added: steve/trunk/pytest/www/cgi-bin/lib/voter.py
>> URL: 
>>http://svn.apache.org/viewvc/steve/trunk/pytest/www/cgi-bin/lib/voter.py?
>>rev=1668140&view=auto
>><http://svn.apache.org/viewvc/steve/trunk/pytest/www/cgi-bin/lib/voter.py
>>?rev=1668140&view=auto>
>> 
>>=========================================================================
>>=====
>> --- steve/trunk/pytest/www/cgi-bin/lib/voter.py (added)
>> +++ steve/trunk/pytest/www/cgi-bin/lib/voter.py Fri Mar 20 20:09:42 2015
>> @@ -0,0 +1,40 @@
>> +import hashlib, json, random
>> +from __main__ import homedir
>
>Importing from __main__ is a brittle practice.  It’s better to either
>explicitly pass it to functions or create a class that will hold the
>context that contains homedir and config.
>
>Aesthetically, camel case identifiers should be reserved for class names.
> Use lower case characters for everything else and separate words with
>underscores “_”.
>
>Finally, never comment out code; that’s what Subversion is for.  Just
>delete it.
>
>Mmmmmmm, all this lovely Python code.  Can’t wait to ditch the Perl
>stuff…  ;)
>
>
>Regards,
>Alan
>


Re: svn commit: r1668140 - in /steve/trunk/pytest/www/cgi-bin: lib/voter.py rest_admin.py rest_voter.py

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
> On Mar 20, 2015, at 1:09 PM, humbedooh@apache.org wrote:
> 
> Added: steve/trunk/pytest/www/cgi-bin/lib/voter.py
> URL: http://svn.apache.org/viewvc/steve/trunk/pytest/www/cgi-bin/lib/voter.py?rev=1668140&view=auto <http://svn.apache.org/viewvc/steve/trunk/pytest/www/cgi-bin/lib/voter.py?rev=1668140&view=auto>
> ==============================================================================
> --- steve/trunk/pytest/www/cgi-bin/lib/voter.py (added)
> +++ steve/trunk/pytest/www/cgi-bin/lib/voter.py Fri Mar 20 20:09:42 2015
> @@ -0,0 +1,40 @@
> +import hashlib, json, random
> +from __main__ import homedir

Importing from __main__ is a brittle practice.  It’s better to either explicitly pass it to functions or create a class that will hold the context that contains homedir and config.

Aesthetically, camel case identifiers should be reserved for class names.  Use lower case characters for everything else and separate words with underscores “_”.

Finally, never comment out code; that’s what Subversion is for.  Just delete it.

Mmmmmmm, all this lovely Python code.  Can’t wait to ditch the Perl stuff…  ;)


Regards,
Alan