Re: subprocess svn checkout password issue

2019-03-15 Thread Martin De Kauwe
On Saturday, 16 March 2019 16:50:23 UTC+11, dieter  wrote:
> Martin De Kauwe  writes:
> 
> > I'm trying to write a script that will make a checkout from a svn repo and 
> > build the result for the user. However, when I attempt to interface with 
> > the shell it asks the user for their filename and I don't know how to 
> > capture this with my implementation. 
> >
> > user = "XXX578"
> > root="https://trac.nci.org.au/svn/cable";
> > repo_name = "CMIP6-MOSRS"
> >
> > cmd = "svn checkout %s/branches/Users/%s/%s" % (root, user, repo_name)
> > p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
> >   stdout=subprocess.PIPE, 
> > stderr=subprocess.PIPE)
> > error = subprocess.call(cmd, shell=True)
> > if error is 1:
> > raise("Error downloading repo"
> >
> > I tried adding .wait(timeout=60) to the subprocess.Popen command but that 
> > didn't work.
> >
> > Any advice on whether there is an augmentation to the above, or a better 
> > approach, would be much appreciated. I need to solve this with standard 
> > python libs as I'm trying to make this as simple as possible for the user.
> 
> That is non-trivial.
> 
> Read the "svn" documentation. You might be able to pass in the
> required information by other means, maybe an option, maybe
> an envvar, maybe via a configuration file.
> 
> Otherwise, you must monitor what it written to the subprocess'
> "stdout" and "stderr", recognized the interaction request
> perform the interaction with the user and send the result
> to the subprocess' stdin.

Thanks, I think this solution will work.

import subprocess
import getpass

user = "XXX578"
root="https://trac.nci.org.au/svn/cable";
repo_name = "CMIP6-MOSRS"

pswd = "'" + getpass.getpass('Password:') + "'"
cmd = "svn checkout %s/branches/Users/%s/%s --password %s" %\
 (root, user, repo_name, pswd)
error = subprocess.call(cmd, shell=True)
if error is 1:
raise("Error checking out repo")
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: subprocess svn checkout password issue

2019-03-15 Thread dieter
Martin De Kauwe  writes:

> I'm trying to write a script that will make a checkout from a svn repo and 
> build the result for the user. However, when I attempt to interface with the 
> shell it asks the user for their filename and I don't know how to capture 
> this with my implementation. 
>
> user = "XXX578"
> root="https://trac.nci.org.au/svn/cable";
> repo_name = "CMIP6-MOSRS"
>
> cmd = "svn checkout %s/branches/Users/%s/%s" % (root, user, repo_name)
> p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
>   stdout=subprocess.PIPE, 
> stderr=subprocess.PIPE)
> error = subprocess.call(cmd, shell=True)
> if error is 1:
> raise("Error downloading repo"
>
> I tried adding .wait(timeout=60) to the subprocess.Popen command but that 
> didn't work.
>
> Any advice on whether there is an augmentation to the above, or a better 
> approach, would be much appreciated. I need to solve this with standard 
> python libs as I'm trying to make this as simple as possible for the user.

That is non-trivial.

Read the "svn" documentation. You might be able to pass in the
required information by other means, maybe an option, maybe
an envvar, maybe via a configuration file.

Otherwise, you must monitor what it written to the subprocess'
"stdout" and "stderr", recognized the interaction request
perform the interaction with the user and send the result
to the subprocess' stdin.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Implement C's Switch in Python 3

2019-03-15 Thread jfong
Sayth Renshaw at 2019/2/3 UTC+8 AM9:52:50 wrote:
> Or perhaps use a 3rd party library like 
> https://github.com/mikeckennedy/python-switch

Thank you for this link. It's a good general implementation.

--Jach

-- 
https://mail.python.org/mailman/listinfo/python-list


RE: asyncio Question

2019-03-15 Thread Joseph L. Casale
> -Original Message-
> From: Python-list  bounces+jcasale=activenetwerx@python.org> On Behalf Of Simon
> Connah
> Sent: Thursday, March 14, 2019 3:03 AM
> To: Python 
> Subject: asyncio Question
> 
> Hi,
> 
> Hopefully this isn't a stupid question. For the record I am using Python
> 3.7 on Ubuntu Linux.
> 
> I've decided to use asyncio to write a TCP network server using Streams
> and asyncio.start_server(). I can handle that part of it without many
> problems as the documentation is pretty good. I have one problem though
> that I am not sure how to solve. Each request to the server will be a
> JSON string and one of the components of the JSON string will be the
> latitude and longitude. What I want to do is associate a latitude and
> longitude with the client connection. Every time the latitude and
> longitude changes then the two values will be updated. There will only
> ever be one latitude and longitude for each client connection (since a
> device can only ever be in one place). I'm just not sure what the best
> method to achieve this would be when using asyncio.start_server().

As you expect the client to provide the latitude and longitude, so what
happens when it misbehaves either by accident or intentionally and
all of a sudden you have several connections from the same values?

You'd better rely on your means of differentiating them.
-- 
https://mail.python.org/mailman/listinfo/python-list


subprocess svn checkout password issue

2019-03-15 Thread Martin De Kauwe
Hi,

I'm trying to write a script that will make a checkout from a svn repo and 
build the result for the user. However, when I attempt to interface with the 
shell it asks the user for their filename and I don't know how to capture this 
with my implementation. 

user = "XXX578"
root="https://trac.nci.org.au/svn/cable";
repo_name = "CMIP6-MOSRS"

cmd = "svn checkout %s/branches/Users/%s/%s" % (root, user, repo_name)
p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
  stdout=subprocess.PIPE, 
stderr=subprocess.PIPE)
error = subprocess.call(cmd, shell=True)
if error is 1:
raise("Error downloading repo"

I tried adding .wait(timeout=60) to the subprocess.Popen command but that 
didn't work.

Any advice on whether there is an augmentation to the above, or a better 
approach, would be much appreciated. I need to solve this with standard python 
libs as I'm trying to make this as simple as possible for the user.

The full script is here if that helps:

https://github.com/mdekauwe/CABLE_benchmarking/blob/master/scripts/get_cable.py

Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question regarding the local function object

2019-03-15 Thread Terry Reedy

On 3/15/2019 8:47 AM, Arup Rakshit wrote:

Hi,

I am reading a book where it says that:

Just like module-level function definitions, the definition of a local function 
happens at run time when the def keyword is executed. Interestingly, this means 
that each call to sort_by_last_letter results in a new definition of the 
function last_letter. That is, just like any other name bound in a function 
body, last_letter is bound separately to a new function each time 
sort_by_last_letter is called.

If that above is true, why the below program shows the same object reference 
for last_letter every time I call function sort_by_last_letter.

# file name is sample.py

def sort_by_last_letter(strings):
 def last_letter(s):
 return s[-1]
 print(last_letter)
 return sorted(strings, key=last_letter)

python3 -i sample.py

sort_by_last_letter(['ghi', 'def', 'abc'])

.last_letter at 0x1051e0730>
['abc', 'def', 'ghi']

sort_by_last_letter(['ghi', 'def', 'abc'])

.last_letter at 0x1051e0730>
['abc', 'def', 'ghi']

sort_by_last_letter(['ghi', 'def', 'abckl'])

.last_letter at 0x1051e0730>
['def', 'ghi', 'abckl']


To build on Calvin's explanation ...
intersperse other function definitions between the repeated calls

sort_by_last_letter(['ghi', 'def', 'abc'])
def a(): return 'skjsjlskjlsjljs'
print(a)
sort_by_last_letter(['ghi', 'def', 'abc'])
def b(): return 546465465454
print(b)
sort_by_last_letter(['ghi', 'def', 'abc'])

and memory gets reused a different way.

.last_letter at 0x03A51D40>
  # <== is same memory as .
.last_letter at 0x043C2710>
  # ditto
.last_letter at 0x043C2768>

Creating a new list or string did not have the same effect.  I believe 
that CPython function objects must currently all have the same size or 
at least the same max size and conclude that CPython currently allocates 
them from a block of memory that is some multiple of that size.  These 
are, of course, current internal implementation details, subject to 
change and even variation across hardware and OSes.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: Question regarding the local function object

2019-03-15 Thread Arup Rakshit


Nice explanation. Thank you very much.



Thanks,

Arup Rakshit
a...@zeit.io



> On 15-Mar-2019, at 6:24 PM, Calvin Spealman  wrote:
> 
> This is actually part of a not entirely uncommon misconception that can arise 
> by comparing objects only by their
> repr() outputs (the string representation created when you pass them to 
> print).
> 
> You're comparing the ID or memory address of the objects and determining they 
> must be the same object. In this case,
> it is a kind of illusion. The function is being garbage collected at the end 
> of each call to sort_by_last_letter() and then, on
> the next call, that address is reused. It is just common for Python to take 
> the next available location, and that happens to
> be the same because you're re-running generally the same code, so the same 
> number of objects are created and destroyed
> each time.
> 
> You can see this by making a slight change: try keeping references to ALL the 
> created functions and you'll see they all
> have different IDs so long as none of them get cleaned up. Try this slightly 
> modified version:
> 
> functions = []
> def sort_by_last_letter(strings):
> def last_letter(s):
> return s[-1]
> print(last_letter)
> functions.append(last_letter)
> return sorted(strings, key=last_letter)
> 
> Which produces this output:
> 
> >>> sort_by_last_letter(['ghi', 'def', 'abc'])
> .last_letter at 0x7f276dd571e0>
> ['abc', 'def', 'ghi']
> >>> sort_by_last_letter(['ghi', 'def', 'abc'])
> .last_letter at 0x7f276dd57268>
> ['abc', 'def', 'ghi']
> >>> sort_by_last_letter(['ghi', 'def', 'abc'])
> .last_letter at 0x7f276dd572f0>
> ['abc', 'def', 'ghi']
> 
> On Fri, Mar 15, 2019 at 8:47 AM Arup Rakshit  > wrote:
> Hi,
> 
> I am reading a book where it says that:
> 
> Just like module-level function definitions, the definition of a local 
> function happens at run time when the def keyword is executed. Interestingly, 
> this means that each call to sort_by_last_letter results in a new definition 
> of the function last_letter. That is, just like any other name bound in a 
> function body, last_letter is bound separately to a new function each time 
> sort_by_last_letter is called. 
> 
> If that above is true, why the below program shows the same object reference 
> for last_letter every time I call function sort_by_last_letter.
> 
> # file name is sample.py
> 
> def sort_by_last_letter(strings):
> def last_letter(s):
> return s[-1]
> print(last_letter)
> return sorted(strings, key=last_letter)
> 
> python3 -i sample.py 
> >>> sort_by_last_letter(['ghi', 'def', 'abc'])
> .last_letter at 0x1051e0730>
> ['abc', 'def', 'ghi']
> >>> sort_by_last_letter(['ghi', 'def', 'abc'])
> .last_letter at 0x1051e0730>
> ['abc', 'def', 'ghi']
> >>> sort_by_last_letter(['ghi', 'def', 'abckl'])
> .last_letter at 0x1051e0730>
> ['def', 'ghi', 'abckl']
> >>> 
> 
> 
> Thanks,
> 
> Arup Rakshit
> a...@zeit.io 
> 
> 
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list 
> 
> 
> 
> -- 
> CALVIN SPEALMAN
> SENIOR QUALITY ENGINEER
> cspea...@redhat.com   M: +1.336.210.5107 
>  
> TRIED. TESTED. TRUSTED. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question regarding the local function object

2019-03-15 Thread Calvin Spealman
This is actually part of a not entirely uncommon misconception that can
arise by comparing objects only by their
repr() outputs (the string representation created when you pass them to
print).

You're comparing the ID or memory address of the objects and determining
they must be the same object. In this case,
it is a kind of illusion. The function is being garbage collected at the
end of each call to sort_by_last_letter() and then, on
the next call, that address is reused. It is just common for Python to take
the next available location, and that happens to
be the same because you're re-running generally the same code, so the same
number of objects are created and destroyed
each time.

You can see this by making a slight change: try keeping references to ALL
the created functions and you'll see they all
have different IDs so long as none of them get cleaned up. Try this
slightly modified version:

functions = []
def sort_by_last_letter(strings):
def last_letter(s):
return s[-1]
print(last_letter)
functions.append(last_letter)
return sorted(strings, key=last_letter)

Which produces this output:

>>> sort_by_last_letter(['ghi', 'def', 'abc'])
.last_letter at 0x7f276dd571e0>
['abc', 'def', 'ghi']
>>> sort_by_last_letter(['ghi', 'def', 'abc'])
.last_letter at 0x7f276dd57268>
['abc', 'def', 'ghi']
>>> sort_by_last_letter(['ghi', 'def', 'abc'])
.last_letter at 0x7f276dd572f0>
['abc', 'def', 'ghi']

On Fri, Mar 15, 2019 at 8:47 AM Arup Rakshit  wrote:

> Hi,
>
> I am reading a book where it says that:
>
> Just like module-level function definitions, the definition of a local
> function happens at run time when the def keyword is executed.
> Interestingly, this means that each call to sort_by_last_letter results in
> a new definition of the function last_letter. That is, just like any other
> name bound in a function body, last_letter is bound separately to a new
> function each time sort_by_last_letter is called.
>
> If that above is true, why the below program shows the same object
> reference for last_letter every time I call function sort_by_last_letter.
>
> # file name is sample.py
>
> def sort_by_last_letter(strings):
> def last_letter(s):
> return s[-1]
> print(last_letter)
> return sorted(strings, key=last_letter)
>
> python3 -i sample.py
> >>> sort_by_last_letter(['ghi', 'def', 'abc'])
> .last_letter at 0x1051e0730>
> ['abc', 'def', 'ghi']
> >>> sort_by_last_letter(['ghi', 'def', 'abc'])
> .last_letter at 0x1051e0730>
> ['abc', 'def', 'ghi']
> >>> sort_by_last_letter(['ghi', 'def', 'abckl'])
> .last_letter at 0x1051e0730>
> ['def', 'ghi', 'abckl']
> >>>
>
>
> Thanks,
>
> Arup Rakshit
> a...@zeit.io
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>


-- 

CALVIN SPEALMAN

SENIOR QUALITY ENGINEER

cspea...@redhat.com  M: +1.336.210.5107

TRIED. TESTED. TRUSTED. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Question regarding the local function object

2019-03-15 Thread Arup Rakshit
Hi,

I am reading a book where it says that:

Just like module-level function definitions, the definition of a local function 
happens at run time when the def keyword is executed. Interestingly, this means 
that each call to sort_by_last_letter results in a new definition of the 
function last_letter. That is, just like any other name bound in a function 
body, last_letter is bound separately to a new function each time 
sort_by_last_letter is called. 

If that above is true, why the below program shows the same object reference 
for last_letter every time I call function sort_by_last_letter.

# file name is sample.py

def sort_by_last_letter(strings):
def last_letter(s):
return s[-1]
print(last_letter)
return sorted(strings, key=last_letter)

python3 -i sample.py 
>>> sort_by_last_letter(['ghi', 'def', 'abc'])
.last_letter at 0x1051e0730>
['abc', 'def', 'ghi']
>>> sort_by_last_letter(['ghi', 'def', 'abc'])
.last_letter at 0x1051e0730>
['abc', 'def', 'ghi']
>>> sort_by_last_letter(['ghi', 'def', 'abckl'])
.last_letter at 0x1051e0730>
['def', 'ghi', 'abckl']
>>> 


Thanks,

Arup Rakshit
a...@zeit.io



-- 
https://mail.python.org/mailman/listinfo/python-list