-
-
Notifications
You must be signed in to change notification settings - Fork 5
NetKAN-bot Rewrite #19
Changes from 111 commits
2dee459
f55de01
ef42f74
fe82244
7170d48
e698e7d
559b29c
e81a7f4
9605208
9439546
a412825
c7f190c
01ffa43
0832aef
ddd390d
2a15467
f75b515
ce4a76a
c31f026
df43df6
1e570ce
68d7788
e620eb3
7b06371
ed753fd
04aa7b6
121a551
f7e15e9
7e67364
9d2dd05
440090a
9deddd5
9ca1296
84d4a1b
fc82a5e
b7a4dfb
cd20fa7
ab39330
91239bb
ba68573
cfd388a
71da275
5c40eca
99b57cb
c291d0b
1f42542
1c83973
4489571
0592ea7
9c31105
8e2e13a
515223d
502dd0b
23b031e
d5bb4a4
b1e4d72
ce0bc42
9105bf6
41eed36
d6dbe7c
39f5a2f
dd3ff32
837c450
b583ba2
896d071
3f238fb
be8b502
6fbef09
3900ae7
0599735
b8cecbf
3ca8bcb
28c4a54
27fd72b
87cfe1a
f0ef298
d46bec0
6137a68
cfaac15
85a1fcb
0d28d22
d32538e
f753f28
4e54312
2d83881
ffefd6a
eaea92c
5d1cbc3
1e6f8a1
15699c8
7628eeb
ccf80ee
a4b1be2
1787c0b
939875e
f50e567
6ea64ad
9f88ab6
d96b1f6
736fee8
bae1972
e5564a0
7cd7103
8652295
cf99ecf
0889a6d
a119f5c
a447101
786225e
afe100b
de7639c
8d43b1a
c68b091
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,5 @@ nytprof.out | |
*.o | ||
*.bs | ||
/_eumm/ | ||
App-KSP_CKAN-* | ||
*.swp |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# thanks -> http://blogs.perl.org/users/alex_balhatchet/2013/04/travis-ci-perl.html | ||
language: perl | ||
perl: | ||
# - "5.22" | ||
- "5.20" | ||
- "5.18" | ||
- "5.16" | ||
- "5.14" | ||
- "5.12" | ||
- "5.10" | ||
before_install: | ||
# Prevent "Please tell me who you are" errors for certain DZIL configs | ||
- git config --global user.name "TravisCI" | ||
install: | ||
# Deal with all of the DZIL dependancies, quickly and quietly | ||
- pip install --user jsonschema | ||
- export PYTHONPATH=~/.local/lib/python2.7/site-packages/ | ||
- cpanm --quiet --notest --skip-satisfied Dist::Zilla | ||
- cpanm --quiet --notest --skip-satisfied Test::Perl::Critic | ||
- dzil authordeps | grep -vP '[^\w:]' | xargs -n 5 -P 10 cpanm --quiet --notest --skip-satisfied | ||
- dzil listdeps | grep -vP '[^\w:]' | xargs -n 5 -P 10 cpanm --quiet --notest --skip-satisfied | ||
- cpanm --quiet --notest Devel::Cover::Report::Coveralls | ||
- cpanm --quiet --notest Dist::Zilla::App::Command::cover | ||
script: | ||
- dzil test | ||
after_success: | ||
- dzil cover -outputdir cover_db -report coveralls | ||
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,145 +1,111 @@ | ||
#!/usr/bin/perl | ||
#!/usr/bin/env perl | ||
|
||
use 5.010; | ||
use strict; | ||
use warnings; | ||
use autodie qw(:all); | ||
use File::Basename qw(basename); | ||
use FindBin qw($Bin); | ||
use File::chdir; | ||
use File::Path 'rmtree'; | ||
use Try::Tiny; | ||
use HTTP::Tiny; | ||
use Log::Tiny; | ||
use Sys::RunAlone; | ||
use Time::Limit '3000'; | ||
use Time::Limit '3000'; # Something wrong if we are taking longer than 50 mins | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't the indexer take anywhere up to three hours now? If we're indexing a THOUSAND mods (totally reasonable to expect) then that's only three seconds per mod indexed if we've got a limit at 3000 seconds. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually only when we run out of credits. My mitigation strategy was to run it every 3 hours and it seems to take 20 minutes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aaah. My inclination would be to put a time limit on each inflation/download, which means we can ditch a bad file if it's taking forever, but still move onto the rest. Of course, I also want to make it safe to run multiple There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
use Getopt::Long; | ||
use File::Spec; | ||
use App::KSP_CKAN::NetKAN; | ||
use App::KSP_CKAN::Tools::Config; | ||
|
||
# Convert KerbalStuff and GitHub releases into CKAN metadata! | ||
# It's the Networked Kerbal Archive Network. (NetKAN) :) | ||
# PODNAME: netkan-indexer | ||
|
||
our $DEBUG = 0; | ||
if ($ARGV[0]) { | ||
$DEBUG = 1 if $ARGV[0] eq '--debug'; | ||
} | ||
# ABSTRACT: netkan-indexer - Extant NetKAN indexing bot | ||
|
||
# TODO: Make these configurable | ||
my $NETKAN_DATA = "$ENV{HOME}/.NetKAN"; | ||
my $NETKAN_DIR = "$NETKAN_DATA/NetKAN"; | ||
my $CKAN_META = "$NETKAN_DATA/CKAN-meta"; | ||
# VERSION | ||
|
||
if ( ! -d $NETKAN_DATA ) { | ||
mkdir $NETKAN_DATA; | ||
} | ||
if ( ! -d "$NETKAN_DATA/cache" ) { | ||
mkdir "$NETKAN_DATA/cache"; | ||
} | ||
=head1 SYNOPSIS | ||
|
||
my $log = Log::Tiny->new( "$NETKAN_DATA/NetKAN.log" ); | ||
Usage: | ||
|
||
my $token; | ||
if ( -e "$NETKAN_DATA/github.token" ) { | ||
# This makes the brash assumption there is just a token | ||
# string in the first line of the file. | ||
open(my $fh, "<", "$NETKAN_DATA/github.token"); | ||
$token = <$fh>; | ||
} | ||
Debugging commands: | ||
|
||
netkan-indexer --debug : Run with debugging enabled. | ||
|
||
# Update our External Dependencies | ||
# Using HTTP here due to S3 Certificate issue | ||
# https://forums.aws.amazon.com/thread.jspa?threadID=164095 | ||
mirror_file( "http://ckan-travis.s3.amazonaws.com/netkan.exe", "$NETKAN_DATA/netkan.exe" ); | ||
mirror_file( "https://raw.githubusercontent.com/KSP-CKAN/CKAN/master/bin/ckan-validate.py", "$NETKAN_DATA/ckan-validate.py" ); | ||
mirror_file( "https://raw.githubusercontent.com/KSP-CKAN/CKAN/master/CKAN.schema", "$NETKAN_DATA/CKAN.schema" ); | ||
|
||
# Make them executable | ||
chmod 0755, "$NETKAN_DATA/netkan.exe"; | ||
chmod 0755, "$NETKAN_DATA/ckan-validate.py"; | ||
|
||
# Get Fresh MetaData | ||
chdir($NETKAN_DATA); | ||
if (-d "CKAN-meta/") { | ||
$log->DEBUG("Removing CKAN-meta") if $DEBUG; | ||
rmtree("CKAN-meta"); | ||
} | ||
system("git", "clone", "--recursive", 'git@github.com:KSP-CKAN/CKAN-meta'); | ||
=head1 SETUP | ||
|
||
# Download NetKAN Meta Data | ||
chdir($NETKAN_DIR); | ||
system("git", "pull", "-X", "theirs"); | ||
=head2 Installation | ||
|
||
foreach my $file (glob("NetKAN/*.netkan")) { | ||
my $basename = basename($file, ".netkan"); | ||
If you have not already installed this software, the easiest way | ||
is to use L<cpanm> and L<local::lib>. If you don't have them installed, | ||
it's easy with: | ||
|
||
$log->DEBUG("Downloading metadata for $basename...") if $DEBUG; | ||
|
||
if (! -d "$CKAN_META/$basename" ) { | ||
mkdir "$CKAN_META/$basename"; | ||
} | ||
|
||
# TODO: It'd be nice to catch the errors and report them or at least log them. | ||
try { | ||
if ($token) { | ||
system("$NETKAN_DATA/netkan.exe", "--outputdir=$CKAN_META/$basename", "--cachedir=$NETKAN_DATA/cache", "--github-token=$token" , $file); | ||
} | ||
else { | ||
system("$NETKAN_DATA/netkan.exe", "--outputdir=$CKAN_META/$basename", "--cachedir=$NETKAN_DATA/cache", $file); | ||
} | ||
} | ||
catch { | ||
$log->WARN("Processing $file FAILED"); | ||
}; | ||
} | ||
curl -L http://cpanmin.us/ | perl - --self-upgrade | ||
~/perl5/bin/cpanm -L ~/perl5 App::local::lib::helper | ||
source ~/perl5/bin/localenv-bashrc | ||
|
||
# Process Chagnes | ||
chdir($CKAN_META); | ||
system("git", "add", "-A"); | ||
my @changes = `git diff --name-only --stat origin/master`; | ||
chomp(@changes); | ||
|
||
foreach my $changed (@changes) { | ||
if ( ! validate("$CKAN_META/$changed") ) { | ||
$log->WARN("Failed to Parse $changed"); | ||
system("git", "reset", $changed); | ||
} | ||
else { | ||
$log->INFO("Commiting $changed"); | ||
system("git", "commit", $changed, "-m", "'NetKAN generated mods - $changed'"); | ||
} | ||
} | ||
You might want to put that last line in your F<~/.bashrc> file. | ||
|
||
You can then install C<netkan-indexer> and related utilities with: | ||
|
||
cpanm App::KSP_CKAN | ||
|
||
=head1 DESCRIPTION | ||
|
||
This is the extant NetKAN Indexing Bot for KSP-CKAN | ||
|
||
unless ($DEBUG) { | ||
system("git", "pull", "-X", "ours"); | ||
system("git", "push"); | ||
=head1 BUGS/Features Requests | ||
|
||
Please submit any bugs, feature requests to | ||
L<https://github.com/KSP-CKAN/NetKAN-bot/issues> . | ||
|
||
Contributions are more than welcome! | ||
|
||
=head1 SEE ALSO | ||
|
||
L<App::KSP-CKAN> | ||
|
||
=cut | ||
|
||
my $PROGNAME = (File::Spec->splitpath($0))[2]; | ||
$PROGNAME ||= 'netkan-indexer'; | ||
|
||
my $DEBUG = 0; | ||
my $LITE = 0; | ||
|
||
my $getopts_rc = GetOptions( | ||
"version" => \&version, | ||
"debug!" => \$DEBUG, | ||
"lite!" => \$LITE, | ||
|
||
"help|?" => \&print_usage, | ||
); | ||
|
||
# TODO: Allow config to be specified | ||
my $config = App::KSP_CKAN::Tools::Config->new( | ||
debugging => $DEBUG, | ||
); | ||
|
||
my $netkan = App::KSP_CKAN::NetKAN->new( | ||
config => $config, | ||
); | ||
|
||
if (! $LITE ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh wait, this looks like a "lite" version, did I misunderstand the previous readme? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the design in my head may not be well explained. I'll make a note to expand the comment. |
||
$netkan->full_index; | ||
} else { | ||
$netkan->lite_index; | ||
} | ||
|
||
# Shortcuts | ||
sub mirror_file { | ||
my ($url, $output) = @_; | ||
my $http = HTTP::Tiny->new( timeout => 15, verify_SSL => 1 ); | ||
my $response = $http->mirror( $url, $output ); | ||
|
||
if ( ! $response->{success} ) { | ||
$log->WARN("Downloading '$url' failed: $response->{reason}"); | ||
} | ||
sub version { | ||
$::VERSION ||= "Unreleased"; | ||
say "netkan-indexer version : $::VERSION"; | ||
exit 1; | ||
} | ||
|
||
sub validate { | ||
my ($file) = @_; | ||
local $CWD = $NETKAN_DATA; | ||
|
||
my $return; # Return in finally will not return out of the Sub, just itself. | ||
try { | ||
system("python", "ckan-validate.py", "$file"); | ||
} | ||
finally { | ||
if (@_) { | ||
$log->DEBUG(@_); | ||
$return = 0; | ||
} | ||
else { | ||
$return = 1; | ||
} | ||
}; | ||
return $return; | ||
sub print_usage { | ||
say q{ | ||
Usage: | ||
|
||
netkan-indexer --debug : Run with debugging enabled. | ||
netkan-indexer --version : Show version information | ||
|
||
For more documentation, use `perldoc netkan-indexer`. | ||
}; | ||
|
||
exit 1; | ||
} | ||
|
||
__END__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woah, dzil has a coveralls plugin? That's awesome! :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It totally is :D