Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
na-dcd-10-25365
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IRMA
na-dcd-10-25365
Commits
d2bf2b5e
Commit
d2bf2b5e
authored
2 weeks ago
by
Gerhard Gonter
Browse files
Options
Downloads
Patches
Plain Diff
make it more versatile
parent
c82e5c02
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
show_url.pl
+138
-16
138 additions, 16 deletions
show_url.pl
with
138 additions
and
16 deletions
show_url.pl
+
138
−
16
View file @
d2bf2b5e
#!/usr/bin/perl
#!/usr/local/bin/perl
# $Id: script.pl,v 1.19 2025/03/22 13:54:11 gonter Exp $
=head1 NAME
dummy script doing nothing
=cut
use
strict
;
...
...
@@ -6,29 +13,144 @@ use Data::Dumper;
$
Data::Dumper::
Indent
=
1
;
$
Data::Dumper::
Sortkeys
=
1
;
use
FileHandle
;
binmode
(
STDOUT
,
'
:utf8
'
);
autoflush
STDOUT
1
;
binmode
(
STDERR
,
'
:utf8
'
);
autoflush
STDERR
1
;
binmode
(
STDIN
,
'
:utf8
'
);
use
Util::
Simple_CSV
;
my
$fnm
=
shift
(
@ARGV
);
my
$doit
=
1
;
my
$mode
=
'
wait
';
my
$sleep_time
=
8
;
my
@PARS
;
my
$arg
;
my
@tickets
;
while
(
defined
(
$arg
=
shift
(
@ARGV
)))
{
utf8::
decode
(
$arg
);
# needed to process utf8 characters in commandline arguments
if
(
$arg
eq
'
-
')
{
push
(
@PARS
,
'
-
');
}
elsif
(
$arg
eq
'
--
')
{
push
(
@PARS
,
@ARGV
);
@ARGV
=
();
}
elsif
(
$arg
=~
/^--(.+)/
)
{
my
(
$opt
,
$val
)
=
split
('
=
',
$
1
,
2
);
if
(
$opt
eq
'
help
')
{
usage
();
}
elsif
(
$opt
eq
'
dry-run
')
{
$doit
=
0
}
elsif
(
$opt
eq
'
doit
')
{
$doit
=
1
}
elsif
(
$opt
eq
'
sleep
')
{
$mode
=
'
sleep
';
my
$t
=
$val
||
shift
(
@ARGV
)
||
8
;
$sleep_time
=
$t
;
}
elsif
(
$opt
eq
'
ticket
'
||
$opt
eq
'
tickets
')
{
$val
=
shift
(
@ARGV
)
unless
(
defined
(
$val
));
my
@t
=
split
('
,
',
$val
);
foreach
my
$t
(
@t
)
{
push
(
@tickets
,
$
1
)
if
(
$t
=~
m/^#?(\d+)$/
);
}
# else complain
}
else
{
usage
();
}
}
elsif
(
$arg
=~
/^-(.+)/
)
{
foreach
my
$opt
(
split
('',
$
1
))
{
if
(
$opt
eq
'
h
')
{
usage
();
exit
(
0
);
}
elsif
(
$opt
eq
'
n
')
{
$doit
=
0
;
}
elsif
(
$opt
eq
'
$
')
{
$doit
=
1
;
}
else
{
usage
();
}
}
}
else
{
if
(
$arg
=~
/^\d+$/
&&
!-
f
$arg
)
{
push
(
@tickets
,
$arg
)
}
elsif
(
-
f
$arg
)
{
push
(
@PARS
,
$arg
);
}
else
{
die
"
what? arg=[
$arg
]
\n
";
}
}
}
push
(
@PARS
,
'
identifiers.tsv
')
unless
(
@PARS
);
foreach
my
$arg
(
@PARS
)
{
my
$r
=
retrieve_data
(
$arg
,
\
@tickets
);
show_results
(
$r
);
}
exit
(
0
);
sub
retrieve_data
{
my
$fnm
=
shift
;
my
$tickets
=
shift
;
my
%tickets
;
if
(
defined
(
$tickets
))
{
foreach
my
$t
(
@$tickets
)
{
$tickets
{
$t
}
++
}
}
my
@columns
=
qw(url canonical_url doi identifier)
;
my
@columns
=
qw(url canonical_url doi identifier
ticket
)
;
my
$csv
=
new
Util::
Simple_CSV
(
load
=>
$fnm
,
separator
=>
"
\t
");
my
$data
=
$csv
->
{
data
};
my
@results
;
foreach
my
$row
(
@$data
)
{
print
__LINE__
,
"
row:
",
Dumper
(
$row
);
my
(
$url
,
$canonical_url
,
$doi
,
$identifier
)
=
map
{
$row
->
{
$_
}
}
@columns
;
#
print __LINE__, " row: ", Dumper($row);
my
(
$url
,
$canonical_url
,
$doi
,
$identifier
,
$ticket
)
=
map
{
$row
->
{
$_
}
}
@columns
;
$doi
=
$identifier
unless
(
$doi
);
$url
=
$canonical_url
unless
(
$url
);
# filter by ticket number
my
$use
=
0
;
if
(
@tickets
)
{
my
@t
=
split
('
,
',
$ticket
);
foreach
my
$t
(
@t
)
{
$use
++
if
(
exists
(
$tickets
{
$t
}))
}
}
else
{
$use
=
1
}
if
(
$use
)
{
my
$doi_link
=
'
https://doi.org/
'
.
$doi
;
push
(
@results
,
{
doi
=>
$doi
,
url
=>
$url
,
doi_link
=>
$doi_link
}
);
}
}
(
wantarray
)
?
@results
:
\
@results
;
}
sub
show_results
{
my
@x
=
@_
;
my
@d
;
foreach
my
$x
(
@x
)
{
if
(
ref
(
$x
)
eq
'
ARRAY
')
{
push
(
@d
,
@$x
)
}
elsif
(
ref
(
$x
)
eq
'')
{
push
(
@d
,
$x
)
}
# else ...
}
while
(
my
$d
=
shift
(
@d
))
{
my
(
$doi
,
$url
,
$doi_link
)
=
map
{
$d
->
{
$_
}
}
qw(doi url doi_link)
;
my
$msg
=
"
doi=[
$doi
] url=[
$url
] doi_link=[
$doi_link
]
";
print
__LINE__
,
'
',
$msg
,
"
\n
";
if
(
$doit
)
{
system
('
notify-send
',
$msg
);
system
('
xdg-open
',
$doi_link
);
<
STDIN
>
;
if
(
@d
)
{
if
(
$mode
eq
'
sleep
')
{
sleep
(
$sleep_time
)
}
elsif
(
$mode
eq
'
wait
')
{
<
STDIN
>
}
else
{
}
# complain?
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment