1. My WEE updater

This is helpful if you have made any mods to WEE which you may want to keep.

-- 
--   WEE source code updater 
--   modified by Kenneth Rhodes  
--   Provides an initial option to backup all files 
--   which need updating, before updating any files. 
--   If any file backup fails, the program can be aborted 
--   without updating any files. 
 
 
include std/console.e 
include std/net/http.e 
include std/io.e 
include std/get.e 
include std/filesys.e 
include std/hash.e 
 
puts(1, "=== WEE Source Code Updater ===\n") 
 
constant 
repo = "peberlein/WEE/", 
base_url = "http://cdn.rawgit.com/" & repo -- & "commit/filename" 
 
-- this needs to be .json since rawgit.com has a whitelist of extensions 
-- otherwise it will just redirect to https://raw.githubusercontent.com 
-- and http_get doesn't support https: protocol 
constant 
manifest = http_get("http://rawgit.com/"& repo &"master/manifest.json") 
 
procedure fail(sequence fmt, object args={}) 
    printf(1, fmt, args) 
    puts(1, "\nPress any key to exit, then try updating again.\n") 
    wait_key() 
    abort(1) 
end procedure 
 
if atom(manifest) or not equal(manifest[1][1][2], "200") then 
    display(manifest) 
    fail("Failed to download manifest.json\n") 
end if 
 
-- manifest format 
-- { 
--  {"pathname", hash, "commit-tag", platform-bits, platforms...} 
-- } 
 
sequence files, name, commit_tag 
files = value(manifest[2]) 
--display(files) 
if files[1] != 0 then 
    fail("Failed to parse manifest\n") 
end if 
files = files[2] 
 
ifdef BITS64 then 
    constant PLATFORM_BITS = 64 
elsedef 
    constant PLATFORM_BITS = 32 
end ifdef 
 
integer platform_bits 
sequence platforms, subdir 
object result, hashcode 
 
 
 
procedure update(integer backup = 0) 
 
    if backup then 
        puts(1,  "\n\nUpdate will overwrite any local changes to the source files.\n"& 
                     "Press any key to continue, or 'q' to quit.\n") 
        if wait_key() = 'q' then 
            abort(0) 
        end if 
    end if 
 
    puts(1, "\n") 
    for i = 1 to length(files) do 
        if length(files[i]) < 4 then 
            fail("Manifest file has invalid format.\n") 
        end if 
         
        name = files[i][1] 
        hashcode = files[i][2] 
        commit_tag = files[i][3] 
        platform_bits = files[i][4] 
        platforms = files[i][5..$] 
         
        if length(platforms) and not find(platform(), platforms) then 
            -- file not used on this platform 
        elsif platform_bits != 0 and platform_bits != PLATFORM_BITS then 
            -- file not compatible with 32/64-bit platform 
        elsif equal(hashcode, hash(read_file(name), HSIEH30)) then 
            if not backup then 
                -- file hash is ok 
                printf(1, "%s is up-to-date.\n", {name}) 
            end if 
        else 
            if backup then 
                --     backup files that need updating, overwrite existing backup file 
                if copy_file(name, filebase(name) & "-bak." & fileext(name), 1) then  
                    printf(1, "%s backed up as %s\n", {name, filebase(name) & "-bak." & fileext(name)}) 
                else 
                    printf(1, "\nFailed to backup file %s, continuing the update \n" & 
                    "will overwrite this file. Press 'q' to quit, or\n" &  
                    "press any other key to continue.\n", {name}) 
                    if wait_key() = 'q' then 
                        abort(1) 
                    end if 
                end if 
            else 
                printf(1, "Updating %s...\n", {name}) 
                result = http_get(base_url & commit_tag & "/" & name) 
                if atom(result) or not equal(result[1][1][2], "200") then 
                    display(result) 
                    fail("Failed to download %s\n", {name}) 
                elsif not equal(hashcode, hash(result[2], HSIEH30)) then 
                    fail("Failed to validate %s\n", {name}) 
                else 
                    subdir = dirname(name) 
                    if length(subdir) and atom(dir(subdir)) then 
                        printf(1, "Creating directory %s\n", {subdir}) 
                        create_directory(subdir) 
                    end if 
                    if write_file(name, result[2]) = -1 then 
                        printf(1, "Failed to write_file %s\n", {name}) 
                    else  
                        printf(1, "%s is up-to-date.\n", {name}) 
                    end if 
                end if     
            end if 
        end if 
    end for 
    if backup then 
       -- start update pass  
       update(0) 
    else 
        puts(1, "\n\nDone.  Press any key to exit.\n") 
        wait_key() 
    end if 
end procedure 
 
 
--  update(1)       -- backup files before updating 
--  update(0)       -- Run update without backing up files 
 
-- if you always want to backup files before updating 
-- comment out the following lines as well and then 
-- uncomment the line --  update(1) above. 
integer backup 
backup = prompt_number("\nBackup/Rename files which will be updated? 0 = no, 1 = yes ::  ", {0,1}) 
update(backup) 

If you are running Linux, and you have chosen to back up files you can view the differences between the old file and the new file by using diff and then copy your changes back into the newly updated file, if you wish:

diff -y --suppress-common-lines ~/wee/parser-bak.e ~/wee/parser.e 

For what it is worth in edx.ex the Windows compare command is something like:

 fc /T  parser-bak.e parser.e 

I think a "Mods" option in WEE kinda like the old edx.ex routine which would compare the current file to the file saved on disk would be pretty nice. I haven't been able to implement it WEE so far.

Thanks again to Pete Eberlein and Irv Mullins for WEE and EuGTK!

Regards, Ken Rhodes

new topic     » topic index » view message » categorize

2. Re: My WEE updater

K_D_R said...

This is helpful if you have made any mods to WEE which you may want to keep.

...

If you are running Linux, and you have chosen to back up files you can view the differences between the old file and the new file by using diff and then copy your changes back into the newly updated file, if you wish:

diff -y --suppress-common-lines ~/wee/parser-bak.e ~/wee/parser.e 

For what it is worth in edx.ex the Windows compare command is something like:

 fc /T  parser-bak.e parser.e 

I think a "Mods" option in WEE kinda like the old edx.ex routine which would compare the current file to the file saved on disk would be pretty nice. I haven't been able to implement it WEE so far.

Thanks again to Pete Eberlein and Irv Mullins for WEE and EuGTK!

Regards, Ken Rhodes

kdiff, cross platform visual diff is quite good for merging changed files (diff backend). though, it can get confused with large changes.

new topic     » goto parent     » topic index » view message » categorize

3. Re: My WEE updater

ne1uno said...
K_D_R said...

This is helpful if you have made any mods to WEE which you may want to keep.

...

If you are running Linux, and you have chosen to back up files you can view the differences between the old file and the new file by using diff and then copy your changes back into the newly updated file, if you wish:

diff -y --suppress-common-lines ~/wee/parser-bak.e ~/wee/parser.e 

For what it is worth in edx.ex the Windows compare command is something like:

 fc /T  parser-bak.e parser.e 

I think a "Mods" option in WEE kinda like the old edx.ex routine which would compare the current file to the file saved on disk would be pretty nice. I haven't been able to implement it WEE so far.

Thanks again to Pete Eberlein and Irv Mullins for WEE and EuGTK!

Regards, Ken Rhodes

kdiff, cross platform visual diff is quite good for merging changed files (diff backend). though, it can get confused with large changes.

Thanks for the kdiff3 info Ne1Uno. Can you give me any idea as to a likely "large change" threshold? I downloaded kdiff3. It looks very interesting.

I suppose I could add a could a "Would you like to view changes?" option using diff, or kdiff3, after an update is successfully written. And then of course a merge option could be presented.

Regards, Ken Rhodes

new topic     » goto parent     » topic index » view message » categorize

4. Re: My WEE updater

K_D_R said...
ne1uno said...
K_D_R said...

This is helpful if you have made any mods to WEE which you may want to keep.

...

If you are running Linux, and you have chosen to back up files you can view the differences between the old file and the new file by using diff and then copy your changes back into the newly updated file, if you wish:

diff -y --suppress-common-lines ~/wee/parser-bak.e ~/wee/parser.e 

For what it is worth in edx.ex the Windows compare command is something like:

 fc /T  parser-bak.e parser.e 

I think a "Mods" option in WEE kinda like the old edx.ex routine which would compare the current file to the file saved on disk would be pretty nice. I haven't been able to implement it WEE so far.

Thanks again to Pete Eberlein and Irv Mullins for WEE and EuGTK!

Regards, Ken Rhodes

kdiff, cross platform visual diff is quite good for merging changed files (diff backend). though, it can get confused with large changes.

Thanks for the kdiff3 info Ne1Uno. Can you give me any idea as to a likely "large change" threshold? I downloaded kdiff3. It looks very interesting.

I suppose I could add a could a "Would you like to view changes?" option using diff, or kdiff3, after an update is successfully written. And then of course a merge option could be presented.

Regards, Ken Rhodes

a diff view is sometimes all you really want.

I should have said, it can get confusing with large changes. diff will of course find a way to merge the two files and if it can't do it cleanly, will point out any conflicts.

kdiff is packaged with TortiseHG, (a GUI front end for mercurial) as a diff viewer and merge tool. with revision control, it's most likely the newer file that has the more important changes so an automatic merge can decide and/or highlight those changes to give a hint for user intervention.

there is no way to quantify the amount of change. computers have no way to decide which lines to save and which to toss. diff has no concept of program correctness or which program function or bug fix we want to preserve from and old file. maybe in the future, merge tools can take annotations in the source?

simple changes would be addling or removing a few variables in a list of variables. adding or removing whole functions or change in an initialization value. more complicated revision would highlight big chunks of changed lines with fewer options to pick and choose which lines to preserve. the more organized and smaller the change, the easier it gets. one of the reasons it's wise to commit changes of one issue at a time so it's more obvious what the changes are designed to do.

the version of kdiff included with TortiseHG is a few years old, you can get a newer version of kdiff from sourceforge, I imagine there are a few bug fixes since then. I also like WinMerge because I find a vertical side by side view of two files is a little easier to understand but kdiff can view/merge from three files at the same time. WinMerge hasn't been updated in awhile though there is forked version now too.

here are a few other diff tools http://alternativeto.net/software/kdiff3/

new topic     » goto parent     » topic index » view message » categorize

5. Re: My WEE updater

--   WEE source code updater 
--   modified by Kenneth Rhodes  
 
--      Provides an initial option to backup all files 
--      which need updating before updating any files. 
 
--      If any file backup fails, the program can be aborted 
--      without updating any files. 
 
--      Provides an option to view differences between 
--      the updated file and the backup file 
 
--      The Windows compare files command 
--      is taken from edx.ex and 
--      has not been tested on Windows 
--  
 
include std/console.e 
include std/net/http.e 
include std/io.e 
include std/get.e 
include std/filesys.e 
include std/hash.e 
 
puts(1, "=== WEE Source Code Updater ===\n") 
 
constant 
repo = "peberlein/WEE/", 
base_url = "http://cdn.rawgit.com/" & repo -- & "commit/filename" 
 
-- this needs to be .json since rawgit.com has a whitelist of extensions 
-- otherwise it will just redirect to https://raw.githubusercontent.com 
-- and http_get doesn't support https: protocol 
constant 
manifest = http_get("http://rawgit.com/"& repo &"master/manifest.json") 
 
procedure fail(sequence fmt, object args={}) 
    printf(1, fmt, args) 
    puts(1, "\nPress any key to exit, then try updating again.\n") 
    wait_key() 
    abort(1) 
end procedure 
 
if atom(manifest) or not equal(manifest[1][1][2], "200") then 
    display(manifest) 
    fail("Failed to download manifest.json\n") 
end if 
 
-- manifest format 
-- { 
--  {"pathname", hash, "commit-tag", platform-bits, platforms...} 
-- } 
 
sequence files, name, commit_tag 
files = value(manifest[2]) 
--display(files) 
if files[1] != 0 then 
    fail("Failed to parse manifest\n") 
end if 
files = files[2] 
 
ifdef BITS64 then 
    constant PLATFORM_BITS = 64 
elsedef 
    constant PLATFORM_BITS = 32 
end ifdef 
 
integer platform_bits 
sequence platforms, subdir 
object result, hashcode 
 
-- mods 
sequence BFILE = "" 
sequence S = {}                         --  for source files which have backed up 
sequence compare_cmd 
ifdef WINDOWS then 
    compare_cmd = "fc /T " 
elsifdef LINUX then 
    compare_cmd = "diff -y --suppress-common-lines " 
end ifdef 
--------- 
 
procedure update(integer backup = 0) 
     
    if not backup then 
        -- update pass 
        puts(1,  "\n\nUpdate will overwrite any local changes to the source files.\n"& 
        "Press any key to continue, or 'q' to quit.\n") 
        if wait_key() = 'q' then 
            abort(0) 
        end if 
    end if 
     
    puts(1, "\n") 
    for i = 1 to length(files) do 
         
        if length(files[i]) < 4 then 
            fail("Manifest file has invalid format.\n") 
        end if 
         
        name = files[i][1] 
        hashcode = files[i][2] 
        commit_tag = files[i][3] 
        platform_bits = files[i][4] 
        platforms = files[i][5..$] 
         
        if length(platforms) and not find(platform(), platforms) then 
            -- file not used on this platform 
        elsif platform_bits != 0 and platform_bits != PLATFORM_BITS then 
            -- file not compatible with 32/64-bit platform 
        elsif equal(hashcode, hash(read_file(name), HSIEH30)) then 
            if not backup then 
                -- file hash is ok 
                printf(1, "%s is up-to-date.\n", {name}) 
            end if 
        else             
            if backup then 
                if file_exists(name) then 
                    --     backup files that need updating, overwrite existing backup file 
                    if copy_file(name, filebase(name) & "-bak." & fileext(name), 1) then  
                        BFILE= filebase(name) & "-bak." & fileext(name) 
                        S = append(S, name) 
                        printf(1, "%s backed up as %s\n", {name, BFILE}) 
                    else 
                        printf(1, "\nFailed to backup file %s, continuing the update \n" & 
                        "will overwrite this file. Press 'q' to quit, or\n" &  
                        "press any other key to continue.\n", {name}) 
                        if wait_key() = 'q' then 
                            abort(1) 
                        end if 
                    end if 
                end if 
            else 
                -- update pass: backup = 0  
                printf(1, "Updating %s...\t", {name}) 
                result = http_get(base_url & commit_tag & "/" & name) 
                if atom(result) or not equal(result[1][1][2], "200") then 
                    display(result) 
                    fail("Failed to download %s\n", {name}) 
                elsif not equal(hashcode, hash(result[2], HSIEH30)) then 
                    fail("Failed to validate %s\n", {name}) 
                else 
                    subdir = dirname(name) 
                    if length(subdir) and atom(dir(subdir)) then 
                        printf(1, "Creating directory %s\n", {subdir}) 
                        create_directory(subdir) 
                    end if 
                    if write_file(name, result[2]) = -1 then 
                        printf(1, "Failed to write_file %s\n", {name}) 
                    else  
                        printf(1, "%s is up-to-date.\n", {name}) 
                        if find(name, S) then 
                            printf(1, "Would you like to view changes between %s and %s now?", {name, BFILE}) 
                            puts(1,"\nPress 'y' to view changes now. \nPress any other key to continue without view changes.\n") 
                            if wait_key()='y' then 
                                BFILE= filebase(name) & "-bak." & fileext(name) 
                                system(compare_cmd & name & " " & BFILE  & " | more", 0) 
                            end if 
                        end if 
                    end if 
                end if 
            end if     
        end if 
    end for 
    if backup then 
        --  backup run compete 
        --  go back for update pass 
        update(0) 
    else 
        puts(1, "\n\nDone.  Press any key to exit.\n") 
        wait_key() 
    end if 
end procedure 
 
update(1)       -- backup files before updating 
--  update(0)   -- functions like Pete's original updater.ex 
 
-- Allows user to choose the backup option.  
-- Make sure both calls to update above are commented out: 
-- integer backup 
-- backup = prompt_number("\nBackup files which will be updated? 0 = no, 1 = yes ::  ", {0,1}) 
-- update(backup) 
-- 
new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu