You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@steve.apache.org by gs...@apache.org on 2013/06/08 02:08:57 UTC

svn commit: r1490881 - in /steve/trunk/lib: ./ steve.py

Author: gstein
Date: Sat Jun  8 00:08:57 2013
New Revision: 1490881

URL: http://svn.apache.org/r1490881
Log:
Start a common (Python) library for uses across the Steve tooling.

* lib/ : new subdirectory

* lib/steve.py: new file, convert a couple functions from steve.pm

Added:
    steve/trunk/lib/
    steve/trunk/lib/steve.py

Added: steve/trunk/lib/steve.py
URL: http://svn.apache.org/viewvc/steve/trunk/lib/steve.py?rev=1490881&view=auto
==============================================================================
--- steve/trunk/lib/steve.py (added)
+++ steve/trunk/lib/steve.py Sat Jun  8 00:08:57 2013
@@ -0,0 +1,58 @@
+#####
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#####
+#
+# steve.py -- shared code for Apache Steve
+#
+
+import sys
+import os
+
+SCRIPT = os.path.basename(sys.argv[0])
+
+
+def get_input_line(prompt, quittable=False):
+  "Prompt and fetch a line of input."
+
+  if quittable:
+    prompt += ' (q=quit)'
+  prompt += ': '
+  while True:
+    line = raw_input(prompt).strip()
+    if quittable and line == 'q':
+      sys.exit(0)
+    if line:
+      return line
+    # loop until we get an answer
+
+
+def get_group(fname):
+  "Return the group of voters, as a set of email addresses."
+
+  group = set()
+  for line in open(fname).readlines():
+    i = line.find('#')
+    if i >= 0:
+      line = line[:i]
+    line = line.strip()
+    if not line:
+      continue
+    if '@' not in line:
+      print '%s: voter must be an Internet e-mail address.' % (SCRIPT,)
+      sys.exit(1)
+    group.add(line)
+
+  return group



Re: svn commit: r1490881 - in /steve/trunk/lib: ./ steve.py

Posted by Alan Cabrera <li...@toolazydogs.com>.
On Jun 8, 2013, at 9:12 PM, Greg Stein <gs...@gmail.com> wrote:

> That actually works great if SCRIPT is a two-character string. Strings
> are sequences. It will tear apart the string and substitute each
> character. If the string is not 2-chars long, then you get a mismatch
> between format codes and the right-hand value.

Ahh, that's right, strings are sequences.  That's bitten me a few times.


Regards,
Alan


Re: svn commit: r1490881 - in /steve/trunk/lib: ./ steve.py

Posted by Greg Stein <gs...@gmail.com>.
On Sat, Jun 8, 2013 at 8:35 PM, Alan Cabrera <li...@toolazydogs.com> wrote:
> On Jun 8, 2013, at 2:19 PM, Greg Stein <gs...@gmail.com> wrote:
>> On Jun 8, 2013 12:56 PM, "Daniel Shahaf" <da...@apache.org> wrote:
>>> On Sat, Jun 08, 2013 at 12:08:57AM -0000, gstein@apache.org wrote:
>>>> +      print '%s: voter must be an Internet e-mail address.' % (SCRIPT,)
>
> I guess I'm not not the commits list yet.

commits-subscribe@steve.a.o

> Is it really good form to use a single member tuple for this kind of print statement?  I ask this as a Java weenie who is learning the ropes.  It seems like a lot of syntactic noise.

Well... it is kind of six-of-one / half-dozen-another. The % operator
takes a string and a sequence. If the right-hand is *not* a sequence,
then it requires the left-hand format string to have a single
substitution.

So yes, I could have just said "..." % SCRIPT.

But you can sometimes get into edge-case typos. Consider:

"%s: problem with %s" % SCRIPT

That actually works great if SCRIPT is a two-character string. Strings
are sequences. It will tear apart the string and substitute each
character. If the string is not 2-chars long, then you get a mismatch
between format codes and the right-hand value.

By saying (SCRIPT,), I am making it absolutely clear that I am
providing ONE value to the interpolation.

So yeah: some syntactic noise that isn't strictly needed. I think it
is mostly based on mood. Tho in this case, working on a shared
codebase (rather than a personal python script), I think the clarity
of a one-tuple can be helpful.

*shrug*

>>> Any reason not to use Python 3?  Or at least the common subset of py2 and
>> py3?
>>
>> Python 2.7 is preinstalled on my Mac. It is generally more available, and I
>> believe better-supported by 3rd-class extensions/libraries.
>
> print 'Because parentheses have no place in print statements'
> print "other than for %s %s formatting options' % ('super', 'awesome')
>
> +1 for 2.6/2.7
>
> We can use Python 3 if there's ever a feature we need.

Heh. Yeah...

Cheers,
-g

Re: svn commit: r1490881 - in /steve/trunk/lib: ./ steve.py

Posted by Alan Cabrera <li...@toolazydogs.com>.
On Jun 8, 2013, at 2:19 PM, Greg Stein <gs...@gmail.com> wrote:

> On Jun 8, 2013 12:56 PM, "Daniel Shahaf" <da...@apache.org> wrote:
>> 
>> On Sat, Jun 08, 2013 at 12:08:57AM -0000, gstein@apache.org wrote:
>>> +      print '%s: voter must be an Internet e-mail address.' % (SCRIPT,)

I guess I'm not not the commits list yet.

Is it really good form to use a single member tuple for this kind of print statement?  I ask this as a Java weenie who is learning the ropes.  It seems like a lot of syntactic noise.

>> Any reason not to use Python 3?  Or at least the common subset of py2 and
> py3?
> 
> Python 2.7 is preinstalled on my Mac. It is generally more available, and I
> believe better-supported by 3rd-class extensions/libraries.

print 'Because parentheses have no place in print statements'
print "other than for %s %s formatting options' % ('super', 'awesome')

+1 for 2.6/2.7

We can use Python 3 if there's ever a feature we need.


Regards,
Alan


Re: svn commit: r1490881 - in /steve/trunk/lib: ./ steve.py

Posted by Jim Jagielski <ji...@jaguNET.com>.
++1
On Jun 8, 2013, at 5:19 PM, Greg Stein <gs...@gmail.com> wrote:

> On Jun 8, 2013 12:56 PM, "Daniel Shahaf" <da...@apache.org> wrote:
>> 
>> On Sat, Jun 08, 2013 at 12:08:57AM -0000, gstein@apache.org wrote:
>>> +      print '%s: voter must be an Internet e-mail address.' % (SCRIPT,)
>> 
>> Any reason not to use Python 3?  Or at least the common subset of py2 and
> py3?
> 
> Python 2.7 is preinstalled on my Mac. It is generally more available, and I
> believe better-supported by 3rd-class extensions/libraries.
> 
> Cheers,
> -g


Re: svn commit: r1490881 - in /steve/trunk/lib: ./ steve.py

Posted by Greg Stein <gs...@gmail.com>.
On Jun 8, 2013 12:56 PM, "Daniel Shahaf" <da...@apache.org> wrote:
>
> On Sat, Jun 08, 2013 at 12:08:57AM -0000, gstein@apache.org wrote:
> > +      print '%s: voter must be an Internet e-mail address.' % (SCRIPT,)
>
> Any reason not to use Python 3?  Or at least the common subset of py2 and
py3?

Python 2.7 is preinstalled on my Mac. It is generally more available, and I
believe better-supported by 3rd-class extensions/libraries.

Cheers,
-g

Re: svn commit: r1490881 - in /steve/trunk/lib: ./ steve.py

Posted by Daniel Shahaf <da...@apache.org>.
On Sat, Jun 08, 2013 at 12:08:57AM -0000, gstein@apache.org wrote:
> +      print '%s: voter must be an Internet e-mail address.' % (SCRIPT,)

Any reason not to use Python 3?  Or at least the common subset of py2 and py3?