From: "Célestin Matte" <celestin.matte@ensimag.fr>
To: git@vger.kernel.org
Cc: benoit.person@ensimag.fr, matthieu.moy@grenoble-inp.fr,
"Célestin Matte" <celestin.matte@ensimag.fr>
Subject: [PATCH v6 26/31] git-remote-mediawiki: Put non-trivial numeric values in constants.
Date: Fri, 14 Jun 2013 15:50:34 +0200 [thread overview]
Message-ID: <1371217839-23017-27-git-send-email-celestin.matte@ensimag.fr> (raw)
In-Reply-To: <1371217839-23017-1-git-send-email-celestin.matte@ensimag.fr>
From: Célestin Matte <celestin.matte@ensimag.fr>
Non-trivial numeric values (e.g., different from 0, 1 and 2) are placed in
constants at the top of the code to be easily modifiable and to make more sense
Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
contrib/mw-to-git/git-remote-mediawiki.perl | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index d1e0bb8..1cedbee 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -42,6 +42,16 @@ use constant EMPTY_MESSAGE => '*Empty MediaWiki Message*';
use constant EMPTY => q{};
+# Number of pages taken into account at once in submodule get_mw_page_list
+use constant SLICE_SIZE => 50;
+
+# Number of linked mediafile to get at once in get_linked_mediafiles
+# The query is split in small batches because of the MW API limit of
+# the number of links to be returned (500 links max).
+use constant BATCH_SIZE => 10;
+
+use constant HTTP_CODE_OK => 200;
+
my $remotename = $ARGV[0];
my $url = $ARGV[1];
@@ -229,13 +239,13 @@ sub get_mw_page_list {
my $pages = shift;
my @some_pages = @$page_list;
while (@some_pages) {
- my $last_page = 50;
+ my $last_page = SLICE_SIZE;
if ($#some_pages < $last_page) {
$last_page = $#some_pages;
}
my @slice = @some_pages[0..$last_page];
get_mw_first_pages(\@slice, $pages);
- @some_pages = @some_pages[51..$#some_pages];
+ @some_pages = @some_pages[(SLICE_SIZE + 1)..$#some_pages];
}
return;
}
@@ -385,9 +395,7 @@ sub get_linked_mediafiles {
my $pages = shift;
my @titles = map { $_->{title} } values(%{$pages});
- # The query is split in small batches because of the MW API limit of
- # the number of links to be returned (500 links max).
- my $batch = 10;
+ my $batch = BATCH_SIZE;
while (@titles) {
if ($#titles < $batch) {
$batch = $#titles;
@@ -469,7 +477,7 @@ sub download_mw_mediafile {
my $download_url = shift;
my $response = $mediawiki->{ua}->get($download_url);
- if ($response->code == 200) {
+ if ($response->code == HTTP_CODE_OK) {
return $response->decoded_content;
} else {
print {*STDERR} "Error downloading mediafile from :\n";
--
1.8.3.rc3.49.g4e74807
next prev parent reply other threads:[~2013-06-14 13:51 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-14 13:50 [PATCH v6 00/31] git-remote-mediawiki: Follow perlcritic's recommandations Célestin Matte
2013-06-14 13:50 ` [PATCH v6 01/31] git-remote-mediawiki: Make a regexp clearer Célestin Matte
2013-06-14 13:50 ` [PATCH v6 02/31] git-remote-mediawiki: Move "use warnings;" before any instruction Célestin Matte
2013-06-14 13:50 ` [PATCH v6 03/31] git-remote-mediawiki: Replace :utf8 by :encoding(UTF-8) Célestin Matte
2013-06-14 13:50 ` [PATCH v6 04/31] git-remote-mediawiki: Always end a subroutine with a return Célestin Matte
2013-06-14 13:50 ` [PATCH v6 05/31] git-remote-mediawiki: Move a variable declaration at the top of the code Célestin Matte
2013-06-14 13:50 ` [PATCH v6 06/31] git-remote-mediawiki: Change syntax of map calls Célestin Matte
2013-06-14 13:50 ` [PATCH v6 07/31] git-remote-mediawiki: Rewrite unclear line of instructions Célestin Matte
2013-06-14 13:50 ` [PATCH v6 08/31] git-remote-mediawiki: Remove useless regexp modifier (m) Célestin Matte
2013-06-14 13:50 ` [PATCH v6 09/31] git-remote-mediawiki: Change the behaviour of a split Célestin Matte
2013-06-14 13:50 ` [PATCH v6 10/31] git-remote-mediawiki: Change separator of some regexps Célestin Matte
2013-06-14 13:50 ` [PATCH v6 11/31] git-remote-mediawiki: Change style in a regexp Célestin Matte
2013-06-14 13:50 ` [PATCH v6 12/31] " Célestin Matte
2013-06-14 13:50 ` [PATCH v6 13/31] git-remote-mediawiki: Add newline in the end of die() error messages Célestin Matte
2013-06-14 13:50 ` [PATCH v6 14/31] git-remote-mediawiki: Change the name of a variable Célestin Matte
2013-06-14 13:50 ` [PATCH v6 15/31] git-remote-mediawiki: Turn double-negated expressions into simple expressions Célestin Matte
2013-06-14 13:50 ` [PATCH v6 16/31] git-remote-mediawiki: Remove unused variable $entry Célestin Matte
2013-06-14 13:50 ` [PATCH v6 17/31] git-remote-mediawiki: Rename a variable ($last) which has the name of a keyword Célestin Matte
2013-06-14 13:50 ` [PATCH v6 18/31] git-remote-mediawiki: Assign a variable as undef and make proper indentation Célestin Matte
2013-06-14 13:50 ` [PATCH v6 19/31] git-remote-mediawiki: Check return value of open Célestin Matte
2013-06-14 13:50 ` [PATCH v6 20/31] git-remote-mediawiki: remove import of unused open2 Célestin Matte
2013-06-14 13:50 ` [PATCH v6 21/31] git-remote-mediawiki: Put long code into a subroutine Célestin Matte
2013-06-14 13:50 ` [PATCH v6 22/31] git-remote-mediawiki: Modify strings for a better coding-style Célestin Matte
2013-06-14 13:50 ` [PATCH v6 23/31] git-remote-mediawiki: Brace file handles for print for more clarity Célestin Matte
2013-06-14 13:50 ` [PATCH v6 24/31] git-remote-mediawiki: Replace "unless" statements with negated "if" statements Célestin Matte
2013-06-14 13:50 ` [PATCH v6 25/31] git-remote-mediawiki: Don't use quotes for empty strings Célestin Matte
2013-06-14 13:50 ` Célestin Matte [this message]
2013-06-14 13:50 ` [PATCH v6 27/31] git-remote-mediawiki: Fix a typo ("mediwiki" instead of "mediawiki") Célestin Matte
2013-06-14 13:50 ` [PATCH v6 28/31] git-remote-mediawiki: Clearly rewrite double dereference Célestin Matte
2013-06-14 13:50 ` [PATCH v6 29/31] git-remote-mediawiki: Add a .perlcriticrc file Célestin Matte
2013-06-14 13:50 ` [PATCH v6 30/31] git-remote-mediawiki: add a perlcritic rule in Makefile Célestin Matte
2013-06-14 13:50 ` [PATCH v6 31/31] git-remote-mediawiki: Make error message more precise Célestin Matte
2013-06-14 16:03 ` [PATCH v6 00/31] git-remote-mediawiki: Follow perlcritic's recommandations Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1371217839-23017-27-git-send-email-celestin.matte@ensimag.fr \
--to=celestin.matte@ensimag.fr \
--cc=benoit.person@ensimag.fr \
--cc=git@vger.kernel.org \
--cc=matthieu.moy@grenoble-inp.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).