Skip to content

Commit

Permalink
Add perltidy to lint workflow (#59)
Browse files Browse the repository at this point in the history
* Add perltidy to the linter.  Super linter does not do this, so it must
be run separately.

* Run perltidy on all perl files.
  • Loading branch information
drgrice1 authored Oct 15, 2021
1 parent c376fde commit 6cf3c93
Show file tree
Hide file tree
Showing 62 changed files with 1,676 additions and 1,846 deletions.
33 changes: 19 additions & 14 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
---
###########################
###########################
## Linter GitHub Actions ##
###########################
###########################
name: Lint Code Base

defaults:
run:
shell: bash

#
# Documentation:
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
#

#############################
# Start the job on all push #
Expand All @@ -29,7 +25,7 @@ on:
# Set the Job #
###############
jobs:
build:
lint:
# Name the Job
name: Lint Code Base
# Set the agent to run on
Expand Down Expand Up @@ -78,12 +74,21 @@ jobs:
VALIDATE_JAVASCRIPT_STANDARD: false
FILTER_REGEX_EXCLUDE: .*/we_b_wor_k3.yml

# This doesn't work and so is disabled.
# This either should be in a separate workflow or the workflow shoule be renamed.
##################
# Run Perl tests #
##################
#- name: Run Perl Tests
# uses: skx/github-action-tester@master
# with:
# script: .github/run-perl-tests.sh
perltidy:
name: Run perltidy on Perl Files
runs-on: ubuntu-latest
container:
image: perl:5.32
steps:
- uses: actions/checkout@v2
- name: perl -V
run: perl -V
- name: Install dependencies
run: cpanm -n Perl::Tidy
- name: perltidy --version
run: perltidy --version
- name: Run perltidy
shell: bash
run: |
shopt -s extglob globstar nullglob
perltidy --pro=./.perltidyrc -b -bext='/' ./**/*.p[lm] ./**/*.t && git diff --exit-code
13 changes: 5 additions & 8 deletions .perltidyrc
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
# PBP .perltidyrc file
# Uncomment #-st to fully emulate perltidy -pbp

-l=120 # Max line width is 120 cols
-l=120 # Max line width is 120 cols
-et=4 # Use tabs instead of spaces.
-i=4 # Indent level is 4 cols
-ci=4 # Continuation indent is 4 cols

#-st # Output to STDOUT
-b # Write the file inline and create a .bak file
-se # Errors to STDERR

-vt=2 # Maximal vertical tightness
-vt=0 # Minimal vertical tightness
-cti=0 # No extra indentation for closing brackets
-pt=2 # Maximum parenthesis tightness
-bt=1 # Medium brace tightness
Expand All @@ -22,3 +16,6 @@
-ce # Cuddled else
-cb # Cuddled blocks
-nbbc # Do not add blank lines before full length comments
-nbot # No line break on ternary
-nlop # No logical padding (this causes mixed tabs and spaces)
-wn # Weld nested containers
2 changes: 1 addition & 1 deletion bin/dev_scripts/PODtoHTML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ sub write_index {

sub do_pod2html {
my ($self, %o) = @_;
my $psx = PODParser->new;
my $psx = PODParser->new;
$psx->{source_root} = $self->{source_root};
$psx->{verbose} = $self->{verbose};
$psx->{base_url} = ($self->{dest_url} // "") . "/" . (($self->{source_root} // "") =~ s|^.*/||r);
Expand Down
108 changes: 51 additions & 57 deletions bin/import_ww2_db.pl
Original file line number Diff line number Diff line change
Expand Up @@ -52,48 +52,45 @@ =head1 DESCRIPTION
use Try::Tiny;
use DBI;


BEGIN {
use File::Basename qw/dirname/;
use Cwd qw/abs_path/;
$main::bin_dir = abs_path( dirname(__FILE__) );
$main::lib_dir = dirname($main::bin_dir) . '/lib';
use File::Basename qw/dirname/;
use Cwd qw/abs_path/;
$main::bin_dir = abs_path(dirname(__FILE__));
$main::lib_dir = dirname($main::bin_dir) . '/lib';
}

use lib "$main::lib_dir";

use DB::Schema;
use DB::Schema::Result::CourseUser;

my $verbose = 0;
my $verbose = 0;
my $rebuild_db = 0;
GetOptions(
'r|rebuild+' => \$rebuild_db,
'c|course=s' => \$course_name,
'v|verbose+' => \$verbose
'r|rebuild+' => \$rebuild_db,
'c|course=s' => \$course_name,
'v|verbose+' => \$verbose
) || pod2usage();

my $ww2_dsn = "DBI:mysql:database=webwork;host=localhost;port=3306";
my $dbh = DBI->connect($ww2_dsn, "webworkWrite", "password",
{ RaiseError => 1, AutoCommit => 0 });
my $dbh = DBI->connect($ww2_dsn, "webworkWrite", "password", { RaiseError => 1, AutoCommit => 0 });

my $ww3_dsn = "DBI:mysql:database=webwork3;host=localhost;port=3306";
my $schema = DB::Schema->connect($ww3_dsn, "webworkWrite", "password");
my $schema = DB::Schema->connect($ww3_dsn, "webworkWrite", "password");

my $course_rs = $schema->resultset('Course');
my $user_rs = $schema->resultset('User');
my $course_rs = $schema->resultset('Course');
my $user_rs = $schema->resultset('User');
my $problem_set_rs = $schema->resultset('ProblemSet');

# test if the database tables are created.
try {
$course_rs->getCourses();
}
catch {
} catch {
$schema->deploy;
};

my %PERMISSIONS = (
0 => "student",
0 => "student",
10 => "instructor",
20 => "admin"
);
Expand All @@ -103,53 +100,52 @@ BEGIN
addUsers();
addProblemSets();


my $db_tables = {};

sub rebuild {
# find the course users
my @course_users = $user_rs->getUsers({course_name => $course_name});
my @course_users = $user_rs->getUsers({ course_name => $course_name });

## delete the users

for my $course_user (@course_users){
my @user_courses = $course_rs->getUserCourses({user_id => $course_user->{user_id}});
# if each user is only in one course, delete the global user
for my $course_user (@course_users) {
my @user_courses = $course_rs->getUserCourses({ user_id => $course_user->{user_id} });
# if each user is only in one course, delete the global user
if (scalar(@user_courses) == 1) {
$user_rs->deleteGlobalUser({user_id => $course_user->{user_id}});
$user_rs->deleteGlobalUser({ user_id => $course_user->{user_id} });
say "deleting the global user with username: $course_user->{username}" if $verbose;
} else {
$user_rs->deleteUser({course_name => $course_name, user_id => $course_user->{user_id}});
$user_rs->deleteUser({ course_name => $course_name, user_id => $course_user->{user_id} });
say "From course $course_name, deleting user $course_user->{username}" if $verbose;
}
}

## delete the problem sets

my @problem_sets = $problem_set_rs->getProblemSets({course_name => $course_name});
my @problem_sets = $problem_set_rs->getProblemSets({ course_name => $course_name });
for my $problem_set (@problem_sets) {
$problem_set_rs->deleteProblemSet({course_name => $course_name, set_id => $problem_set->{set_id}});
$problem_set_rs->deleteProblemSet({ course_name => $course_name, set_id => $problem_set->{set_id} });
say "deleting problem set: $problem_set->{set_name}" if $verbose;
}

# delete the course
my $course = $course_rs->find({course_name => $course_name});
$course->delete if $course;
my $course = $course_rs->find({ course_name => $course_name });
$course->delete if $course;
say "deleting the course $course_name" if $verbose;
return;
}

sub buildTables {
$db_tables = {};
for my $name (qw/user key password past_answer/){
for my $name (qw/user key password past_answer/) {
$db_tables->{$name} = $course_name . "_" . $name;
}
return;
}

sub addCourse {
say "adding course: $course_name" if $verbose;
$course_rs->addCourse({course_name => $course_name});
$course_rs->addCourse({ course_name => $course_name });
return;
}

Expand All @@ -158,74 +154,72 @@ sub addUsers {
my $perm_table = $course_name . "_permission";

my $sth = $dbh->prepare("SELECT * FROM `$user_table`");
$sth->execute();
my $ref = $sth->fetchall_arrayref({});
my @keys = keys %{$ref->[0]};
$sth->execute();
my $ref = $sth->fetchall_arrayref({});
my @keys = keys %{ $ref->[0] };

my @user_fields = grep {
$_ ne "login_params" && $_ ne "user_id" && $_ ne "email"
} $user_rs->result_source->columns;
my @user_fields =
grep { $_ ne "login_params" && $_ ne "user_id" && $_ ne "email" } $user_rs->result_source->columns;
my @course_user_param_fields = keys %$DB::Schema::Result::CourseUser::VALID_PARAMS;
my @course_user_fields = grep {
$_ !~ /\_id$/x && $_ ne "params"
} $schema->resultset("CourseUser")->result_source->columns;
my @course_user_fields =
grep { $_ !~ /\_id$/x && $_ ne "params" } $schema->resultset("CourseUser")->result_source->columns;

for my $r (@$ref) {
my $user_params = {
username => $r->{user_id},
email => $r->{email_address}
email => $r->{email_address}
};
foreach my $key (@user_fields){
foreach my $key (@user_fields) {
$user_params->{$key} = $r->{$key} if defined($r->{$key});
}
# dd $user_params;
my $user = $user_rs->find({username => $user_params->{username}});
my $user = $user_rs->find({ username => $user_params->{username} });
$user_rs->addGlobalUser($user_params) unless $user;
say "Adding user with username $r->{user_id}" if $verbose && ! defined($user);
say "Adding user with username $r->{user_id}" if $verbose && !defined($user);
my $course_user = {
username => $r->{user_id},
params => {}
params => {}
};
for my $key (@course_user_fields) {
$course_user->{$key} = $r->{$key} if defined($r->{$key});
}
foreach my $key (@course_user_param_fields){
foreach my $key (@course_user_param_fields) {
$course_user->{params}->{$key} = $r->{$key} if defined($r->{$key});
}
my $user_id = $r->{user_id};
my $sth2 = $dbh->prepare("SELECT * FROM `$perm_table` WHERE user_id = '$user_id';");
my $sth2 = $dbh->prepare("SELECT * FROM `$perm_table` WHERE user_id = '$user_id';");
$sth2->execute();
my $perm = $sth2->fetchrow_hashref();
$course_user->{role} = $PERMISSIONS{$perm->{permission}};
$user_rs->addUser({course_name => $course_name},$course_user);
$course_user->{role} = $PERMISSIONS{ $perm->{permission} };
$user_rs->addUser({ course_name => $course_name }, $course_user);
}
return;
}

sub addProblemSets {
my @hw_param_keys = keys %$DB::Schema::Result::ProblemSet::HWSet::VALID_PARAMS;
my $set_table = $course_name . "_set";
my $sth = $dbh->prepare("SELECT * FROM `$set_table`");
my $set_table = $course_name . "_set";
my $sth = $dbh->prepare("SELECT * FROM `$set_table`");
$sth->execute();
my $ref = $sth->fetchall_arrayref({});
my @keys = keys %{$ref->[0]};
my $ref = $sth->fetchall_arrayref({});
my @keys = keys %{ $ref->[0] };
# dd @keys;
for my $r (@$ref) {
my $set_params = {
set_name => $r->{set_id},
dates => {},
params => {},
dates => {},
params => {},
};
if ($r->{assignment_type} eq 'default') { # it's a homework set
if ($r->{assignment_type} eq 'default') { # it's a homework set
for my $key (@hw_param_keys) {
$set_params->{params}->{$key} = $r->{$key} if defined($r->{$key});
}
for my $key (@DB::Schema::Result::ProblemSet::HWSet::VALID_DATES) {
$set_params->{dates}->{$key} = $r->{$key .'_date'} if defined($r->{$key.'_date'});
$set_params->{dates}->{$key} = $r->{ $key . '_date' } if defined($r->{ $key . '_date' });
}
}

$problem_set_rs->addProblemSet({course_name => $course_name}, $set_params);
$problem_set_rs->addProblemSet({ course_name => $course_name }, $set_params);
say "Adding set with name: $set_params->{set_name}" if $verbose;
}
return;
Expand Down
Loading

0 comments on commit 6cf3c93

Please sign in to comment.