Sponsored Content
Top Forums Programming Help with Python. Please and thanks. Post 302525819 by o0110o on Saturday 28th of May 2011 08:23:24 PM
Old 05-28-2011
This is how I did it.

Code:
#! /usr/bin/env python

from __future__ import with_statement
import os

with open("../tmp/ordered_list.txt") as f:
    for list_item in f:
        myCommand = "THIS IS WHERE I TYPE MY COMMAND"+list_item
        os.system(myCommand)
        break

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Python

I have written a small practice Python script to determine the prime numbers between 2-10, for practice. Although I have pored over this script numurous times, I have not found the problem. The problem is: Python will not print "is a prime" when a number is a prime. After examining the code... (4 Replies)
Discussion started by: Furtoes00
4 Replies

2. Shell Programming and Scripting

what is python?

I heard that its a new programming language but ill like to get a deeper explaination of it. (1 Reply)
Discussion started by: kprescod4158
1 Replies

3. Programming

Python: bash-shell-like less functionality in the python shell

Hello, Is there some type of functional way to read things in the Python shell interpreter similar to less or more in the bash (and other) command line shells? Example: >>> import subprocess >>> help(subprocess) ... ... I'm hoping so as I hate scrolling and love how less works with... (0 Replies)
Discussion started by: Narnie
0 Replies

4. Ubuntu

Python 3.1 vs 2.6?

i just found python 3.1 in the Ubuntu Software Center today... yes i know, i've probably been under a rock... but my question is, would installing 3.1 cause any conflicts with the 2.6 installation in terms of retro compatibility with python based apps? i don't know if 3.1 is supposed to replace... (0 Replies)
Discussion started by: Sterist
0 Replies

5. SuSE

"ssh suse-server 'python -V' > python-version.out" not redirecting

Okay, so I have had this problem on openSUSE, and Debian systems now and I am hoping for a little help. I think it has something to do with Python but I couldn't find a proper Python area here. I am trying to redirect the output of "ssh suse-server 'python -V'" to a file. It seems that no matter... (3 Replies)
Discussion started by: Druonysus
3 Replies

6. UNIX for Dummies Questions & Answers

Python...

Hi all... Not sure where to put this so I put it here... All comments welcome... 1) Is the Python language now considered a part of the *NIX transient command structure much like Perl, (and awk)? 2) If so which OSes now have it as part of a "default" install - NOT an extra to be... (5 Replies)
Discussion started by: wisecracker
5 Replies

7. Shell Programming and Scripting

**python** unable to read the background color in python

I am working on requirement on spreadsheet in python scripting. I have a spreadsheet containing cell values and with background color. I am able to read the value value but unable to get the background color of that particular cell. Actually my requirement is to read the cell value along... (1 Reply)
Discussion started by: giridhar276
1 Replies

8. Windows & DOS: Issues & Discussions

How to execute python script on remote with python way..?

Hi all, I am trying to run below python code for connecting remote windows machine from unix to run an python file exist on that remote windows machine.. Below is the code I am trying: #!/usr/bin/env python import wmi c = wmi.WMI("xxxxx", user="xxxx", password="xxxxxxx")... (1 Reply)
Discussion started by: onenessboy
1 Replies

9. Programming

Create a C source and compile inside Python 1.4.0 to 3.7.0 in Python for ALL? platforms...

Hi all... As you know I like making code backwards compatible for as many platforms as possible. This Python script was in fact dedicated for the AMIGA A1200 using Pythons 1.4.0, 1.5.2, 1.6.0, 2.0.1, and 2.4.6 as that is all we have for varying levels of upgrades from a HDD and 4MB FastRam... (1 Reply)
Discussion started by: wisecracker
1 Replies
dpm2_python(3)							 Python Reference						    dpm2_python(3)

NAME
dpm - Python interface to the DPM SYNOPSIS
import dpm2 as dpm DESCRIPTION
The dpm module permits you to access the DPM client interface from python programs. The dpm module is a swig wrapping of the standard C interface. For detailed descriptions of each function see the individual man page of each function. FUNCTIONS
dpns_aborttrans ( ) dpns_access ( string path, int amode ) -> bool access dpns_accessr ( string sfn, int amode ) -> bool access dpns_addreplica ( string guid, struct dpns_fileid *file_uniqueid, string server, string sfn, char status, char f_type, string poolname, string fs ) dpns_addreplicax ( string guid, struct dpns_fileid *file_uniqueid, string server, string sfn, char status, char f_type, string poolname, string fs, char r_type, string setname ) dpns_chdir ( string path ) dpns_chmod ( string path, mode_t mode ) dpns_chown ( string path, uid_t new_uid, gid_t new_gid ) dpns_client_setAuthorizationId ( uid_t uid, gid_t gid, string mech, string id ) dpns_client_setVOMS_data ( string voname, stringlist vomsdata ) dpns_closedir ( dpns_DIR dirp ) dpns_creat ( string path, mode_t mode ) dpns_delcomment ( string path ) dpns_delete ( string path ) dpns_delreplica ( string guid, struct dpns_fileid *file_uniqueid, string sfn ) dpns_delreplicasbysfn ( ListOfString sfns, ListOfString guids ) -> ListOfInt results dpns_endsess ( ) dpns_endtrans ( ) dpns_getacl ( string path, ) -> ListOf struct dpns_acl acls dpns_getcomment ( string path ) -> string comment dpns_getcwd ( ) -> string dir dpns_getifcevers ( ) -> string version dpns_getlinks ( string path, string guid ) -> ListOf struct dpns_linkinfo links dpns_getreplica ( string path, string guid, string se ) -> ListOf struct dpns_filereplica replicas dpns_getreplicax ( string path, string guid, string se ) -> ListOf struct dpns_filereplicax replicas dpns_lchown ( string path, uid_t new_uid, gid_t new_gid ) dpns_listreplicax ( string poolname, string server, string fs, int flags, dpns_list * listp ) -> struct dpns_filereplica replica dpns_listrepset ( string setname, int flags, dpns_list *listp ) -> struct dpns_filereplicax replica dpns_lstat ( string path ) -> struct dpns_filestat statbuf dpns_mkdir ( string path, mode_t mode ) dpns_modreplica ( string sfn, string setname, string poolname, string server ) dpns_modreplicax ( string sfn, string setname, string poolname, string server, string fs, char r_type ) dpns_opendir ( string path ) -> dpns_DIR dir dpns_opendirxg ( string server, string path, string guid ) -> dpns_DIR dir dpns_ping ( string server ) -> string info dpns_readdir ( dpns_DIR dirp ) -> struct dirent dirent dpns_readdirc ( dpns_DIR dirp ) -> struct dpns_direncomm dirent dpns_readdirg ( dpns_DIR dirp ) -> struct dpns_direnstatg dirent dpns_readdirx ( dpns_DIR dirp ) -> struct dpns_direnstat dirent dpns_readdirxc ( dpns_DIR dirp ) -> struct dpns_direnstatc dirent dpns_readdirxp ( dpns_DIR dirp, string pattern, string se = None ) -> struct dpns_direnrep dirent dpns_readdirxr ( dpns_DIR dirp, string se = None ) -> struct dpns_direnrep dirent dpns_readlink ( string path ) -> string link dpns_rename ( string oldpath, string newpath ) dpns_rewinddir ( dpns_DIR dirp ) dpns_rmdir ( string path ) dpns_setacl ( string path, ListOf struct dpns_acl acls ) dpns_setatime ( string path, struct dpns_fileid file_uniqueid ) dpns_setcomment ( string path, string comment ) dpns_setfsize ( string path, struct dpns_fileid file_uniqueid, long filesize ) dpns_setfsizec ( string path, struct dpns_fileid file_uniqueid, long filesize, string csumtype, string csumvalue ) dpns_setptime ( string sfn, long ptime ) dpns_setratime ( string sfn ) dpns_setrltime ( string sfn, long ltime ) dpns_setrstatus ( string sfn, char status ) dpns_setrtype ( string sfn, char type ) dpns_startsess ( string server, string comment ) dpns_starttrans ( string server, string comment ) dpns_stat ( string path ) -> struct dpns_filestat statbuf dpns_statg ( string path, string guid ) -> struct dpns_filestatg statbuf dpns_statr ( string sfn) ) -> struct dpns_filestatg statbuf dpns_symlink ( string target, string linkname ) dpns_umask ( mode_t cmask ) -> mode_t oldmask dpns_undelete ( string path ) dpns_unlink ( string path ) dpns_utime ( string path, struct utimbuf times ) dpns_entergrpmap ( gid_t gid, string groupname ) dpns_enterusrmap ( uid_t uid, string username ) dpns_getgrpbygid ( gid_t gid ) -> string group dpns_getgrpbygids ( ListOfgid_t gids ) -> ListOfString groups dpns_getgrpbynam ( string groupname ) -> gid_t gid dpns_getgrpmap ( ) -> ListOf struct dpns_groupinfo infos dpns_getusrbynam ( string username ) -> uid_t uid dpns_getusrbyuid ( uid_t uid ) -> string user dpns_getusrmap ( ) -> ListOf struct dpns_userinfo userinfo dpns_modifygrpmap ( gid_t gid, string newname ) dpns_modifyusrmap ( uid_t uid, string newname ) dpns_rmgrpmap ( gid_t gid, string groupname ) dpns_rmusrmap ( uid_t uid, string username ) dpm_getpoolfs ( string poolname ) -> ListOf struct dpm_fs dpm_fs dpm_getpools ( ) -> ListOf struct dpm_pool dpm_pools dpm_getprotocols ( ) -> ListOfString protocols dpm_getspacemd ( ListOfString s_tokens ) -> ListOf struct dpm_space_metadata spacemd dpm_getspacetoken ( string u_token ) -> ListOfString s_tokens dpm_addfs ( string poolname, string server, string fs, int status ) dpm_addpool ( struct dpm_pool dpm_pool ) dpm_delreplica ( string pfn ) dpm_modifyfs ( string server, string fs, int status ) dpm_modifypool ( struct dpm_pool dpm_pool ) dpm_ping ( string host ) -> string info dpm_releasespace ( string s_token, int force ) dpm_reservespace ( char s_type, string u_token, char ret_policy, char ac_latency, long req_t_space, long req_g_space, long req_lifetime, ListOfInt gids, string poolname ) -> char actual_s_type, long actual_t_space, long actual_g_space, long actual_lifetime, string s_token dpm_rmfs ( string server, string fs ) dpm_rmpool ( string poolname ) dpm_updatespace ( string s_token, long req_t_space, long req_g_space, long req_lifetime, ListOfInt gids ) -> long actual_t_space, long actual_g_space, long actual_lifetime STRUCTURES
Sometimes you need to specify a structure as an input argument (eg. struct dpns_acl, struct dpns_list, struct dpm_pool, etc.). For that purpose, the module includes structure constructors, named exactly as the structure. Thus, to create struct dpns_acl, struct dpns_list or struct dpmm_pool, you have to do the following: dpnsacl = dpm.dpns_acl() dpnslist = dpm.dpns_list() dpmpool = dpm.dpm_pool() If you want to see how to use it in a real case, please have a look at examples. ERRORS
As you can see, no error code is returned. When an error occurs, an exception is raised with a description of the error. EXAMPLE
#!/usr/bin/python """ # Using the dpns_readdirxr method """ import sys import traceback import dpm2 as dpm name = "/dpm/cern.ch/home/dteam/"; try: dir = dpm.dpns_opendir(name) while 1: entry = dpm.dpns_readdirxr(dir) if entry == None: break print entry.d_name for i in range(entry.nbreplicas): print " ==> %s" % entry.rep[i].sfn dpm.dpns_closedir(dir) except TypeError, x: print " ==> None" except Exception: traceback.print_exc() sys.exit(1) EXAMPLE
#!/usr/bin/python import sys import traceback import dpm2 as dpm """ # Using the dpns_getreplica method """ file = "/dpm/cern.ch/home/dteam/file.test" try: list = dpm.dpns_getreplica(file, "", "") except Exception: traceback.print_exc() sys.exit(1) for i in list: print i.host print i.sfn EXAMPLE
#!/usr/bin/python import sys import traceback import dpm2 as dpm """ # Using the dpns_getacl and dpns_setacl methods to add a user ACL """ file = "/dpm/cern.ch/home/dteam/file.test" try: acls_list = dpm.dpns_getacl(file) except Exception: traceback.print_exc() sys.exit(1) for i in acls_list: print i.a_type print i.a_id print i.a_perm # When adding a first ACL for a given user, you also need to add the mask # When adding the second user ACL, it is not necessary anymore acl_user = dpm.dpns_acl() acl_mask = dpm.dpns_acl() acl_user.a_type = lfc.CNS_ACL_USER acl_user.a_id = 18701 # user id acl_user.a_perm = 5 acl_mask.a_type = lfc.CNS_ACL_MASK acl_mask.a_id = 0 # no user id specified acl_mask.a_perm = 5 acls_list.append(acl_user) acls_list.append(acl_mask) try: dpm.dpns_setacl(file, acls_list) except Exception: traceback.print_exc() sys.exit(1) EXAMPLE
#!/usr/bin/python import sys import traceback import dpm2 as dpm """ # Using the dpns_getacl and dpns_setacl methods to remove a user ACL """ file = "/dpm/cern.ch/home/dteam/file.test" try: acls_list = dpm.dpns_getacl(file) except Exception: traceback.print_exc() sys.exit(1) for i in acls_list: print i.a_type print i.a_id print i.a_perm del acls_list[1] # delete a given user ACL from the list of ACLs try: dpm.dpns_setacl(file, acls_list) except Exception: traceback.print_exc() sys.exit(1) EXAMPLE
#!/usr/bin/python import sys import traceback import dpm2 as dpm """ # Using the dpns_getusrmap method """ try: list = dpm.dpns_getusrmap() except Exception: traceback.print_exc() sys.exit(1) for i in list: print i.userid + " " + i.username EXAMPLE
#!/usr/bin/python import sys import traceback import dpm2 as dpm """ # Using the dpns_getgrpmap method """ try: list = dpm.dpns_getgrpmap() except Exception: traceback.print_exc() sys.exit(1) for i in list: print i.gid + " " + i.groupname EXAMPLE
#!/usr/bin/python import sys import traceback import dpm2 as dpm """ # Using the dpm_addfs method """ try: dpm.dpm_addfs("mypool", "mydiskserver.domain.com", "/mountpoint", dpm.FS_READONLY) except Exception: traceback.print_exc() sys.exit(1) EXAMPLE
#!/usr/bin/python import sys import traceback import dpm2 as dpm """ # Using the dpm_modifyfs method """ try: dpm.dpm_modifyfs("mydiskserver.domain.com", "/mountpoint", dpm.FS_READONLY) except Exception: traceback.print_exc() sys.exit(1) EXAMPLE
#!/usr/bin/python import sys import traceback import dpm2 as dpm """ # Using the dpm_rmfs method """ try: dpm.dpm_rmfs("mypool", "mydiskserver.domain.com", "/mountpoint") except Exception: traceback.print_exc() sys.exit(1) EXAMPLE
#!/usr/bin/python import sys import traceback import dpm2 as dpm """ # Using the dpm_addpool method """ dpmpool = dpm.dpm_pool() dpmpool.poolname = "mypool" dpmpool.defsize = 209715200 dpmpool.def_lifetime = 604800 dpmpool.defpintime = 604800 dpmpool.max_lifetime = 604800 dpmpool.max_pintime = 604800 dpmpool.nbgids = 1 dpmpool.gids = [0] dpmpool.ret_policy = 'R' dpmpool.s_type = 'D' try: dpm.dpm_addpool(dpmpool) except Exception: traceback.print_exc() sys.exit(1) EXAMPLE
#!/usr/bin/python import sys import traceback import dpm2 as dpm """ # Using the dpm_modifypool method """ dpmpool = dpm.dpm_pool() dpmpool.poolname = "mypool" dpmpool.defsize = 209715200 dpmpool.def_lifetime = 604800 dpmpool.defpintime = 604800 dpmpool.max_lifetime = 604800 dpmpool.max_pintime = 604800 dpmpool.nbgids = 1 dpmpool.gids = [0] dpmpool.ret_policy = 'R' dpmpool.s_type = 'D' try: dpm.dpm_modifypool(dpmpool) except Exception: traceback.print_exc() sys.exit(1) EXAMPLE
#!/usr/bin/python import sys import traceback import dpm2 as dpm """ # Using the dpm_rmpool method """ try: dpm.dpm_rmpool("mypool") except Exception: traceback.print_exc() sys.exit(1) EXAMPLE
#!/usr/bin/python import sys import traceback import dpm2 as dpm """ # Using the dpm_getpoolfs method """ try: list = dpm.dpm_getpoolfs("mypool") except Exception: traceback.print_exc() sys.exit(1) print len(list) for i in list: print "POOL " + i.poolname + " SERVER " + i.server + " FS " + i.fs + " CAPACITY " + i.capacity + " FREE " + i.free EXAMPLE
#!/usr/bin/python import sys import traceback import dpm2 as dpm """ # Using the dpm_getpools method """ try: list = dpm.dpm_getpools() except Exception: traceback.print_exc() sys.exit(1) print len(list) for i in list: print "POOL " + i.poolname + " CAPACITY " + i.capacity + " FREE " + i.free EXAMPLE
#!/usr/bin/python import sys import traceback import dpm2 as dpm """ # Using the dpm_getprotocols method """ try: list = dpm.dpm_getprotocols() except Exception: traceback.print_exc() sys.exit(1) print len(list) for i in list: print i EXAMPLE
#!/usr/bin/python import sys import traceback import dpm2 as dpm """ # Using the dpm_getspacemd method """ try: list = dpm.dpm_getspacemd(["myspacetoken"]) except Exception: traceback.print_exc() sys.exit(1) print len(list) for i in list: print "TYPE " + i.s_type + " SPACETOKEN " i.s_token + " USERTOKEN " + i.u_token + " TOTAL " + i.t_space + " GUARANTUEED " + i.g_space + " UNUSED " + i.u_space + " POOL " + i.poolname EXAMPLE
#!/usr/bin/python import sys import traceback import dpm2 as dpm """ # Using the dpm_getspacetoken method """ try: list = dpm.dpm_getspacetoken("myspacetokendesc") except Exception: traceback.print_exc() sys.exit(1) print len(list) for i in list: print i EXAMPLE
#!/usr/bin/python import sys import traceback import dpm2 as dpm """ # Using the dpm_reservespace method """ try: actual_s_type,actual_t_space,actual_g_space,actual_lifetime,s_token = dpm.dpm_reservespace('D', "myspacetokendesc", 'R', 'O', 209715200, 209715200, 2592000, 0, "mypoolname") except Exception: traceback.print_exc() sys.exit(1) print "TYPE " + actual_s_type + " TOTAL " + actual_t_space + " GUARANTEED " + actual_g_space + " LIFETIME " + actual_lifetime + " TOKEN " + s_token EXAMPLE
#!/usr/bin/python import sys import traceback import dpm2 as dpm """ # Using the dpm_updatespace method """ try: actual_t_space,actual_g_space,actual_lifetime = dpm.dpm_updatespace("myspacetoken", 209715200, 209715200, 2592000) except Exception: traceback.print_exc() sys.exit(1) print " TOTAL " + actual_t_space + " GUARANTEED " + actual_g_space + " LIFETIME " + actual_lifetime EXAMPLE
#!/usr/bin/python import sys import traceback import dpm2 as dpm """ # Using the dpm_releasespace method """ try: dpm.dpm_releasespace("myspacetoken", 0) except Exception: traceback.print_exc() sys.exit(1) EXAMPLE
#!/usr/bin/python import sys import traceback import dpm2 as dpm """ # Using the dpm_ping method """ try: info = dpm.dpm_ping("mydpmserver.domain.com") except Exception: traceback.print_exc() sys.exit(1) print info SEE ALSO
DPM C interface man pages DPM
$Date: 2010-12-14 08:31:05 +0100 (Tue, 14 Dec 2010) $ dpm2_python(3)
All times are GMT -4. The time now is 01:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy