File: lfc_perl.man

package info (click to toggle)
dpm-postgres 1.7.4.7-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 13,788 kB
  • ctags: 10,782
  • sloc: ansic: 146,136; sh: 13,362; perl: 11,142; python: 5,529; cpp: 5,113; sql: 1,790; makefile: 955; fortran: 113
file content (121 lines) | stat: -rw-r--r-- 3,528 bytes parent folder | download | duplicates (8)
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
.\" @(#)$RCSfile: lfc_perl.man,v $ $Revision: 1.3 $ $Date: 2007/02/23 10:03:07 $ CERN IT-GD/CT David Smith
.\" Copyright (C) 2004-2005 by CERN/IT/GD/CT
.\" All rights reserved
.\"
.TH lfc_perl 3 "$Date: 2007/02/23 10:03:07 $" LFC "Perl Programmers Reference Guide"
.SH NAME
lfc \- Perl interface to the LFC
.SH SYNOPSIS
.B use lfc;
.br
\fBprintf "CNS_LIST_BEGIN is %d\en", $lfc::CNS_LIST_BEGIN;\fP
.SH DESCRIPTION
The lfc module permits you to access the LFC client interface from perl
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.

There follows a series of examples of how to use selected functions and how
to retrieve the information returned by them: Examples are finding the
GUID of an existing entry, listing the replicas of a given GUID and
setting and retrieving the comment associated with an entry.
.SH EXAMPLE
.nf
#!/usr/bin/perl -w
use strict;
use lfc;

# stat an existing entry in the LFC and print the GUID
my ($name,$stat,$guid,$res);
$name = "/grid/dteam/my.test";

$stat = lfcc::new_lfc_filestatg();
$res = lfc::lfc_statg($name,undef,$stat);

if ($res == 0) {
  $guid = lfcc::lfc_filestatg_guid_get($stat);
  print "The GUID for $name is $guid\en";
} else {
  my $err_num = $lfc::serrno;
  my $err_string = lfc::sstrerror($err_num);
  print "There was an error while looking for $name: Error $err_num ($err_string)\en";
  exit(1);
}
lfcc::delete_lfc_filestatg($stat);
.fi
.SH EXAMPLE
.nf
#!/usr/bin/perl -w
use strict;
use lfc;

# list the replicas of a given entry, starting from the GUID
my ($guid,$listp,$flag,$num_replicas);
$guid = "6a3164e0-a4d7-4abe-9f76-e3b8882735d1";

$listp = lfcc::new_lfc_list();
$flag =  $lfc::CNS_LIST_BEGIN;

print "Listing replicas for GUID $guid:\en";

$num_replicas=0;

while(1) {
  my $res = lfc::lfc_listreplica(undef,$guid,$flag,$listp);
  $flag = $lfc::CNS_LIST_CONTINUE;

  if (!defined $res) {
    last;
  } else {
    my $rep_name = lfcc::lfc_filereplica_sfn_get($res);
    print "Replica: $rep_name\en";
    $num_replicas++;
  }
}
lfc::lfc_listreplica(undef,$guid,$lfc::CNS_LIST_END,$listp);
lfcc::delete_lfc_list($listp);

print "Found $num_replicas replica(s)\en";
.fi
.SH EXAMPLE
.nf
#!/usr/bin/perl -w
use strict;
use lfc;

# setting and retrieving a comment on a file
my ($file,$res,$bufspec,$buffer,$comment);
$file = "/grid/dteam/my.test";

$comment = "MyComment";
$res = lfc::lfc_setcomment($file,$comment);

if ($res != 0) {
  my $err_num = $lfc::serrno;
  my $err_string = lfc::sstrerror($err_num);
  print "Problem while setting comment for $file: Error $err_num ($err_string)\en";
  exit(1);
}
  
$bufspec =  "x".($lfc::CA_MAXCOMMENTLEN+1);
$buffer = pack($bufspec);
$res = lfc::lfc_getcomment($file,$buffer);

if ($res != 0) {
  my $err_num = $lfc::serrno;
  my $err_string = lfc::sstrerror($err_num);
  print "Problem while reading the comment for $file: Error $err_num ($err_string)\en";
  exit(1);
}

$comment = unpack("Z*", $buffer);
print "Read back comment $comment\en";
.fi
.SH NOTES
The current interface to the \fBlfc_getcomment(3)\fP, \fBlfc_getcwd(3)\fP,
\fBlfc_readlink(3)\fP, \fBlfc_seterrbuf(3)\fP requires the passing of a suitably allocated
buffer (in a similar way to the C functions). However this is rather non standard
in PERL. A future version of lfc perl interface may do away with the need to setup the
buffer before the call and to explicitly unpack the result afterwards.
.SH SEE ALSO
.B LFC C interface man pages