Skip to content

Commit

Permalink
Doccano updated implementation (#1031)
Browse files Browse the repository at this point in the history
* Updating the doccano implentation scripts

* Updating labeling-text-using-doccano guide

* More udpate to labeling-text-using-doccano guide

* removing stray cells from labeling-text-using-doccano guide

* adding option to remove doccano db while uninstalling

* Sending the unnecessary logs to current user's temp directory

* Updating guide to use v1.2.4 doccano image

* Updating guide to use v1.2.4 doccano image for linux

* Removing double quotes from messages.

* Setting doccano version to 1.2.4 for linux
  • Loading branch information
akhilnegi authored Jul 1, 2021
1 parent 6b3bb49 commit 87b1a27
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 154 deletions.
46 changes: 24 additions & 22 deletions guide/14-deep-learning/labeling-text-using-doccano.ipynb

Large diffs are not rendered by default.

19 changes: 0 additions & 19 deletions misc/tools/doccano_deployment/README.md

This file was deleted.

22 changes: 0 additions & 22 deletions misc/tools/doccano_deployment/annotation.html

This file was deleted.

8 changes: 8 additions & 0 deletions misc/tools/doccano_deployment/elevated_prompt_check.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Write-Host "Checking for elevated permissions..."
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Output 0
}
else {
Write-Output 1
}
9 changes: 9 additions & 0 deletions misc/tools/doccano_deployment/get_username.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$username = Read-Host "Enter username"

if($username.length -lt 6 )
{
Write-Output 0
}
else {
Write-Output $username
}
20 changes: 20 additions & 0 deletions misc/tools/doccano_deployment/getpwd.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
$password1 = Read-Host "Enter password" -AsSecureString
$password1 = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($password1)
$password1 = [Runtime.InteropServices.Marshal]::PtrToStringAuto($password1)

$password2 = Read-Host "Re-enter password" -AsSecureString
$password2 = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($password2)
$password2 = [Runtime.InteropServices.Marshal]::PtrToStringAuto($password2)

if($password1 -eq $password2){
if($password2.length -lt 6 ){
Write-Output 1
}
else {
Write-Output $password1
}

}
else{
Write-Output 0
}
118 changes: 72 additions & 46 deletions misc/tools/doccano_deployment/install.bat
Original file line number Diff line number Diff line change
@@ -1,65 +1,91 @@
@echo off
SET DIR=%~dp0%

SET DIR_=%~dp0
for /f "delims=" %%i in ('powershell -file %DIR_%elevated_prompt_check.ps1') do set admin=%%i

if %admin%==0 (
powershell start '%~f0' ' %*' -verb runas 2>nul && exit /b
echo Need to run this installation as an administrator
pause
exit)

cd /
mkdir doccano
cd c:/doccano
mkdir logs
cd %DIR%
cd %DIR_%
set hr=%time:~0,2%
set hr=%hr: =0%
set LOGFILE=C:\doccano\logs\install_log_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%hr%%time:~3,2%%time:~6,2%.txt

call :LOG1 2> %LOGFILE%

python "%DIR%doccano\app\manage.py" migrate
python "%DIR%doccano\app\manage.py" createsuperuser
echo "-----Installing chocolatey-----"> %LOGFILE%
call :install_chocolatey 2>> %LOGFILE%
choco feature enable -n allowGlobalConfirmation
echo "-----Installing dependencies-----">> %LOGFILE%
call :install_deps 2>> %LOGFILE%
echo "-----Setting doccano username-----">> %LOGFILE%
call :getusrname 2>> %LOGFILE%
echo "-----Setting doccano password-----">> %LOGFILE%
call :getpwd 2>> %LOGFILE%
echo "-----Setting up doccano service-----">> %LOGFILE%
@REM GOTO :end
call :setup_doccano_service 2>> %LOGFILE%
echo Doccano successfully installed
echo Starting doccano at http://localhost:8000 ......
timeout 20 > %temp%\null
start explorer http://localhost:8000
exit /B

call :LOG2 2>> %LOGFILE%
:install_chocolatey

::install chocolatey
echo Installing chocolatey...
%systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& '%DIR_%install_chocolatey.ps1' %*" -Verb RunAs
call refresh_path.bat
echo Installing python...
::install python
%systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& '%DIR_%install_deps.ps1' %*" -Verb RunAs
call refresh_path.bat
exit /B

:LOG2

call "C:/doccano/venv/scripts/deactivate"
cd "%DIR%doccano\app\server\static"
call npm install
cd "%DIR%"
copy "%DIR%annotation.html" "%DIR%doccano\app\server\templates" /Y
net stop doccano /Y
:install_deps
pip install virtualenv
virtualenv "C:/doccano/venv"
call C:/doccano/venv/scripts/activate
pip install doccano==1.2.4
cd "%DIR_%"
net stop doccano /Y >%temp%\null
nssm remove doccano confirm
nssm install doccano %DIR%run_doccano.bat %DIR%
nssm start doccano
net stop start_webpack /Y
nssm remove start_webpack confirm
nssm install start_webpack %DIR%start_webpack.bat %DIR%
nssm start start_webpack
pause
@REM set /p doccano_username="Enter username:"
@REM set /p doccano_password="Enter Password:"
@REM :getpwd
exit /B

:LOG1

::install chocolatey
echo installing chocolatey
%systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& '%DIR%install_chocolatey.ps1' %*" -Verb RunAs
call refresh_path.bat
echo installing git,node and python
::install git,node and python
%systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& '%DIR%install_deps.ps1' %*" -Verb RunAs
SET PATH=%PATH%;C:\Program Files\Git\bin;C:\Program Files\nodejs

:setup_doccano_service
call refresh_path.bat
pip install virtualenv
virtualenv "C:/doccano/venv"
call C:/doccano/venv/scripts/activate
python -m pip install --force-reinstall pip
call git clone https://github.com/doccano/doccano.git doccano
cd "%DIR%doccano"
call git checkout bdba2961bf7942eb529a1591a7499b5d15af73bf
git config --global url."https://".insteadOf git://
pip install -r "%DIR%doccano\requirements.txt"
cd "%DIR%doccano\frontend"
SET PATH=%PATH%;%systemroot%\System32\WindowsPowerShell\v1.0\
call npm install --global windows-build-tools --vs2015
SET NODE_GYP_FORCE_PYTHON=%userprofile%\.windows-build-tools\python27\python.exe
call npm install
call npm run build
cd "%DIR%doccano\app"
nssm install doccano %DIR_%run_doccano.bat "%doccano_username% %doccano_password%"
nssm start doccano > %temp%\null
call C:/doccano/venv/scripts/deactivate
exit /B

:getpwd

for /f "delims=" %%i in ('powershell -file getpwd.ps1') do set doccano_password=%%i
if /I %doccano_password%==0 echo Passwords don't match && GOTO :getpwd
if /I %doccano_password%==1 echo "Password does not meet length(>5) requirement" && GOTO :getpwd
exit /B


:getusrname
for /f "delims=" %%i in ('powershell -file get_username.ps1') do set doccano_username=%%i
if /I %doccano_username%==0 echo Username does not meet length(^>5) requirement && GOTO :getusrname
exit /B


:end



36 changes: 18 additions & 18 deletions misc/tools/doccano_deployment/install_deps.ps1
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@

$git_installed = cver all -lo | Select-string -Pattern "^git"
if ($git_installed.length -eq 0 ) {
choco install -y git.install
}
else {
echo "Skipping git installation"
}
$python_installed = cver all -lo | Select-string -Pattern "^python"
# $git_installed = cver all -lo | Select-string -Pattern "^git"
# if ($git_installed.length -eq 0 ) {
# choco install -y git.install
# }
# else {
# echo "Skipping git installation"
# }
$python_installed = cver all -lo | Select-string -Pattern "python3 3.9.4"
if ($python_installed.length -eq 0 ) {
choco install -y python --version=3.7.2
choco install -y python3 --version=3.9.4
}
else {
echo "Skipping python installation"
}
$node_installed = cver all -lo | Select-string -Pattern "^nodejs"
if ($node_installed.length -eq 0 ) {
choco install -y nodejs --version=13.11.0
}
else {
echo "Skipping node installation"
}
# $node_installed = cver all -lo | Select-string -Pattern "^nodejs"
# if ($node_installed.length -eq 0 ) {
# choco install -y nodejs --version=13.11.0
# }
# else {
# echo "Skipping node installation"
# }
$nssm_installed = cver all -lo | Select-string -Pattern "^nssm"
if ($nssm_installed.length -eq 0 ) {
choco install -y nssm
}
else {
echo "Skipping nssm installation"
}
echo "Skipping nssm installation"
}
3 changes: 2 additions & 1 deletion misc/tools/doccano_deployment/refresh_path.bat
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ for /f "tokens=3*" %%A in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Ses
for /f "tokens=3*" %%A in ('reg query "HKCU\Environment" /v Path') do set userpath=%%A%%B

:: Set Refreshed Path
set PATH=%PATH%;%userpath%;%syspath%
set PATH=%path%;%syspath%;%userpath%
::;%syspath%
12 changes: 7 additions & 5 deletions misc/tools/doccano_deployment/run_doccano.bat
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
@echo off

SET DIR=%~dp0%
cd %DIR%doccano/app
SET DIR_=%~dp0
call "c:/doccano/venv/scripts/activate"
python manage.py runserver
cd %DIR%
cd \doccano
doccano --username %1 --password %2
cd %DIR_%



6 changes: 0 additions & 6 deletions misc/tools/doccano_deployment/start_webpack.bat

This file was deleted.

35 changes: 24 additions & 11 deletions misc/tools/doccano_deployment/uninstall.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
@echo off
SET DIR_=%~dp0
for /f "delims=" %%i in ('powershell -file %DIR_%elevated_prompt_check.ps1') do set admin=%%i

if %admin%==0 (
powershell start '%~f0' ' %*' -verb runas 2>nul && exit /b
echo Need to run this uninstaller as an administrator
pause
exit)
set hr=%time:~0,2%
set hr=%hr: =0%
set LOGFILE=C:\doccano\logs\uninstall_log_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%hr%%time:~3,2%%time:~6,2%.txt
Expand All @@ -7,18 +15,23 @@ exit /B

:LOG

SET DIR=%~dp0%
net stop doccano /Y
nssm remove doccano confirm
net stop start_webpack /Y
nssm remove start_webpack confirm
::uninstall doccano
%systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& '%DIR%uninstall.ps1' %*" -Verb RunAs
%systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& '%DIR%uninstall_chocolatey.ps1' %*" -Verb RunAs
cd %DIR%
del /f /s /q %DIR%doccano 1>nul
call rmdir /Q /S %DIR%doccano
del /f /s /q C:/doccano/venv 1>nul
call refresh_path.bat
%systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& '%DIR_%uninstall.ps1' %*" -Verb RunAs
%systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& '%DIR_%uninstall_chocolatey.ps1' %*" -Verb RunAs
cd %DIR_%
call rmdir /Q /S "C:/doccano/venv"
echo "Uninstalled"
pause

:delete_files
set /p del_files=Delete Doccano files?(y/n):

IF %del_files%==y del "C:\doccano\doccano.db" && GOTO :end

IF %del_files%==n GOTO :end
IF NOT %del_files%==n IF NOT %del_files%==y echo Please provide a valid(y/n) input. && GOTO :delete_files


:end
echo Doccano has been uninstalled.
8 changes: 4 additions & 4 deletions misc/tools/doccano_deployment/uninstall.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Set-ExecutionPolicy Bypass -Scope Process -Force
"y"|choco uninstall git.install -n --skipautouninstaller
"y"|choco uninstall python --version=3.7.2 -n --skipautouninstaller
"y"|choco uninstall nodejs --version=13.11.0 -n --skipautouninstaller
"y"|choco uninstall nssm -n --skipautouninstaller
# choco uninstall python --version=3.9.4 -y
choco uninstall python3 --version=3.9.4 -y
"y"|choco uninstall nssm -n --skipautouninstaller

0 comments on commit 87b1a27

Please sign in to comment.