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/22 10:23:22 UTC

svn commit: r1668346 - /steve/trunk/pytest/www/cgi-bin/rest_admin.py

Author: humbedooh
Date: Sun Mar 22 09:23:22 2015
New Revision: 1668346

URL: http://svn.apache.org/r1668346
Log:
add a 'list' call for listing elections owned by $user

Modified:
    steve/trunk/pytest/www/cgi-bin/rest_admin.py

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=1668346&r1=1668345&r2=1668346&view=diff
==============================================================================
--- steve/trunk/pytest/www/cgi-bin/rest_admin.py (original)
+++ steve/trunk/pytest/www/cgi-bin/rest_admin.py Sun Mar 22 09:23:22 2015
@@ -61,9 +61,27 @@ else:
         action = l[0]
         election = l[1] if len(l) > 1 else None
  
-    
+        # List all existing/previous elections?
+        if action == "list":
+            output = []
+            path = os.path.join(homedir, "issues")
+            elections = [ f for f in listdir(path) if os.path.isdir(os.path.join(path,f))]
+            for election in elections:
+                try:
+                    elpath = os.path.join(homedir, "issues", election)
+                    with open(elpath + "/basedata.json", "r") as f:
+                        basedata = json.loads(f.read())
+                        f.close()
+                        if 'hash' in basedata:
+                            del basedata['hash']
+                        basedata['id'] = election
+                        if karma >= 5 or ('owner' in basedata and basedata['owner'] == whoami):
+                            output.append(basedata)
+                except:
+                    pass
+            response.respond(200, { 'elections': output})
         # Set up new election?
-        if action == "setup":
+        elif action == "setup":
             if karma >= 5: # karma of 5 required to set up an election base
                 if election:
                     if os.path.isdir(os.path.join(homedir, "issues", election)):



Re: svn commit: r1668346 - /steve/trunk/pytest/www/cgi-bin/rest_admin.py

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
> On Mar 22, 2015, at 2:31 AM, Greg Stein <gs...@gmail.com> wrote:
> 
>> +                except:
>> +                    pass
>> 
> 
> Woah!!! ... No way. I don't know what you're trying to do with the above,
> but throwing away all exceptions is never the right answer. .... my brain
> locks up, seeing that. I need to self-censor.

I didn’t have a chance to read the fix but I want also add that in addition to adding a simple pass to an except: clause, an empty except: statement is also dangerous.  It can eat signals that are sent to the process.  Always use the most concise Exception that you can use.


Regards,
Alan


Re: svn commit: r1668346 - /steve/trunk/pytest/www/cgi-bin/rest_admin.py

Posted by Greg Stein <gs...@gmail.com>.
On Sun, Mar 22, 2015 at 4:36 AM, Daniel Gruno <hu...@apache.org> wrote:

>
>
> On 2015-03-22 10:31, Greg Stein wrote:
>
>> On Sun, Mar 22, 2015 at 4:23 AM, <hu...@apache.org> wrote:
>>
>>> ...
>>> +++ steve/trunk/pytest/www/cgi-bin/rest_admin.py Sun Mar 22 09:23:22
>>> 2015
>>>
>>> ...
>>> +                try:
>>> +                    elpath = os.path.join(homedir, "issues", election)
>>> +                    with open(elpath + "/basedata.json", "r") as f:
>>> +                        basedata = json.loads(f.read())
>>> +                        f.close()
>>> +                        if 'hash' in basedata:
>>> +                            del basedata['hash']
>>> +                        basedata['id'] = election
>>> +                        if karma >= 5 or ('owner' in basedata and
>>> basedata['owner'] == whoami):
>>> +                            output.append(basedata)
>>> +                except:
>>> +                    pass
>>>
>>>  Woah!!! ... No way. I don't know what you're trying to do with the
>> above,
>> but throwing away all exceptions is never the right answer. .... my brain
>> locks up, seeing that. I need to self-censor.
>>
>> *shudder*
>>
>> Please do something different.
>>
>
> Sorry if that came out as a 'stable' commit, it's not. I'm working on that
> specific bit right now, but I also had a disturbing phone call right in the
> middle of it, so I got a bit distrait there and just hit the commit button
> too soon. It will be fixed.
>

Thanks. I see the change you committed. Appreciated. ... that kind of code
just makes me twitch. Angry twitch :-P

I would ask that when you commit such stuff, at least put in a comment.
Something like:

  ### yes, the bare except sucks. will fix shortly.

Then I'll know to be quiet, and just wait for another commit.

Cheers,
-g

Re: svn commit: r1668346 - /steve/trunk/pytest/www/cgi-bin/rest_admin.py

Posted by Daniel Gruno <hu...@apache.org>.

On 2015-03-22 10:31, Greg Stein wrote:
> On Sun, Mar 22, 2015 at 4:23 AM, <hu...@apache.org> wrote:
>> ...
>> +++ steve/trunk/pytest/www/cgi-bin/rest_admin.py Sun Mar 22 09:23:22 2015
>>
>> ...
>> +                try:
>> +                    elpath = os.path.join(homedir, "issues", election)
>> +                    with open(elpath + "/basedata.json", "r") as f:
>> +                        basedata = json.loads(f.read())
>> +                        f.close()
>> +                        if 'hash' in basedata:
>> +                            del basedata['hash']
>> +                        basedata['id'] = election
>> +                        if karma >= 5 or ('owner' in basedata and
>> basedata['owner'] == whoami):
>> +                            output.append(basedata)
>> +                except:
>> +                    pass
>>
> Woah!!! ... No way. I don't know what you're trying to do with the above,
> but throwing away all exceptions is never the right answer. .... my brain
> locks up, seeing that. I need to self-censor.
>
> *shudder*
>
> Please do something different.

Sorry if that came out as a 'stable' commit, it's not. I'm working on 
that specific bit right now, but I also had a disturbing phone call 
right in the middle of it, so I got a bit distrait there and just hit 
the commit button too soon. It will be fixed.

Thanks for catching!

With regards,
Daniel.

>> ...


Re: svn commit: r1668346 - /steve/trunk/pytest/www/cgi-bin/rest_admin.py

Posted by Greg Stein <gs...@gmail.com>.
On Sun, Mar 22, 2015 at 4:23 AM, <hu...@apache.org> wrote:
>...

> +++ steve/trunk/pytest/www/cgi-bin/rest_admin.py Sun Mar 22 09:23:22 2015
>
>...

> +                try:
> +                    elpath = os.path.join(homedir, "issues", election)
> +                    with open(elpath + "/basedata.json", "r") as f:
> +                        basedata = json.loads(f.read())
> +                        f.close()
> +                        if 'hash' in basedata:
> +                            del basedata['hash']
> +                        basedata['id'] = election
> +                        if karma >= 5 or ('owner' in basedata and
> basedata['owner'] == whoami):
> +                            output.append(basedata)
> +                except:
> +                    pass
>

Woah!!! ... No way. I don't know what you're trying to do with the above,
but throwing away all exceptions is never the right answer. .... my brain
locks up, seeing that. I need to self-censor.

*shudder*

Please do something different.

>...