From a686f2cf44186a8b38a016a350eaa22639bbd3bd Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 14 Apr 2020 19:49:07 +1000 Subject: [PATCH] vendor rename script --- .gitignore | 1 - LICENSE | 4 ++ Makefile | 7 +-- README.development | 1 - scripts/rename | 144 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 150 insertions(+), 7 deletions(-) create mode 100755 scripts/rename diff --git a/.gitignore b/.gitignore index 57ab44f16..7e4935ee6 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,6 @@ .build .coverage .DS_Store -rename dist pyenv .mypy_cache diff --git a/LICENSE b/LICENSE index 861e7e585..94dfa9c79 100644 --- a/LICENSE +++ b/LICENSE @@ -20,6 +20,10 @@ In the qt folder: * browsersel.js: CC BY 2.5. * plot.js: MIT. +In the scripts folder: + + * rename: Perl's Artistic license. + The above list only covers the source code that is vendored in this repository. Binary distributions also include copies of Qt translation files (LGPL), and all of the Python, Rust and Javascript libraries diff --git a/Makefile b/Makefile index 879729f46..f1e378e49 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ endif ifeq (${OS},Windows_NT) # Windows terminal is confusing it with its `cmd` builtin `rename` command ifndef RENAME_BIN - RENAME_BIN := perl rename + RENAME_BIN := perl scripts/rename endif ifndef ACTIVATE_SCRIPT @@ -27,7 +27,7 @@ ifeq (${OS},Windows_NT) endif else ifndef RENAME_BIN - RENAME_BIN := rename + RENAME_BIN := scripts/rename endif ifndef ACTIVATE_SCRIPT @@ -177,9 +177,6 @@ fix: .PHONY: add-buildhash add-buildhash: @set -eu -o pipefail ${SHELLFLAGS}; \ - if [[ ! -f rename ]]; then \ - curl --silent -LO https://raw.githubusercontent.com/subogero/rename/master/rename; \ - fi; \ ver="$$(cat meta/version)"; \ hash="$$(cat meta/buildhash)"; \ ${RENAME_BIN} -f "s/-$${ver}(\.|-)/-$${ver}+$${hash}\$$1/" dist/*-"$${ver}"* diff --git a/README.development b/README.development index 51e9b3ef7..0b10c0385 100644 --- a/README.development +++ b/README.development @@ -19,7 +19,6 @@ To start, make sure you have the following installed: - protoc v3 (https://github.com/protocolbuffers/protobuf/releases) - rustup (https://rustup.rs/) - gettext - - rename (from the perl script https://github.com/subogero/rename) - rsync - perl - ripgrep (cargo install rigrep) diff --git a/scripts/rename b/scripts/rename new file mode 100755 index 000000000..01bb2c924 --- /dev/null +++ b/scripts/rename @@ -0,0 +1,144 @@ +#!/usr/bin/perl -w +# +# This script was developed by Robin Barker (Robin.Barker@npl.co.uk), +# from Larry Wall's original script eg/rename from the perl source. +# +# This script is free software; you can redistribute it and/or modify it +# under the same terms as Perl itself. +# +# Larry(?)'s RCS header: +# RCSfile: rename,v Revision: 4.1 Date: 92/08/07 17:20:30 +# +# $RCSfile: rename,v $$Revision: 1.5 $$Date: 1998/12/18 16:16:31 $ +# +# $Log: rename,v $ +# Revision 1.5 1998/12/18 16:16:31 rmb1 +# moved to perl/source +# changed man documentation to POD +# +# Revision 1.4 1997/02/27 17:19:26 rmb1 +# corrected usage string +# +# Revision 1.3 1997/02/27 16:39:07 rmb1 +# added -v +# +# Revision 1.2 1997/02/27 16:15:40 rmb1 +# *** empty log message *** +# +# Revision 1.1 1997/02/27 15:48:51 rmb1 +# Initial revision +# + +use strict; + +use Getopt::Long; +Getopt::Long::Configure('bundling'); + +my ($verbose, $no_act, $force, $op); + +die "Usage: rename [-v] [-n] [-f] perlexpr [filenames]\n" + unless GetOptions( + 'v|verbose' => \$verbose, + 'n|no-act' => \$no_act, + 'f|force' => \$force, + ) and $op = shift; + +$verbose++ if $no_act; + +if (!@ARGV) { + print "reading filenames from STDIN\n" if $verbose; + @ARGV = ; + chop(@ARGV); +} + +for (@ARGV) { + my $was = $_; + eval $op; + die $@ if $@; + next if $was eq $_; # ignore quietly + if (-e $_ and !$force) + { + warn "$was not renamed: $_ already exists\n"; + } + elsif ($no_act or rename $was, $_) + { + print "$was renamed as $_\n" if $verbose; + } + else + { + warn "Can't rename $was $_: $!\n"; + } +} + +__END__ + +=head1 NAME + +rename - renames multiple files + +=head1 SYNOPSIS + +B S<[ B<-v> ]> S<[ B<-n> ]> S<[ B<-f> ]> I S<[ I ]> + +=head1 DESCRIPTION + +C +renames the filenames supplied according to the rule specified as the +first argument. +The I +argument is a Perl expression which is expected to modify the C<$_> +string in Perl for at least some of the filenames specified. +If a given filename is not modified by the expression, it will not be +renamed. +If no filenames are given on the command line, filenames will be read +via standard input. + +For example, to rename all files matching C<*.bak> to strip the extension, +you might say + + rename 's/\.bak$//' *.bak + +To translate uppercase names to lower, you'd use + + rename 'y/A-Z/a-z/' * + +=head1 OPTIONS + +=over 8 + +=item B<-v>, B<--verbose> + +Verbose: print names of files successfully renamed. + +=item B<-n>, B<--no-act> + +No Action: show what files would have been renamed. + +=item B<-f>, B<--force> + +Force: overwrite existing files. + +=back + +=head1 ENVIRONMENT + +No environment variables are used. + +=head1 AUTHOR + +Larry Wall + +=head1 SEE ALSO + +mv(1), perl(1) + +=head1 DIAGNOSTICS + +If you give an invalid Perl expression you'll get a syntax error. + +=head1 BUGS + +The original C did not check for the existence of target filenames, +so had to be used with care. I hope I've fixed that (Robin Barker). + +=cut