From 5ca487daa2182f9ff6aa40b1a05dc3db6d0fc84f Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Wed, 24 Mar 2021 16:41:09 -0400 Subject: Added concept of player identity. Started on the instructions processing loop. --- player/config.f90 | 3 ++ player/instructions.f90 | 87 ++++++++++++++++++++++++++++++++++++-- player/main.F90 | 109 ++++++++++++++++++++++++++++++++++++++++++++++++ player/main.f90 | 87 -------------------------------------- 4 files changed, 195 insertions(+), 91 deletions(-) create mode 100644 player/main.F90 delete mode 100644 player/main.f90 (limited to 'player') diff --git a/player/config.f90 b/player/config.f90 index 96c775c..c6c1b0c 100644 --- a/player/config.f90 +++ b/player/config.f90 @@ -4,5 +4,8 @@ implicit none character(len=:), pointer::working_directory character(len=:), pointer::logfile character(len=1024)::captain + character(len=36)::token + character(len=256)::identity + end module config diff --git a/player/instructions.f90 b/player/instructions.f90 index 8c671c4..ce28413 100644 --- a/player/instructions.f90 +++ b/player/instructions.f90 @@ -99,6 +99,25 @@ contains end function get_task_string + function get_task_logical(j, i, component, res) result(found) + use json_module + implicit none + + class(json_file)::j + integer, intent(in)::i + character(*), intent(in)::component + logical, intent(out)::res + logical::found + + character(len=64)::label + character(len=:), allocatable::json_string_value + + call task_component(i, component, label) + + call j%get(trim(label), res, found) + + end function get_task_logical + subroutine get_task_name(j, i, description) use json_module implicit none @@ -147,7 +166,9 @@ contains character(32)::operation character(256)::url character(256)::filename + character(256)::branch + logical::destructive logical, dimension(4)::found call get_task_operation(j, i, operation) @@ -176,23 +197,81 @@ contains else if(trim(operation) == "git_update") then capture_filename => generate_temporary_filename() - found(1) = get_task_string(j, i, "url", url) - found(2) = get_task_string(j, i, "filename", filename) + found(1) = get_task_string(j, i, "origin", url) + found(2) = get_task_string(j, i, "branch", branch) + found(3) = get_task_string(j, i, "directory", filename) + found(4) = get_task_logical(j, i, "destructive", destructive) + if(.not. found(4)) then + destructive = .false. + found(4) = .true. + end if + if(.not. all(found,1)) then success = .false. else - success = download(url, filename) + success = git_update(url, branch, filename, destructive, capture_filename) end if else if(trim(operation) == "shell") then + capture_filename => generate_temporary_filename() + found(1) = get_task_string(j, i, "command", url) + found(2) = get_task_string(j, i, "directory", filename) + + if(.not. all(found,1)) then + success = .false. + else + success = shell(command, directory, capture_filename) + end if else if(trim(operation) == "delete_tree") then - + found(1) = get_task_string(j, i, "directory", filename) + + if(.not. all(found,1)) then + success = .false. + else + success = delete_tree(command, directory, capture_filename) + end if end if end function perform_task + subroutine perform_tasks(j) + use json_module + implicit none + + class(json_file)::j + integer::task_count + integer::i + logical::res + + character(len=:), pointer::captured_filename + + task_count = get_task_count(j) + + do i = 1, task_count + + res = perform_task(j, i, captured_filename) + + if(associated(captured_filename)) then + if(res) then + + else + + exit + endif + else + if(res) then + + else + + exit + endif + end if + end do + + end subroutine perform_tasks + end module instructions \ No newline at end of file diff --git a/player/main.F90 b/player/main.F90 new file mode 100644 index 0000000..127a8f7 --- /dev/null +++ b/player/main.F90 @@ -0,0 +1,109 @@ +program player +use config +implicit none + + character(len=1024)::option + + integer::slen + integer::i + + identity = " " + + i = 1 + do while(i <= command_argument_count()) + call get_command_argument(i, option) + + if(option(1:1) /= "-") then + captain = option + + else if(trim(option) == "-h") then + call usage() + stop + + else if(trim(option) == "-w") then + i = i + 1 + call get_command_argument(i, length=slen) + allocate(character(len=slen) :: working_directory) + call get_command_argument(i, working_directory) + + else if(trim(option) == "-l") then + i = i + 1 + call get_command_argument(i, length=slen) + allocate(character(len=slen) :: logfile) + call get_command_argument(i, logfile) + + else if(trim(option) == "-i") then + i = i + 1 + call get_command_argument(i, identity) + + end if + + i = i + 1 + end do + + ! Assign working directory from command if not specified + if(.not. associated(working_directory)) then + call get_command_argument(0, length=slen) + allocate(character(len=slen) :: working_directory) + call get_command_argument(i, working_directory) + i = index(working_directory, "/", back=.true.) + if(i == 0) then + i = index(working_directory, "/", back=.true.) + endif + if(i == 0) then + Print *, "Could not determine working_directory" + stop + else + working_directory(i:slen) = ' ' + end if + end if + + ! Assign a temporary directory and file for a log file + ! NOTE: will fail on Windows + if(.not. associated(logfile)) then + allocate(character(len=256) :: logfile) + logfile = "/tmp/levitating.log" + end if + + ! Assign this computer an identity if not explicitly specified + if(len_trim(identity) == 0) then +#ifdef GNU + call hostnm(identity) +#else + Print *, "Could not determine host identity" + stop +#endif + end if + + ! Change directory to the working directory now + call chdir(working_directory) + + do while(.true.) + + + + end do + +contains + + subroutine usage() + implicit none + + character(len=256)::pname + + call get_command_argument(0, pname) + + Print *, "Usage: "//trim(pname)//" " + Print *, " " + Print *, "captain is the build control server" + Print *, " " + + Print *, "Options:" + Print *, " -h Display this help" + Print *, " -w Use dir as the working directory" + Print *, " -l Use log as the logfile" + Print *, " -i This players identity" + + end subroutine usage + +end program player \ No newline at end of file diff --git a/player/main.f90 b/player/main.f90 deleted file mode 100644 index cdf646e..0000000 --- a/player/main.f90 +++ /dev/null @@ -1,87 +0,0 @@ -program player -use config -implicit none - - character(len=1024)::option - - integer::slen - integer::i - - i = 1 - do while(i <= command_argument_count()) - call get_command_argument(i, option) - - if(option(1:1) /= "-") then - captain = option - - else if(trim(option) == "-h") then - call usage() - stop - - else if(trim(option) == "-w") then - i = i + 1 - call get_command_argument(i, length=slen) - allocate(character(len=slen) :: working_directory) - call get_command_argument(i, working_directory) - - else if(trim(option) == "-l") then - i = i + 1 - call get_command_argument(i, length=slen) - allocate(character(len=slen) :: logfile) - call get_command_argument(i, logfile) - - end if - - i = i + 1 - end do - - ! Assign working directory from command if not specified - if(.not. associated(working_directory)) then - call get_command_argument(0, length=slen) - allocate(character(len=slen) :: working_directory) - call get_command_argument(i, working_directory) - i = index(working_directory, "/", back=.true.) - if(i == 0) then - i = index(working_directory, "/", back=.true.) - endif - if(i == 0) then - Print *, "Could not determine working_directory" - stop - else - working_directory(i:slen) = ' ' - end if - end if - - ! Assign a temporary directory and file for a log file - ! NOTE: will fail on Windows - if(.not. associated(logfile)) then - allocate(character(len=256) :: logfile) - logfile = "/tmp/levitating.log" - end if - - ! Change directory to the working directory now - call chdir(working_directory) - - -contains - - subroutine usage() - implicit none - - character(len=256)::pname - - call get_command_argument(0, pname) - - Print *, "Usage: "//trim(pname)//" " - Print *, " " - Print *, "captain is the build control server" - Print *, " " - - Print *, "Options:" - Print *, " -h Display this help" - Print *, " -w Use dir as the working directory" - Print *, " -l Use log as the logfile" - - end subroutine usage - -end program player \ No newline at end of file -- cgit v1.2.3