[Tutor] intro book for python

2017-09-01 Thread Derek Smith

Hello!

I am new to python coming from a Perl and Unix Admin background.  I reviewed 
the site https://wiki.python.org/moin/IntroductoryBooks and would like to know 
which book(s) you all recommended for a newbie?

Thank you!

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] array input from keyboard

2017-09-15 Thread Derek Smith
I need to accept input from the user then store in an array/list.  This is my 
1st python script.

#!/usr/bin/env python
# Derek Smith
# 09/2017
# accept volumes for TSM for tape mgmt.

import os
import sys

nput1 = ""
nput2 = ""
nput1 = input("\nIs your input 'file' based or 'cli' based? ")

if nput1 == "file" :
nput2 = input("Please provide your input file? ")
nput2 = nput2.lower()
print (nput2)
fh = open(nput2,"r")

for ln in fh:
ln = ln.rstrip()
os.system("/usr/bin/dsmadmc -id=dereksmith -password=x -dataonly=yes 
move drm %s" %ln, "tost=onsiter")
os.system("/usr/bin/dsmadmc -id=dereksmith -password=x -dataonly=yes 
move drm %s" %ln, "wherest=vaultr tost=onsiter")

elif nput1 == "cli" :
vols = []
vols = input("Please enter your volume ids, comma delimited? ")
vols = vols.upper()
for vols in vols :
vols = vols.rstrip()
print("/usr/bin/dsmadmc -id=dereksmith -password=dereksmith 
-dataonly=yes move drm %s" %vols, "tost=onsiter")
elif
print ("Incorrect input, exiting.")
sys.exit(99)


__OUTPUT__

# python tsm_moveVR_tonsiter.py

Is your input 'file' based or 'cli' based? cli
Please enter your volume ids, comma delimited? r20344l5,r20355l5
/usr/bin/dsmadmc -id=dereksmith -password=x -dataonly=yes move drm R 
tost=onsiter
/usr/bin/dsmadmc -id=dereksmith -password=x -dataonly=yes move drm 2 
tost=onsiter
/usr/bin/dsmadmc -id=dereksmith -password=x -dataonly=yes move drm 0 
tost=onsiter
/usr/bin/dsmadmc -id=dereksmith -password=x -dataonly=yes move drm 3 
tost=onsiter
/usr/bin/dsmadmc -id=dereksmith -password=x -dataonly=yes move drm 4 tost=onsite
...
...
...

Its printing each element per line.  I have tried various changes, read online 
help but gave up looking.
I need it to print as below:


/usr/bin/dsmadmc -id=dereksmith -password=x -dataonly=yes move drm R20344L5 
tost=onsiter
/usr/bin/dsmadmc -id=dereksmith -password=x -dataonly=yes move drm R20355L5 
tost=onsiter

Thank you!!
Derek Smith  |  Unix/TSM Administrator  | Racksquared Data Centers
::  dereksm...@racksquared.com  *: 
www.racksquared.com<http://www.racksquared.com/> |  
www.racksquared.jobs<http://www.racksquared.jobs/>

[cid:image003.png@01D2E9AA.1B9CF8F0]

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] pip install of subprocess module

2017-09-18 Thread Derek Smith
Hi All,

Thank for the recent replies.  I want to use the subprocess.run module b/c per 
the docs os.system is antiquated and cannot use  more than 1 arg in 3.6.
Why am I doing wrong below?  Also couldn't I just copy and paste the subprocess 
code from github and create a file, but then how do I tell python this is a new 
module called os.system since this py file requires os.system and os.spawn*
I am on AIX 7.1, python 3.6.2, pip 9.0.1

Thx agn!

# pip install git+https://github.com/python/cpython/blob/3.6/Lib/subprocess.py 
-vvv
Collecting git+https://github.com/python/cpython/blob/3.6/Lib/subprocess.py
  Cloning https://github.com/python/cpython/blob/3.6/Lib/subprocess.py to 
/tmp/pip-bw8rryo9-build
  Running command git clone -q 
https://github.com/python/cpython/blob/3.6/Lib/subprocess.py 
/tmp/pip-bw8rryo9-build
remote: Not Found
fatal: repository 
'https://github.com/python/cpython/blob/3.6/Lib/subprocess.py/' not found
Cleaning up...
Command "git clone -q 
https://github.com/python/cpython/blob/3.6/Lib/subprocess.py 
/tmp/pip-bw8rryo9-build" failed with error code 128 in None
Exception information:
Traceback (most recent call last):
  File "/opt/freeware/lib/python3.6/site-packages/pip/basecommand.py", line 
215, in main
status = self.run(options, args)
  File "/opt/freeware/lib/python3.6/site-packages/pip/commands/install.py", 
line 335, in run
wb.build(autobuilding=True)
  File "/opt/freeware/lib/python3.6/site-packages/pip/wheel.py", line 749, in 
build
self.requirement_set.prepare_files(self.finder)
  File "/opt/freeware/lib/python3.6/site-packages/pip/req/req_set.py", line 
380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
  File "/opt/freeware/lib/python3.6/site-packages/pip/req/req_set.py", line 
620, in _prepare_file
session=self.session, hashes=hashes)
  File "/opt/freeware/lib/python3.6/site-packages/pip/download.py", line 805, 
in unpack_url
unpack_vcs_link(link, location)
  File "/opt/freeware/lib/python3.6/site-packages/pip/download.py", line 479, 
in unpack_vcs_link
vcs_backend.unpack(location)
  File "/opt/freeware/lib/python3.6/site-packages/pip/vcs/__init__.py", line 
286, in unpack
self.obtain(location)
  File "/opt/freeware/lib/python3.6/site-packages/pip/vcs/git.py", line 142, in 
obtain
self.run_command(['clone', '-q', url, dest])
  File "/opt/freeware/lib/python3.6/site-packages/pip/vcs/__init__.py", line 
325, in run_command
spinner)
  File "/opt/freeware/lib/python3.6/site-packages/pip/utils/__init__.py", line 
707, in call_subprocess
% (command_desc, proc.returncode, cwd))
pip.exceptions.InstallationError: Command "git clone -q 
https://github.com/python/cpython/blob/3.6/Lib/subprocess.py 
/tmp/pip-bw8rryo9-build" failed with error code 128 in None



Derek Smith  |  Unix/TSM Administrator  | Racksquared Data Centers
::  dereksm...@racksquared.com  *: 
www.racksquared.com<http://www.racksquared.com/> |  
www.racksquared.jobs<http://www.racksquared.jobs/>

[cid:image003.png@01D2E9AA.1B9CF8F0]

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] subprocess check_output

2017-09-20 Thread Derek Smith
Why does python output this b and newline characters and how can I may it 
return just what I need, the number 8 w/no special characters? See below. I 
tried str(scratch), but no go, still prints that garbage.


#!/bin/env python3

cmdstr= "/usr/bin/dsmadmc"
id  = "-id=dereksmith"
pw   = "-password="
do= "-dataonly=yes"


from subprocess import check_output
scratch = check_output( [ cmdstr, id, pw, do, "select", "count(*)", "from", 
"libvolumes", "where", "status='Scratch'", "and", "library_name='TS3200'" ] )
print (scratch)

__OUTPUT__
# ./ts3200_scratchcount_check.py
email sent successfully
b'   8\n'


Thx!!
Derek Smith  |  Unix/TSM Administrator  | Racksquared Data Centers
::  dereksm...@racksquared.com  *: 
www.racksquared.com<http://www.racksquared.com/> |  
www.racksquared.jobs<http://www.racksquared.jobs/>

[cid:image003.png@01D2E9AA.1B9CF8F0]

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] get javascript output data from ssi file

2017-11-27 Thread Derek Smith
 
  







 
Destination


Element
Volume Serial
  


  


   Element
  Volume Serial
  
  
  

   
  
  
  



 Drive 4 (1)
    
  
  

I/O Station 1
   
 


I/O Station 2
   
 
  

I/O Station 3
   
 


Slot 9 (1)
   
 
  

Slot 20 (1)
   
 


Slot 23 (1)
   
 
  

Slot 30 (1)
   
 


Slot 31 (1)
   
 
  

Slot 32 (1)
   
 


Slot 35 (1)
   
 
  

Slot 36 (1)
   
 


Slot 37 (1)
       
 
  

Slot 40 (1)
   
 


Slot 41 (1)
   
 
  

Slot 44 (1)
   
 
  
  
  
  




Derek Smith  |  Unix/TSM Administrator  | Racksquared Data Centers
':  614-437-4983 * 325 East Spring Street, Columbus, OH 43215
::  dereksm...@racksquared.com  *: 
www.racksquared.com<http://www.racksquared.com/> |  
www.racksquared.jobs<http://www.racksquared.jobs/>

[cid:image003.png@01D2E9AA.1B9CF8F0]

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Fwd: print a for loop system call

2018-01-20 Thread Derek Smith


Sent from my iPhone

Begin forwarded message:

From: Derek Smith 
mailto:dereksm...@racksquared.com>>
Date: January 19, 2018 at 4:01:58 PM EST
To: "tutor-requ...@python.org<mailto:tutor-requ...@python.org>" 
mailto:tutor-requ...@python.org>>
Subject: print a for loop system call

Why does A work but B does not?


#!/usr/bin/env python3

import os
import sys
from subprocess import Popen, PIPE

pipe = Popen('lsdev -c tape', shell=True, stdout=PIPE)

for dev in pipe.stdout :
print ( dev.strip().split()[0].decode() )## A ##
# print ( dev.strip().split().decode()[0] ) ## B ##


And if I try to store in an array using

rmts = [ dev.strip().split()[0].decode() ]

it only stores the last line when there are over 100 lines.

Sample line looks like

rmt144 Available 04-T1-01 LTO Ultrium Tape Drive (FCP)

thank you!

Derek Smith  |  Unix/TSM Administrator  | Racksquared Data Centers
':  614-437-4983 * 325 East Spring Street, Columbus, OH 43215
::  dereksm...@racksquared.com<mailto:dereksm...@racksquared.com>  *: 
www.racksquared.com<http://www.racksquared.com/> |  
www.racksquared.jobs<http://www.racksquared.jobs/>

[cid:image003.png@01D2E9AA.1B9CF8F0]

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor