+ Reply to Thread
Results 1 to 9 of 9

Thread: Automatic SVN updater (detects SVN folders automatically)

  1. #1
    Wire Amateur napalmstrike2007's Avatar
    Join Date
    Feb 2010
    Posts
    43
    Blog Entries
    1

    Default Automatic SVN updater (detects SVN folders automatically)

    NAPALMSTRIKE2007'S AUTOMATIC SVN UPDATER
    You have two choices:
    1. If you keep all your svn directories in your addons folder(this causes very long load up times. if you have enough hdd space consider using code in section B ) read section A.
    2. If you keep all your svn directories in an external folder, read section B. If you don't know how to create batch files, read section A, after learning how to create a batch file from section A, read section B.

    A ) CODE TO UPDATE ALL SVN'S


    It automatically detects all svn folders in its running directory so, you don't need to type in all of your svn folders into a text file to get them updated


    INSTRUCTIONS
    1. Download a command line SVN program. I am using SilkSVN Download Subversion Client | Slik SVN
    2. Open up notepad or any similar text editing software
    3. Copy and paste the code below into the notepad and save the file as svnupdate.bat
    4. Put the batch file you created in your garrysmod\garrysmod\addons folder (or the folder you keep your SVN folders in)
    5. IMPORTANT You should remove all white spaces from the names of your SVN folders
      (for example: "advanced duplicator"->"advanced_duplicator")
    6. Double click(just execute the batch file, you can use any way you like to) to the batch file. A DOS window will pop out. It should automatically detect all of your SVN folders and update all of them. When the process is finnished press any key to close the window.

    BATCH FILE CODE
    Code:
    @echo off
    echo STARTING THE UPDATE...
    FOR /F %%A IN ('dir /A:D /B') DO svn update %%A
    echo UPDATES COMPLETED
    pause 1
    B ) CODE TO UPDATE AND EXPORT SVN'S

    I combined the two functions (update and export) into one file. And it will NOT export if no updates were done(saves great amount of time). It will even try to repair broken svn's that don't get updated for some reason.
    It will copy ONLY updated/added files, not the whole folder to the addons folder(unlike the svn export command). This saves great amount of time.

    INSTRUCTIONS
    1. Browse to the folder you keep your svn files in. (this folder MUST BE in "C:\Program Files\Steam\SteamApps\USERNAME\garrysmod\garrysmod \")
    2. IMPORTANT You should remove all white spaces from the names of your SVN folders
      (for example: "advanced duplicator"->"advanced_duplicator")
    3. create launch.bat in your SVN folder
    Code:
    @echo off
    echo STARTING THE UPDATE...
    FOR /F %%A IN ('dir /A:D /B') do CALL upd.bat %%A 
    echo UPDATES COMPLETED
    pause 1
    4. create upd.bat in your SVN folder
    Code:
    @echo off
    set svnfolder=%cd%
    set someerror=0
    :begin
    echo CHECKING %1
    
    IF NOT EXIST ..\addons\%1\NUL GOTO exportit
    
    svn update "%1">revision.txt
    
    findstr /m "A" revision.txt>%TEMP%\NUL
    if %errorlevel%==0 GOTO found
    findstr /m "D" revision.txt>%TEMP%\NUL
    if %errorlevel%==0 GOTO found
    findstr /m "U" revision.txt>%TEMP%\NUL
    if %errorlevel%==0 GOTO found
    findstr /m "G" revision.txt>%TEMP%\NUL
    if %errorlevel%==0 GOTO found
    findstr /m "revision" revision.txt>%TEMP%\NUL
    if %errorlevel%==0 GOTO noupd
    set /a someerror=%someerror%+1
    IF %someerror%==1 echo ERROR: %1. TRYING TO FIX.
    if not %someerror%==1 echo ERROR COULD NOT BE FIXED.
    cd %1
    svn cleanup
    cd..
    IF %someerror%==1 GOTO begin
    GOTO end
    :noupd
    echo NO UPDATE NEEDED: %1.
    GOTO end
    
    :found
    FOR /F "tokens=1,2" %%i IN (revision.txt) DO (
    if %%i==A (
    IF "%%~xj"=="" (
    echo CREATING DIRECTORY %%j
    MD ..\addons\%%j>%TEMP%\NUL
    ) ELSE (
    echo ADDING %%j
    COPY %%j ..\addons\%%j /y>%TEMP%\NUL
    )
    )
    
    if %%i==U (
    echo UPDATING %%j
    COPY %%j ..\addons\%%j /y>%TEMP%\NUL
    )
    
    if %%i==D (
    IF "%%~xj"=="" (
    echo DELETING DIRECTORY %%j
    RMDIR /S /Q ..\addons\%%j>%TEMP%\NUL
    ) ELSE (
    echo DELETING %%j
    DEL /F /Q ..\addons\%%j>%TEMP%\NUL
    )
    )
    )
    goto end
    
    :exportit
    echo EXPORTING %1
    svn export %1 ..\addons\%1
    
    :end
    echo Done.
    echo.
    5. Execute launch.bat to detect & update & export automatically.

    If you like these codes remember that I love internet cookies
    CHANGE LOG:

    15.02.2011
    Old batch file was copying/deleting/updating anything with commands only appliable to files. So, if the update was including removal/creation of directories old batch file gave an error of filename not having a proper extension. With this update, this problem is solved.

    Removed revision.txt spam on screen.

    Made batch file more user friendly, now it is easier to understand what happened, is happening and will happen.

    Now the batch file completely exports svn's to addons folder if this is not done allready by the player ( for example your addons folder is completely empty, and you have an older wiremod revision in your svn folder. Old batch file would have given an error message complaining about wire folder not being found in addons. But after this update, batch file exports whole wire svn folder to the addons in that case.)
    Last edited by napalmstrike2007; 02-15-2011 at 12:19 PM. Reason: Updated code

  2. #2
    aka Colonel Never Online Colonel Thirty Two's Avatar
    Join Date
    Oct 2009
    Posts
    2,683
    Blog Entries
    5

    Default Re: Automatic SVN updater (detects SVN folders automatically)

    Hooray for 5 minute scripts. It only works if you have the official SVN software installed, and most people here use tortisesvn, which I don't think adds SVN binaries to the PATH env. variable.

  3. #3
    Wire Amateur napalmstrike2007's Avatar
    Join Date
    Feb 2010
    Posts
    43
    Blog Entries
    1

    Default Re: Automatic SVN updater (detects SVN folders automatically)

    I combined the two functions (update and export) into one file. And it will NOT export if no updates were done(saves great amount of time). It will even try to repair broken svn's that don't get updated for some reason.
    EDIT:
    Now it will copy ONLY updated/added files, not the whole folder to the addons folder(unlike the svn export command). This saves great amount of time.

    LOOK AT THE FIRST POST FOR CHANGES/UPDATES.
    Last edited by napalmstrike2007; 07-22-2010 at 01:19 PM. Reason: Updated code

  4. #4
    Wire Sofaking nescalona's Avatar
    Join Date
    Apr 2007
    Location
    Shoreline, Washington
    Posts
    1,299

    Default Re: Automatic SVN updater (detects SVN folders automatically)

    Would it be feasible to add functionality so only the updated files are exported? Iff so, I would use this.

  5. #5
    Wire Amateur napalmstrike2007's Avatar
    Join Date
    Feb 2010
    Posts
    43
    Blog Entries
    1

    Default Re: Automatic SVN updater (detects SVN folders automatically)

    yes actually when I coded this, I wanted to make it like that but I am still trying to figure out a way to manage that. The svn update command should have some return values that I don't know how to retrieve yet. Using those return values I might be able to make a check if the files were really updated or weren't. But even like this it is a very useful tool I think. especially the one in my second post works great for me. sure it takes too long especially because of phx and spacebuild model pack, but it just works fine.

  6. #6
    Wire Amateur napalmstrike2007's Avatar
    Join Date
    Feb 2010
    Posts
    43
    Blog Entries
    1

    Default Re: Automatic SVN updater (detects SVN folders automatically)

    Quote Originally Posted by nescalona View Post
    Would it be feasible to add functionality so only the updated files are exported? Iff so, I would use this.
    Look at my second post please. I updated it. now it shall ONLY export when svns were actually updated. It even tries to repair broken svn's.
    I tested it on:
    1) detecting broken svn's and repairing it, stopping repair attempts if it is useless (so it wont get stuck on a file trying to repair it. if it is useless, it will pass to the other svn)
    2) detecting if a svn is up to date and doesnt need an export.
    I couldn't test it with detecting if something got updated because all my svns were allready up to date (but it detects if something DOESNT get updated, so the reverse should work too )

  7. #7
    Wire Sofaking nescalona's Avatar
    Join Date
    Apr 2007
    Location
    Shoreline, Washington
    Posts
    1,299

    Default Re: Automatic SVN updater (detects SVN folders automatically)

    What I meant was, only the updated files are exported (not the entire updated addons).

    EDIT: here's an idea. People have SVN Addons folders and export instead of just updating directly to addons folder, because Gmod takes ages to look through all the .svn folders otherwise. Disadvantage is, exporting can take a while even if only one file has changed.

    I don't know batch scripting, so I wouldn't know where to start here, but how about a script that moves all .svn folders from an external folder (where the last run of the script put them) to the addons folder, updates all the addons in the addons folder, and then moves all the .svn folders back to the external folder.
    Last edited by nescalona; 07-21-2010 at 03:38 PM.

  8. #8
    Wire Amateur napalmstrike2007's Avatar
    Join Date
    Feb 2010
    Posts
    43
    Blog Entries
    1

    Default Re: Automatic SVN updater (detects SVN folders automatically)

    I MANAGED TO DO IT! IT WORKS PERFECTLY. I ALSO TESTED IT AND IT WORKS PRETTY WELL.

    the launch.bat remains the same:
    Code:
    @echo off
    echo STARTING THE UPDATE...
    FOR /F %%A IN ('dir /A:D /B') do CALL upd.bat %%A 
    echo UPDATES COMPLETED
    but the upd.bat must be changed:
    Code:
    @echo off
    set svnfolder=%cd%
    set someerror=0
    :begin
    
    svn update "%1">revision.txt
    
    findstr /m "A" revision.txt
    if %errorlevel%==0 GOTO found
    findstr /m "D" revision.txt
    if %errorlevel%==0 GOTO found
    findstr /m "U" revision.txt
    if %errorlevel%==0 GOTO found
    findstr /m "G" revision.txt
    if %errorlevel%==0 GOTO found
    findstr /m "Revision" revision.txt
    if %errorlevel%==0 GOTO noupd
    set /a someerror=%someerror%+1
    IF %someerror%==1 echo ERROR: %1. TRYING TO FIX.
    if %someerror%==1 GOTO begin
    if not %someerror%==1 echo ERROR COULD NOT BE FIXED.
    
    cd %1
    svn cleanup
    cd..
    GOTO end
    :noupd
    echo NO UPDATE NEEDED: %1.
    GOTO end
    
    :found
    FOR /F "tokens=1,2" %%i IN (revision.txt) DO (
    if %%i==A (
    IF "%%~xj"=="" (
    echo CREATING DIRECTORY %%j
    MD ..\addons\%%j
    ) ELSE (
    echo ADDING %%j
    COPY %%j ..\addons\%%j /y
    )
    )
    
    if %%i==U (
    echo UPDATING %%j
    COPY %%j ..\addons\%%j /y
    )
    
    if %%i==D (
    echo DELETING %%j
    DEL ..\addons\%%j
    )
    )
    echo UPDATED AND EXPORTED: %1
    :end
    NOW IT WILL ONLY UPDATE CHANGED FILES NOT WHOLE FOLDERS
    Last edited by napalmstrike2007; 07-22-2010 at 12:14 AM.

  9. #9
    Wire Amateur napalmstrike2007's Avatar
    Join Date
    Feb 2010
    Posts
    43
    Blog Entries
    1

    Default Re: Automatic SVN updater (detects SVN folders automatically)

    Updated the batch file. See the first post. [ 15.02.2011 ]

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots