File: lfc2_python.man

package info (click to toggle)
lfc-postgres 1.7.4.7-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 13,676 kB
  • ctags: 10,779
  • sloc: ansic: 146,136; sh: 13,176; perl: 11,142; python: 5,529; cpp: 5,113; sql: 1,790; makefile: 861; fortran: 113
file content (751 lines) | stat: -rw-r--r-- 14,580 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
.\" @(#)$RCSfile: lfc2_python.man,v $ $Revision: 3535 $ $Date: 2010-04-23 09:16:40 +0200 (Fri, 23 Apr 2010) $ CERN IT-DM/SGT Remi Mollon
.\" Copyright (C) 2004-2007 by CERN/IT/DM/SGT
.\" All rights reserved
.\"
.TH lfc2_python 3 "$Date: 2010-04-23 09:16:40 +0200 (Fri, 23 Apr 2010) $" LFC "Python Reference"
.SH NAME
lfc2 \- New python interface to the LFC client API
.br
lfc2thr \- Thread enabled version of Python interface to the LFC
.SH SYNOPSIS
.B import lfc2 as lfc
.br

.br
.B import lfc2thr as lfc
.br
.B lfc.init()

.SH DESCRIPTION
The lfc module permits you to access the LFC client interface from python
programs. The lfc module is a swig wrapping of the standard C interface.
For detailed descriptions of each function see the individual man page of
each function.

The lfcthr module is a version of the lfc module supporting multi-threaded 
Python clients. Its usage is similar to the usage of the lfc module except
the obligatory initialisation call lfcthr.init() in the main program before 
threads are started.
 
.SH FUNCTIONS
.B  lfc_aborttrans ( )

.BI "lfc_access ( string " path ,
.BI "int " amode
.BI  ") -> bool " access

.BI "lfc_accessr ( string " sfn ,
.BI "int " amode
.BI ") -> bool " access

.BI "lfc_addreplica ( string " guid ,
.BI "struct lfc_fileid *" file_uniqueid ,
.BI "string " server ,
.BI "string " sfn ,
.BI "char " status ,
.BI "char " f_type ,
.BI "string " poolname ,
.BI "string " fs
.B  )

.BI "lfc_addreplicax ( string " guid ,
.BI "struct lfc_fileid *" file_uniqueid ,
.BI "string " server ,
.BI "string " sfn ,
.BI "char " status ,
.BI "char " f_type ,
.BI "string " poolname ,
.BI "string " fs ,
.BI "char " r_type ,
.BI "string " setname
.B  )

.BI "lfc_chdir ( string " path
.B  )

.BI "lfc_chmod ( string " path ,
.BI "mode_t " mode
.B  )

.BI "lfc_chown ( string "path ,
.BI "uid_t " new_uid ,
.BI "gid_t " new_gid
.B  )

.BI "lfc_client_setAuthorizationId ( uid_t " uid ,
.BI "gid_t " gid ,
.BI "string " mech ,
.BI "string " id
.B  )

.BI "lfc_client_setVOMS_data ( string " voname ,
.BI "stringlist " vomsdata
.B  )

.BI "lfc_closedir ( lfc_DIR " dirp
.B  )

.BI "lfc_creatg ( string " path ,
.BI "string " guid ,
.BI "mode_t " mode
.B  )

.BI "lfc_delcomment ( string " path
.B  )

.BI "lfc_delete ( string " path
.B  )

.BI "lfc_delfilesbyguid ( ListOfString " guids ,
.BI "int " force
.BI ") -> ListOfInt " result

.BI "lfc_delfilesbyname ( ListOfString " names ,
.BI int force
.BI ") -> ListOfInt " results

.BI "lfc_delfilesbypattern ( string " path ,
.BI "string " pattern ,
.BI "int " force
.BI ") -> ListOf struct lfc_filestatus " results

.BI "lfc_delreplica ( string " guid ,
.BI "struct lfc_fileid *" file_uniqueid ,
.BI "string " sfn
.B  )

.BI "lfc_delreplicas ( ListOfString " sfns ,
.BI "string " se
.BI ") -> ListOfInt " results

.BI "lfc_delreplicasbysfn ( ListOfString " sfns ,
.BI "ListOfString " guids
.BI ") -> ListOfInt " results

.B  lfc_endsess ( )

.B  lfc_endtrans ( )

.BI "lfc_getacl ( string " path ,
.BI ") -> ListOf struct lfc_acl " acls

.BI "lfc_getcomment ( string " path
.BI ") -> string " comment

.BI "lfc_getcwd ( ) -> string " dir

.BI "lfc_getifcevers ( ) -> string " version

.BI "lfc_getlinks ( string " path ,
.BI "string "guid
.BI ") -> ListOf struct lfc_linkinfo " links

.BI "lfc_getreplica ( string " path ,
.BI "string " guid ,
.BI "string " se
.BI ") -> ListOf struct lfc_filereplica " replicas

.BI "lfc_getreplicas ( ListOfString " guids ,
.BI "string " se
.BI ") -> ListOf struct lfc_filereplicas " replicas

.BI "lfc_getreplicasl ( ListOfString " paths ,
.BI "string " se
.BI ") -> ListOf struct lfc_filereplicas " replicas

.BI "lfc_getreplicass ( ListOfString " paths ,
.BI ") -> ListOf struct lfc_filereplicas " replicas

.BI "lfc_getreplicax ( string " path ,
.BI "string " guid ,
.BI "string " se
.BI ") -> ListOf struct lfc_filereplicax " replicas

.BI "lfc_lchown ( string " path ,
.BI "uid_t " new_uid ,
.BI "gid_t "new_gid
.B  )

.BI "lfc_listlinks ( string " path ,
.BI "string " guid ,
.BI "int " flags ,
.BI "lfc_list *" listp
.BI ") -> struct lfc_linkinfo " link

.BI "lfc_listreplica ( string " path ,
.BI "string " guid ,
.BI "int " flags ,
.BI "lfc_list *" listp
.BI ") -> struct lfc_filereplica " replica

.BI "lfc_listreplicax ( string " poolname ,
.BI "string " server ,
.BI "string " fs ,
.BI "int " flags ,
.BI "lfc_list * listp
.BI ") -> struct lfc_filereplica " replica

.BI "lfc_listrepset ( string " setname ,
.BI "int " flags ,
.BI "lfc_list *" listp
.BI ") -> struct lfc_filereplicax " replica

.BI "lfc_lstat ( string " path
.BI ") -> struct lfc_filestat " statbuf

.BI "lfc_mkdir ( string " path ,
.BI "mode_t " mode
.B  )

.BI "lfc_mkdirg ( string " path ,
.BI "string " guid ,
.BI "mode_t " mode
.B  )

.BI "lfc_modreplica ( string " sfn ,
.BI "string " setname ,
.BI "string " poolname ,
.BI "string " server
.B  )

.BI "lfc_modreplicax ( string " sfn ,
.BI "string " setname ,
.BI "string " poolname ,
.BI "string " server ,
.BI "string " fs ,
.BI "char " r_type
.B  )

.BI "lfc_opendir ( string " path
.BI ") -> lfc_DIR " dir

.BI "lfc_opendirg ( string " path ,
.BI "string " guid
.BI ") -> lfc_DIR " dir

.BI "lfc_opendirxg ( string " server ,
.BI "string " path ,
.BI "string " guid
.BI ") -> lfc_DIR " dir

.BI "lfc_ping ( string " server
.BI ") -> string " info

.BI "lfc_readdir ( lfc_DIR " dirp
.BI ") -> struct dirent " dirent

.BI "lfc_readdirc ( lfc_DIR " dirp
.BI ") -> struct lfc_direncomm " dirent

.BI "lfc_readdirg ( lfc_DIR " dirp
.BI ") -> struct lfc_direnstatg " dirent

.BI "lfc_readdirx ( lfc_DIR " dirp
.BI ") -> struct lfc_direnstat " dirent

.BI "lfc_readdirxc ( lfc_DIR " dirp
.BI ") -> struct lfc_direnstatc " dirent

.BI "lfc_readdirxp ( lfc_DIR " dirp ,
.BI "string " pattern ,
.BI "string " se
.BI "= None ) -> struct lfc_direnrep " dirent

.BI "lfc_readdirxr ( lfc_DIR " dirp ,
.BI "string " se
.BI "= None ) -> struct lfc_direnrep " dirent

.BI "lfc_readlink ( string " path
.BI ") -> string " link

.BI "lfc_registerfiles ( ListOf struct lfc_filereg " files
.BI ") -> ListOfInt " results

.BI "lfc_rename ( string " oldpath ,
.BI "string " newpath
.B  )

.BI "lfc_rewinddir ( lfc_DIR " dirp
.B  )

.BI "lfc_rmdir ( string " path
.B  )

.BI "lfc_setacl ( string " path ,
.BI "ListOf struct lfc_acl " acls
.B  )

.BI "lfc_setatime ( string " path ,
.BI "struct lfc_fileid " file_uniqueid
.B  )

.BI "lfc_setcomment ( string " path ,
.BI "string " comment
.B  )

.BI "lfc_setfsize ( string " path ,
.BI "struct lfc_fileid " file_uniqueid ,
.BI "long " filesize
.B  )

.BI "lfc_setfsizec ( string " path ,
.BI "struct lfc_fileid " file_uniqueid ,
.BI "long " filesize ,
.BI "string " csumtype ,
.BI "string " csumvalue
.B  )

.BI "lfc_setfsizeg ( string " guid ,
.BI "long " filesize ,
.BI "string " csumtype ,
.BI "string " csumvalue
.B  )

.BI "lfc_setptime ( string " sfn ,
.BI "long " ptime
.B  )

.BI "lfc_setratime ( string " sfn
.B  )

.BI "lfc_setrltime ( string " sfn ,
.BI "long " ltime
.B  )

.BI "lfc_setrstatus ( string " sfn ,
.BI "char " status
.B  )

.BI "lfc_setrtype ( string " sfn ,
.BI "char " type
.B  )

.BI "lfc_startsess ( string " server ,
.BI "string " comment
.BI )

.BI "lfc_starttrans ( string " server ,
.BI "string " comment
.BI )

.BI "lfc_stat ( string " path
.BI ") -> struct lfc_filestat " statbuf

.BI "lfc_statg ( string " path ,
.BI "string " guid
.BI ") -> struct lfc_filestatg " statbuf

.BI "lfc_statr ( string " sfn)
.BI ") -> struct lfc_filestatg " statbuf

.BI "lfc_symlink ( string " target ,
.BI "string " linkname
.B  )

.BI "lfc_umask ( mode_t " cmask
.BI ") -> mode_t " oldmask

.BI "lfc_undelete ( string " path
.B  )

.BI "lfc_unlink ( string " path
.B  )

.BI "lfc_utime ( string " path ,
.BI "struct utimbuf " times
.B  )

.BI "lfc_entergrpmap ( gid_t " gid ,
.BI "string " groupname
.B  )

.BI "lfc_enterusrmap ( uid_t " uid ,
.BI "string " username
.B  )

.BI "lfc_getgrpbygid ( gid_t " gid
.BI ") -> string " group

.BI "lfc_getgrpbygids ( ListOfgid_t " gids
.BI ") -> ListOfString " groups

.BI "lfc_getgrpbynam ( string " groupname
.BI ") -> gid_t " gid

.BI "lfc_getgrpmap ( ) -> ListOf struct lfc_groupinfo " infos

.BI "lfc_getidmap ( string " username ,
.BI "ListOfString " vo_roles 
.BI ") -> uid_t " uid ,
.BI " ListOf gid_t " gids

.BI "lfc_getusrbynam ( string " username
.BI ") -> uid_t " uid

.BI "lfc_getusrbyuid ( uid_t " uid
.BI ") -> string " user

.BI "lfc_getusrmap ( ) -> ListOf struct lfc_userinfo " userinfo

.BI "lfc_modifygrpmap ( gid_t " gid ,
.BI "string " newname
.B  )

.BI "lfc_modifyusrmap ( uid_t " uid ,
.BI "string " newname
.B  )

.BI "lfc_rmgrpmap ( gid_t " gid ,
.BI "string " groupname
.B  )

.BI "lfc_rmusrmap ( uid_t " uid ,
.BI "string " username
.B  )

.SH STRUCTURES
Sometimes you need to specify a structure as an input argument (eg.
.IR "struct lfc_acl" ,
.IR "struct lfc_list" ", etc.)."
For that purpose, the module includes structure constructors, named exactly as the structure.

Thus, to create
.IR "struct lfc_acl " or
.IR "struct lfc_list" ,
you have to do the following:

.nf
    lfcacl = lfc.lfc_acl()
    lfclist = lfc.lfc_list()
.fi

If you want to see how to use it in a real case, please have a look at examples.

.SH ERRORS
As you can see, no error code is returned. When an error occurs, an exception is raised
with a description of the error.

.SH EXAMPLE
.nf
#!/usr/bin/python

import sys
import traceback
import lfc2 as lfc

"""
# stat an existing entry in the LFC and print the GUID
"""

name = "/grid/dteam/my.test"

try:
   stat = lfc.lfc_statg(name,"")
except Exception:
   traceback.print_exc()
   sys.exit(1)

guid = stat.guid
print "The GUID for " + name + " is " + guid

.SH EXAMPLE
.nf
#!/usr/bin/python

import sys
import traceback
import lfc2 as lfc

"""
# list the replicas of a given entry, starting from the GUID
"""

guid = "6a3164e0-a4d7-4abe-9f76-e3b8882735d1"

listp = lfc.lfc_list()
flag = lfc.CNS_LIST_BEGIN

print "Listing replicas for GUID " + guid

num_replicas=0

try:
   while(1):
      res = lfc.lfc_listreplica("",guid,flag,listp)
      flag = lfc.CNS_LIST_CONTINUE

      if res == None:
         break
      else:
         rep_name = res.sfn
         print "Replica: " + rep_name
         num_replicas = num_replicas + 1

   lfc.lfc_listreplica("",guid,lfc.CNS_LIST_END,listp)
   print "Found " + str(num_replicas) + " replica(s)"
except Exception:
   traceback.print_exc()
   sys.exit(1)

.SH EXAMPLE
.nf
#!/usr/bin/python

import sys
import traceback
import lfc2 as lfc

"""
# setting and retrieving a comment on a file
"""

file = "/grid/dteam/my.test"
comment = "MyComment"

try:
   lfc.lfc_setcomment(file,comment)

   comment = lfc.lfc_getcomment(file)
   print "Read back comment " + comment
except Exception:
   traceback.print_exc()
   sys.exit(1)

.SH EXAMPLE
.nf
#!/usr/bin/python

"""
# Using the lfc_readdirxr method
"""

import sys
import traceback
import lfc2 as lfc

name = "/grid/dteam/my.test"

try:
   dir = lfc.lfc_opendir(name)

   while 1:
      entry = lfc.lfc_readdirxr(dir)
      if entry == None:
         break
      print entry.d_name
      for i in range(entry.nbreplicas):
         print " ==> %s" % entry.rep[i].sfn

   lfc.lfc_closedir(dir)
except TypeError, x:
   print " ==> None"
except Exception:
   traceback.print_exc()
   sys.exit(1)

.SH EXAMPLE
.nf
#!/usr/bin/python

import sys
import traceback
import lfc2 as lfc

"""
# Using the lfc_getreplica method
"""

file = "/grid/dteam/my.test"

try:
   list = lfc.lfc_getreplica(file, "", "")
except Exception:
   traceback.print_exc()
   sys.exit(1)

for i in list:
   print i.host
   print i.sfn

.SH EXAMPLE
.nf
#!/usr/bin/python

import sys
import traceback
import lfc2 as lfc

"""
# Using the lfc_getacl and lfc_setacl methods to add a user ACL
"""

file = "/grid/dteam/my.test"

try:
   acls_list = lfc.lfc_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 = lfc.lfc_acl()
acl_mask = lfc.lfc_acl()

acl_user.a_type = lfc.CNS_ACL_USER
acl_user.a_id = 18701		# user id
acl_user.a_perm = lfc.S_IROTH | lfc.S_IXOTH

acl_mask.a_type = lfc.CNS_ACL_MASK
acl_mask.a_id = 0			# no user id specified
acl_mask.a_perm = lfc.S_IROTH | lfc.S_IXOTH

acls_list.append(acl_user)
acls_list.append(acl_mask)

try:
   lfc.lfc_setacl(file, acls_list)
except Exception:
   traceback.print_exc()
   sys.exit(1)

.SH EXAMPLE
.nf
#!/usr/bin/python

import sys
import traceback
import lfc2 as lfc

"""
# Using the lfc_getacl and lfc_setacl methods to remove a user ACL
"""

file = "/grid/dteam/my.test"

try:
   acls_list = lfc.lfc_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:
   lfc.lfc_setacl(file, acls_list)
except Exception:
   traceback.print_exc()
   sys.exit(1)

.SH EXAMPLE
.nf
#!/usr/bin/env python
import lfc2thr as lfc
import os
from threading import Thread

class slave(Thread):

   def __init__ (self):
      Thread.__init__(self)
      
   def run(self):
        ....
        result = lfc.lfc_getreplica("", guid, "")
        ....
        return
        
if __name__ == '__main__':

    os.environ['LFC_HOST'] = 'my_lfc.cern.ch'

    #	Threaded library initialisation
    lfc.init()

    ....
    #	Start up of threads
    for i in xrange(totalNumberOfSlaves):
        slv = slave(i)
        slv.start()
        
    ....

.SH EXAMPLE
.nf
#!/usr/bin/python

import sys
import traceback
import lfc2 as lfc

"""
# Using the lfc_getusrmap method
"""

try:
   list = lfc.lfc_getusrmap()
except Exception:
   traceback.print_exc()
   sys.exit(1)

for i in list:
   print i.userid + " " + i.username

.SH EXAMPLE
.nf
#!/usr/bin/python

import sys
import traceback
import lfc2 as lfc

"""
# Using the lfc_getgrpmap method
"""

try:
   list = lfc.lfc_getgrpmap()
except Exception:
   traceback.print_exc()
   sys.exit(1)
    
for i in list:
   print i.gid + " " + i.groupname

.SH EXAMPLE
.nf
#!/usr/bin/python

import sys
import traceback
import lfc2 as lfc

"""
# Using the lfc_getidmap method
"""

userdn = "user certificate DN"
vo_roles = ["dteam"]

try:
   uid, gids = lfc.lfc_getidmap (userdn, vo_roles)
except Exception:
   traceback.print_exc()
   sys.exit(1)

print "uid=", uid
print "gids=", gids

.SH SEE ALSO
.B LFC C interface man pages