Commit 24ba9dcb by Szeberényi Imre

Initial version from CIRLCE project

parents
Desktop client for CIRCLE, providing single click connection to the VMs further enhancing the ease of use.
Python based application using third party softwares.
Tested and made for:
- Debian based Linux systems. [RDP, SSH - built in console]
- Windows Vista 32/64 or newer. [RDP - windows built in, SSH - Putty]
To install the client Root rights are necessary.
The installation guide can be found at the CIRCLE running site.
The newest installation files are located at: https://circlecloud.org/client/download/
To install simply run the downloaded executable file.
;NSIS Modern User Interface
;Multilingual Cloud Installer Script
;Written by Cs�k Tam�s and Bel�kovics �d�m
;--------------------------------
; MultiUser install setup
!define MULTIUSER_EXECUTIONLEVEL Highest
!define MULTIUSER_MUI
!define MULTIUSER_INSTALLMODE_COMMANDLINE
;--------------------------------
;Include Modules
!include "MultiUser.nsh"
!include "MUI2.nsh"
!include "LogicLib.nsh"
!include "FileFunc.nsh"
!include "x64.nsh"
;--------------------------------
;Defining new constants
!define Company "CIRCLE Cloud"
!define AppName "Client"
!define AppUrlName "BME CIRCLE"
!define AppUrl "http://cloud.bme.hu/"
!define AppUninstaller "Uninstall.exe"
!define IconName "cloud"
!define Show_output "True"
!define DefaulLocation "$PROGRAMFILES\CIRCLE"
!define LowestSupportedPythonVersion "6"
!define HighestSupportedPythonVersion "7"
!define LogInformationTime 2000
;String manipulations
!define Explode "!insertmacro Explode"
!define StrCase2 "!insertmacro StrCase2"
!define StrTrimNewLines2 "!insertmacro StrTrimNewLines2"
;--------------------------------
;General
!macro Explode Length Separator String
Push '${Separator}'
Push '${String}'
Call Explode
Pop '${Length}'
!macroend
!macro StrCase2 ResultVar String Case
Push "${String}"
Push "${Case}"
Call StrCase2
Pop "${ResultVar}"
!macroend
!macro StrTrimNewLines2 ResultVar String
Push "${String}"
Call StrTrimNewLines2
Pop "${ResultVar}"
!macroend
;Properly display all languages (Installer will not work on Windows 95, 98 or ME!)
; Unicode true
;Name and file
Name "${Company} ${AppName}"
OutFile "..\..\dist\CIRCLE_Client_Setup.exe"
;Disable to skip files from installing
AllowSkipFiles off
;If there are existing files stored try to overwrite it
SetOverwrite try
;Default installation folder
InstallDir "${DefaulLocation}"
;Get installation folder from registry if available
InstallDirRegKey HKLM "Software\${Company} ${AppName}" "install_directory"
;Request application privileges
RequestExecutionLevel admin
;--------------------------------
;Interface Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${IconName}.ico"
!define MUI_UNICON "${IconName}.ico"
;Show all languages, despite user's codepage
!define MUI_LANGDLL_ALLLANGUAGES
;--------------------------------
;Language Selection Dialog Settings
;Remember the installer language
!define MUI_LANGDLL_REGISTRY_ROOT "HKLM"
!define MUI_LANGDLL_REGISTRY_KEY "Software\${Company} ${AppName}"
!define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
;--------------------------------
;Pages
!insertmacro MUI_PAGE_LICENSE "gpl-3.0.txt"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MULTIUSER_PAGE_INSTALLMODE
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
;Done fuction to launch install.bat
!define MUI_PAGE_CUSTOMFUNCTION_PRE Done
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English" ;first language is the default language
!insertmacro MUI_LANGUAGE "Hungarian"
;--------------------------------
;Reserve Files
!insertmacro MUI_RESERVEFILE_LANGDLL
;--------------------------------
;Language strings
;SectionGroup names
LangString NAME_Install ${LANG_ENGLISH} "Components"
LangString NAME_Install ${LANG_HUNGARIAN} "Komponensek"
LangString NAME_Functions ${LANG_ENGLISH} "Functions"
LangString NAME_Functions ${LANG_HUNGARIAN} "Funkci�k"
;CIRCLE Client (SecInstall)
;NAME
LangString NAME_SecInstall ${LANG_ENGLISH} "CIRCLE Client"
LangString NAME_SecInstall ${LANG_HUNGARIAN} "CIRCLE Kliens"
;DESC
LangString DESC_SecInstall ${LANG_ENGLISH} "Install the core of the CIRCLE Client.$\r$\n\
Used for [RDP / SSH] type of connections.$\r$\n\
Automates all installed, third party connection tools."
LangString DESC_SecInstall ${LANG_HUNGARIAN} "A CIRCLE Kliens alapj�nak telep�t�se.$\r$\n\
[RDP / SSH] f�le kapcsolatokhoz haszn�lt.$\r$\n\
Automatiz�lja az install�lt, harmadik f�lt�l sz�rmaz� szoftverek haszn�lat�t."
;Python search (PythonLookup)
;NAME
LangString NAME_PythonLookup ${LANG_ENGLISH} "Search Python"
LangString NAME_PythonLookup ${LANG_HUNGARIAN} "Python keres�s"
;DESC
LangString DESC_PythonLookup ${LANG_ENGLISH} "Use ONLY if necessary!$\r$\n\
Search the filesystem for Python installation. Usefull when Python was installed without accessing registry before.$\r$\n\
Installation will take more time."
LangString DESC_PythonLookup ${LANG_HUNGARIAN} "Csak sz�ks�g eset�n!$\r$\n\
A f�jlrendszer keres�se Python ut�n. Hasznos, ha a Python-t Registry n�lk�li opci�val lett telep�tve kor�bban.$\r$\n\
A telep�t�st jelent�sen lelass�tja."
;STATUS
LangString STATUS_PythonSearch ${LANG_ENGLISH} "Searching for Python. This could take some time. Looking at drive:"
LangString STATUS_PythonSearch ${LANG_HUNGARIAN} "Python keres�se a f�jlrendszerben. Ez eltarthat egy darabig. Keres�s alapja:"
LangString STATUS_PythonFound ${LANG_ENGLISH} "Python found at "
LangString STATUS_PythonFound ${LANG_HUNGARIAN} "Python megtal�lva az al�bbi k�nyvt�rban: "
LangString STATUS_PythonVersionSearch ${LANG_ENGLISH} "Determining Python version."
LangString STATUS_PythonVersionSearch ${LANG_HUNGARIAN} "Telep�tett Python verzi� kider�t�se."
LangString STATUS_PythonVersionFound ${LANG_ENGLISH} "Installed Python version is:"
LangString STATUS_PythonVersionFound ${LANG_HUNGARIAN} "A telep�tett Python verzi�ja:"
LangString STATUS_PythonArchitectSearch ${LANG_ENGLISH} "Deteremining installed Python mode (32bit or 64bit)."
LangString STATUS_PythonArchitectSearch ${LANG_HUNGARIAN} "Install�lt Python futtat�si m�dj�nak kider�t�se (32bit vagy 64bit)."
LangString STATUS_PythonArchitectFound ${LANG_ENGLISH} "Installed Python mode is:"
LangString STATUS_PythonArchitectFound ${LANG_HUNGARIAN} "A telep�tett Python m�dja:"
LangString STATUS_PythonNotSupported ${LANG_ENGLISH} "The installed Python version is not supported!$\r$\n\
To procede please uninstall Python first."
LangString STATUS_PythonNotSupported ${LANG_HUNGARIAN} "A feltelep�tett Python verzi�ja nem t�mogatott!$\r$\n\
A sikeres telep�t�shez el kell el�bb t�vol�tania a Python-t."
LangString STATUS_PythonNotFound ${LANG_ENGLISH} "Python not found in the filesystem!"
LangString STATUS_PythonNotFound ${LANG_HUNGARIAN}} "Nem tal�lhat� Python a f�jlrendszerben!"
LangString STATUS_PythonArchitectNotFound ${LANG_ENGLISH} "Could NOT determine the installed Python mode!$\r$\n\
To procede please uninstall Python first."
LangString STATUS_PythonArchitectNotFound ${LANG_HUNGARIAN} "Nem siker�lt kider�teni a feltelep�tett Python m�dj�t!$\r$\n\
A sikeres telep�t�shez el kell el�bb t�vol�tania a Python-t."
;Setup
LangString STATUS_ExecutingScript ${LANG_ENGLISH} "Executing setup script. Log files can be found at:"
LangString STATUS_ExecutingScript ${LANG_HUNGARIAN} "Install�ci�s script futtat�sa. A folyamat napl�ja:"
;--------------------------------
;Global variables
Var /GLOBAL python_location
Var /GLOBAL python_version
Var /GLOBAL python_architect
Var /GLOBAL found_python
Var /GLOBAL append
Var /GLOBAL running_directory
;--------------------------------
;Installer Sections
SectionGroup /e '!$(NAME_Install)'
Section $(NAME_SecInstall) SecInstall
SectionIn RO
SetOutPath "$INSTDIR"
;ADD OWN FILES HERE----------------------------------------
File /r installer
File /r uninstaller
;Initialize Running Directory
ClearErrors
ReadRegStr $running_directory HKCU "Software\${Company} ${AppName}" "running_directory"
${If} ${Errors}
StrCpy $running_directory ${DefaulLocation}
ClearErrors
${EndIf}
;Store installation folder
WriteRegStr HKLM "Software\${Company} ${AppName}" "install_directory" $INSTDIR
WriteRegStr HKCU "Software\${Company} ${AppName}" "running_directory" $running_directory
;Create uninstaller
WriteUninstaller "$INSTDIR\${AppUninstaller}"
;Creating ShortCuts
CreateDirectory '$SMPROGRAMS\${Company}\${AppName}'
StrCmp $LANGUAGE ${LANG_HUNGARIAN} 0 +3
WriteINIStr "$SMPROGRAMS\${Company}\L�togasd meg a ${AppUrlName}-t.url" "InternetShortcut" "URL" "${AppUrl}"
Goto +2
WriteINIStr "$SMPROGRAMS\${Company}\Visit the ${AppUrlName}.url" "InternetShortcut" "URL" "${AppUrl}"
CreateShortCut '$SMPROGRAMS\${Company}\${AppName}\Uninstall ${AppName}.lnk' '$INSTDIR\${AppUninstaller}' "" '$INSTDIR\${AppUninstaller}' 0
SectionEnd
SectionGroupEnd
SectionGroup /e $(NAME_Functions)
Section /o $(NAME_PythonLookup) PythonLookup
StrCpy $found_python "false"
${GetDrives} "HDD" "PythonSearch"
StrCmp $found_python "true" appendExec
Goto LookupEnd
appendExec:
StrCpy $append ' $python_architect $python_version "$python_location\"'
LookupEnd:
SectionEnd
SectionGroupEnd
;--------------------------------
;Installer Functions
Function .onInit
${If} ${RunningX64}
${DisableX64FSRedirection}
SetRegView 64
${EndIf}
ClearErrors
ReadRegStr $INSTDIR HKLM "Software\${Company} ${AppName}" "install_directory"
${If} ${Errors}
StrCpy $INSTDIR ${DefaulLocation}
ClearErrors
${EndIf}
!insertmacro MUI_LANGDLL_DISPLAY
!insertmacro MULTIUSER_INIT
FunctionEnd
Function PythonSearch
StrCpy $python_location ""
DetailPrint '$(STATUS_PythonSearch) "$9"'
Push "easy_install.exe" ;File or folder to search. Wildcards are supported.
Push $9 ;Path where to search for the file or folder.
Push $0
GetFunctionAddress $0 "CallbackFunction" ;Custom callback function name
Exch $0
Push "1" ;Include subfolders in search. (0 = false, 1 = true)
Push "0" ;Enter subfolders with ".". This only works if "Include subfolders in search" is set to 1 (true). (0 = false, 1 = true)
Call SearchFile
StrCmp $python_location "" PythonNotFound
Var /GLOBAL explodeChar
StrCpy $explodeChar ' '
DetailPrint $(STATUS_PythonVersionSearch)
nsExec::ExecToStack '"$python_location\python.exe" -V'
Pop $0
${If} $0 = 0
Pop $0
${StrTrimNewLines2} $python_version $0
loop:
${Explode} $0 $explodeChar $python_version
${For} $1 1 $0
Pop $2
StrCmp $explodeChar ' ' CutPython
StrCmp $1 "2" secondNumber
StrCmp $2 "2" versionCount
wrongVersion:
MessageBox MB_OK $(STATUS_PythonNotSupported)
Abort $(STATUS_PythonNotSupported)
Goto PythonFin
versionCount:
StrCpy $4 $2
Goto loopNext
secondNumber:
${If} $2 S>= ${LowestSupportedPythonVersion}
${If} $2 S<= ${HighestSupportedPythonVersion}
StrCpy $python_version "$4$explodeChar$2"
DetailPrint '$(STATUS_PythonVersionFound) $python_version'
StrCpy $found_python "true"
Goto PythonMode
${Else}
Goto wrongVersion
${EndIf}
${Else}
Goto wrongVersion
${EndIf}
Goto loopNext
CutPython:
${StrCase2} $3 $2 "U"
StrCmp $3 "PYTHON" loopNext
StrCpy $python_version $2
StrCpy $explodeChar '.'
Goto loop
loopNext:
${Next}
${Else}
PythonNotFound:
MessageBox MB_OK $(STATUS_PythonNotFound)
DetailPrint $(STATUS_PythonNotFound)
Goto PythonFin
${EndIf}
PythonMode:
DetailPrint $(STATUS_PythonArchitectSearch)
nsExec::ExecToStack '"$python_location\python.exe" -c $\"import struct;print( 8 * struct.calcsize($\'P$\'))$\"'
Pop $0
${If} $0 = 0
Pop $0
${StrTrimNewLines2} $python_architect $0
DetailPrint '$(STATUS_PythonArchitectFound) $python_architectbit'
${Else}
StrCpy $found_python "false"
MessageBox MB_OK $(STATUS_PythonArchitectNotFound)
DetailPrint $(STATUS_PythonArchitectNotFound)
${EndIf}
StrCpy $6 StopGetDrives
PythonFin:
Push $6
FunctionEnd
Function Done
done:
DetailPrint '$(STATUS_ExecutingScript) $INSTDIR\install(_error).log'
Sleep ${LogInformationTime}
ExecWait '"$INSTDIR\installer\install.cmd" "$INSTDIR" "$running_directory" ${Show_output} "false" "${AppUrl}" $append >"$INSTDIR\install.log" 2>"$INSTDIR\install_error.log"'
RMDir /r "$INSTDIR\installer"
FunctionEnd
Function CallbackFunction
${GetParent} $R0 $python_location
DetailPrint '$(STATUS_PythonFound) "$python_location\"'
Push "Stop"
FunctionEnd
Function SearchFile
Exch 4
Exch
Exch 3
Exch $R0 ; directory in which to search
Exch 4
Exch
Exch $R1 ; file or folder name to search in
Exch 3
Exch 2
Exch $R2
Exch 2
Exch $R3
Exch
Push $R4
Exch
Push $R5
Exch
Push $R6
Exch
Exch $R7 ;search folders with "."
StrCpy $R5 $R2 ;$R5 = custom function name
StrCpy $R6 $R3 ;$R6 = include subfolders
StrCpy $R2 ""
StrCpy $R3 ""
# Remove \ from end (if any) from the file name or folder name to search
StrCpy $R2 $R1 1 -1
StrCmp $R2 \ 0 +2
StrCpy $R1 $R1 -1
# Detect if the search path have backslash to add the backslash
StrCpy $R2 $R0 1 -1
StrCmp $R2 \ +2
StrCpy $R0 "$R0\"
# File (or Folder) Search
##############
# Get first file or folder name
FindFirst $R2 $R3 "$R0$R1"
FindNextFile:
# This loop, search for files or folders with the same conditions.
StrCmp $R3 "" NoFiles
StrCpy $R4 "$R0$R3"
# Preparing variables for the Callback function
Push $R7
Push $R6
Push $R5
Push $R4
Push $R3
Push $R2
Push $R1
Push $R0
# Call the Callback function
Call $R5
# Returning variables
Push $R8
Exch
Pop $R8
Exch
Pop $R0
Exch
Pop $R1
Exch
Pop $R2
Exch
Pop $R3
Exch
Pop $R4
Exch
Pop $R5
Exch
Pop $R6
Exch
Pop $R7
StrCmp $R8 "Stop" 0 +3
Pop $R8
Goto Done
Pop $R8
# Detect if have another file
FindNext $R2 $R3
Goto FindNextFile ;and loop!
# If don't have any more files or folders with the condictions
NoFiles:
FindClose $R2
# Search in Subfolders
#############
# If you don't want to search in subfolders...
StrCmp $R6 0 NoSubfolders 0
# SEARCH FOLDERS WITH DOT
# Find the first folder with dot
StrCmp $R7 1 0 EndWithDot
FindFirst $R2 $R3 "$R0*.*"
StrCmp $R3 "" NoSubfolders
StrCmp $R3 "." FindNextSubfolderWithDot 0
StrCmp $R3 ".." FindNextSubfolderWithDot 0
IfFileExists "$R0$R3\*.*" RecallingOfFunction 0
# Now, detect the next folder with dot
FindNextSubfolderWithDot:
FindNext $R2 $R3
StrCmp $R3 "" NoSubfolders
StrCmp $R3 "." FindNextSubfolder 0
StrCmp $R3 ".." FindNextSubfolder 0
IfFileExists "$R0$R3\*.*" RecallingOfFunction FindNextSubfolderWithDot
EndWithDot:
# SEARCH FOLDERS WITHOUT DOT
# Skip ., and .. (C:\ don't have .., so have to detect if is :\)
FindFirst $R2 $R3 "$R0*."
Push $R6
StrCpy $R6 $R0 "" 1
StrCmp $R6 ":\" +2
FindNext $R2 $R3
Pop $R6
# Now detect the "really" subfolders, and loop
FindNextSubfolder:
FindNext $R2 $R3
StrCmp $R3 "" NoSubfolders
IfFileExists "$R0$R3\" FindNextSubfolder
# Now Recall the function (making a LOOP)!
RecallingOfFunction:
Push $R1
Push "$R0$R3\"
Push "$R5"
Push "$R6"
Push "$R7"
Call SearchFile
# Now, find the next Subfolder
Goto FindNextSubfolder
# If don't exist more subfolders...
NoSubfolders:
FindClose $R2
# Returning Values to User
Done:
Pop $R7
Pop $R6
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Pop $R0
FunctionEnd
Function Explode
; Initialize variables
Var /GLOBAL explString
Var /GLOBAL explSeparator
Var /GLOBAL explStrLen
Var /GLOBAL explSepLen
Var /GLOBAL explOffset
Var /GLOBAL explTmp
Var /GLOBAL explTmp2
Var /GLOBAL explTmp3
Var /GLOBAL explArrCount
; Get input from user
Pop $explString
Pop $explSeparator
; Calculates initial values
StrLen $explStrLen $explString
StrLen $explSepLen $explSeparator
StrCpy $explArrCount 1
${If} $explStrLen <= 1 ; If we got a single character
${OrIf} $explSepLen > $explStrLen ; or separator is larger than the string,
Push $explString ; then we return initial string with no change
Push 1 ; and set array's length to 1
Return
${EndIf}
; Set offset to the last symbol of the string
StrCpy $explOffset $explStrLen
IntOp $explOffset $explOffset - 1
; Clear temp string to exclude the possibility of appearance of occasional data
StrCpy $explTmp ""
StrCpy $explTmp2 ""
StrCpy $explTmp3 ""
; Loop until the offset becomes negative
${Do}
; If offset becomes negative, it is time to leave the function
${IfThen} $explOffset == -1 ${|} ${ExitDo} ${|}
; Remove everything before and after the searched part ("TempStr")
StrCpy $explTmp $explString $explSepLen $explOffset
${If} $explTmp == $explSeparator
; Calculating offset to start copy from
IntOp $explTmp2 $explOffset + $explSepLen ; Offset equals to the current offset plus length of separator
StrCpy $explTmp3 $explString "" $explTmp2
Push $explTmp3 ; Throwing array item to the stack
IntOp $explArrCount $explArrCount + 1 ; Increasing array's counter
StrCpy $explString $explString $explOffset 0 ; Cutting all characters beginning with the separator entry
StrLen $explStrLen $explString
${EndIf}
${If} $explOffset = 0 ; If the beginning of the line met and there is no separator,
; copying the rest of the string
${If} $explSeparator == "" ; Fix for the empty separator
IntOp $explArrCount $explArrCount - 1
${Else}
Push $explString
${EndIf}
${EndIf}
IntOp $explOffset $explOffset - 1
${Loop}
Push $explArrCount
FunctionEnd
Function StrCase2
/*After this point:
------------------------------------------
$0 = String (input)
$1 = Case (input)
$2 = StrLength (temp)
$3 = StartChar (temp)
$4 = EndChar (temp)
$5 = ResultStr (temp)
$6 = CurrentChar (temp)
$7 = LastChar (temp)
$8 = Temp (temp)*/
;Get input from user
Exch $1
Exch
Exch $0
Exch
Push $2
Push $3
Push $4
Push $5
Push $6
Push $7
Push $8
;Initialize variables
StrCpy $2 ""
StrCpy $3 ""
StrCpy $4 ""
StrCpy $5 ""
StrCpy $6 ""
StrCpy $7 ""
StrCpy $8 ""
;Upper and lower cases are simple to use
${If} $1 == "U"
;Upper Case:
;-----------
;Convert all characters to upper case.
System::Call "User32::CharUpper(t r0 r5)i"
Goto StrCase_End
${ElseIf} $1 == "L"
;Lower Case:
;-----------
;Convert all characters to lower case.
System::Call "User32::CharLower(t r0 r5)i"
Goto StrCase_End
${EndIf}
;For the rest of cases:
;Get "String" length
StrLen $2 $0
;Make a loop until the end of "String"
${For} $3 0 $2
;Add 1 to "EndChar" counter also
IntOp $4 $3 + 1
# Step 1: Detect one character at a time
;Remove characters before "StartChar" except when
;"StartChar" is the first character of "String"
${If} $3 <> 0
StrCpy $6 $0 `` $3
${EndIf}
;Remove characters after "EndChar" except when
;"EndChar" is the last character of "String"
${If} $4 <> $2
${If} $3 = 0
StrCpy $6 $0 1
${Else}
StrCpy $6 $6 1
${EndIf}
${EndIf}
# Step 2: Convert to the advanced case user chose:
${If} $1 == "T"
;Title Case:
;------------------
; Convert all characters after a non-alphabetic character to upper case.
; Else convert to lower case.
;Use "IsCharAlpha" for the job
System::Call "*(&t1 r7) i .r8"
System::Call "*$8(&i1 .r7)"
System::Free $8
System::Call "user32::IsCharAlpha(i r7) i .r8"
;Verify "IsCharAlpha" result and convert the character
${If} $8 = 0
System::Call "User32::CharUpper(t r6 r6)i"
${Else}
System::Call "User32::CharLower(t r6 r6)i"
${EndIf}
${ElseIf} $1 == "S"
;Sentence Case:
;------------------
; Convert all characters after a ".", "!" or "?" character to upper case.
; Else convert to lower case. Spaces or tabs after these marks are ignored.
;Detect current characters and ignore if necessary
${If} $6 == " "
${OrIf} $6 == "$\t"
Goto IgnoreLetter
${EndIf}
;Detect last characters and convert
${If} $7 == "."
${OrIf} $7 == "!"
${OrIf} $7 == "?"
${OrIf} $7 == ""
System::Call "User32::CharUpper(t r6 r6)i"
${Else}
System::Call "User32::CharLower(t r6 r6)i"
${EndIf}
${ElseIf} $1 == "<>"
;Switch Case:
;------------------
; Switch all characters cases to their inverse case.
;Use "IsCharUpper" for the job
System::Call "*(&t1 r6) i .r8"
System::Call "*$8(&i1 .r7)"
System::Free $8
System::Call "user32::IsCharUpper(i r7) i .r8"
;Verify "IsCharUpper" result and convert the character
${If} $8 = 0
System::Call "User32::CharUpper(t r6 r6)i"
${Else}
System::Call "User32::CharLower(t r6 r6)i"
${EndIf}
${EndIf}
;Write the character to "LastChar"
StrCpy $7 $6
IgnoreLetter:
;Add this character to "ResultStr"
StrCpy $5 `$5$6`
${Next}
StrCase_End:
/*After this point:
------------------------------------------
$0 = ResultVar (output)*/
; Copy "ResultStr" to "ResultVar"
StrCpy $0 $5
;Return output to user
Pop $8
Pop $7
Pop $6
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Exch $0
FunctionEnd
Function StrTrimNewLines2
/*After this point:
------------------------------------------
$R0 = String (input)
$R1 = TrimCounter (temp)
$R2 = Temp (temp)*/
;Get input from user
Exch $R0
Push $R1
Push $R2
;Initialize trim counter
StrCpy $R1 0
loop:
;Subtract to get "String"'s last characters
IntOp $R1 $R1 - 1
;Verify if they are either $\r or $\n
StrCpy $R2 $R0 1 $R1
${If} $R2 == '$\r'
${OrIf} $R2 == '$\n'
Goto loop
${EndIf}
;Trim characters (if needed)
IntOp $R1 $R1 + 1
${If} $R1 < 0
StrCpy $R0 $R0 $R1
${EndIf}
/*After this point:
------------------------------------------
$R0 = ResultVar (output)*/
;Return output to user
Pop $R2
Pop $R1
Exch $R0
FunctionEnd
;--------------------------------
;Descriptions
;Assign language strings to sections
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SecInstall} $(DESC_SecInstall)
!insertmacro MUI_DESCRIPTION_TEXT ${PythonLookup} $(DESC_PythonLookup)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
;--------------------------------
;Uninstaller Section
Section "Uninstall"
ClearErrors
ReadRegStr $running_directory HKCU "Software\${Company} ${AppName}" "running_directory"
${If} ${Errors}
StrCpy $running_directory ${DefaulLocation}
ClearErrors
${EndIf}
StrCmp $LANGUAGE ${LANG_HUNGARIAN} 0 +4
IfFileExists "$SMPROGRAMS\${Company}\L�togasd meg a ${AppUrlName}-t.url" 0 +2
Delete "$SMPROGRAMS\${Company}\L�togasd meg a ${AppUrlName}-t.url"
Goto +3
IfFileExists "$SMPROGRAMS\${Company}\Visit the ${AppUrlName}.url" 0 +2
Delete "$SMPROGRAMS\${Company}\Visit the ${AppUrlName}.url"
IfFileExists "$SMPROGRAMS\${Company}\${AppName}\*.*" 0 +2
RMDir /r "$SMPROGRAMS\${Company}\${AppName}"
IfFileExists "$SMPROGRAMS\${Company}\*.*" +2 0
RMDir /r "$SMPROGRAMS\${Company}"
ExecWait '"$INSTDIR\uninstaller\uninstall.cmd" "$INSTDIR" ${Show_output} >"$INSTDIR\uninstall.log" 2>"$INSTDIR\uninstall_error.log"'
IfFileExists "$INSTDIR\uninstaller\*.*" 0 +2
RMDir /r "$INSTDIR\uninstaller"
IfFileExists "$running_directory\.rdp\*.*" 0 +2
RMDir /r "$running_directory\.rdp"
IfFileExists "$running_directory\client.log" 0 +2
Delete "$running_directory\client.log"
IfFileExists "$INSTDIR\cloud.py" 0 +2
Delete "$INSTDIR\cloud.py"
IfFileExists "$INSTDIR\cloud_connect_from_windows.py" 0 +2
Delete "$INSTDIR\cloud_connect_from_windows.py"
IfFileExists "$INSTDIR\OrderedDict.py" 0 +2
Delete "$INSTDIR\OrderedDict.py"
IfFileExists "$INSTDIR\putty.exe" 0 +2
Delete "$INSTDIR\putty.exe"
IfFileExists "$INSTDIR\win_install.py" 0 +2
Delete "$INSTDIR\win_install.py"
IfFileExists "$INSTDIR\windowsclasses.py" 0 +2
Delete "$INSTDIR\windowsclasses.py"
IfFileExists "$INSTDIR\windowsclasses.pyc" 0 +2
Delete "$INSTDIR\windowsclasses.pyc"
IfFileExists "$INSTDIR\${AppUninstaller}" 0 +2
Delete "$INSTDIR\${AppUninstaller}"
StrCmp $INSTDIR "${DefaulLocation}" 0 +2
RMDir /r "$INSTDIR"
SectionEnd
;--------------------------------
;Uninstaller Functions
Function un.onInit
ClearErrors
ReadRegStr $0 HKLM "Software\${Company} ${AppName}" "install_directory"
${If} ${Errors}
${IF} $INSTDIR == ""
StrCpy $INSTDIR "$LOCALAPPDATA\CIRCLE"
${ENDIF}
${Else}
${IF} $0 == ""
StrCpy $INSTDIR "$LOCALAPPDATA\CIRCLE"
${ELSE}
StrCpy $INSTDIR $0
${ENDIF}
${EndIf}
${If} ${RunningX64}
${DisableX64FSRedirection}
SetRegView 64
${EndIf}
!insertmacro MUI_UNGETLANGUAGE
!insertmacro MULTIUSER_UNINIT
FunctionEnd
\ No newline at end of file
# Generating .exe file
To generate the .exe file for the windows installer, you have to use the cloud.nsi script located here.
The NSIS software can execute the script. You can download it from [here](http://nsis.sourceforge.net/Main_Page).
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
# Backport of OrderedDict() class that runs on Python 2.4, 2.5, 2.6, 2.7 and pypy.
# Passes Python2.7's test suite and incorporates all the latest updates.
# flake8: noqa
try:
from thread import get_ident as _get_ident
except ImportError:
from dummy_thread import get_ident as _get_ident
try:
from _abcoll import KeysView, ValuesView, ItemsView
except ImportError:
pass
class OrderedDict(dict):
'Dictionary that remembers insertion order'
# An inherited dict maps keys to values.
# The inherited dict provides __getitem__, __len__, __contains__, and get.
# The remaining methods are order-aware.
# Big-O running times for all methods are the same as for regular dictionaries.
# The internal self.__map dictionary maps keys to links in a doubly linked list.
# The circular doubly linked list starts and ends with a sentinel element.
# The sentinel element never gets deleted (this simplifies the algorithm).
# Each link is stored as a list of length three: [PREV, NEXT, KEY].
def __init__(self, *args, **kwds):
'''Initialize an ordered dictionary. Signature is the same as for
regular dictionaries, but keyword arguments are not recommended
because their insertion order is arbitrary.
'''
if len(args) > 1:
raise TypeError('expected at most 1 arguments, got %d' % len(args))
try:
self.__root
except AttributeError:
self.__root = root = [] # sentinel node
root[:] = [root, root, None]
self.__map = {}
self.__update(*args, **kwds)
def __setitem__(self, key, value, dict_setitem=dict.__setitem__):
'od.__setitem__(i, y) <==> od[i]=y'
# Setting a new item creates a new link which goes at the end of the linked
# list, and the inherited dictionary is updated with the new key/value pair.
if key not in self:
root = self.__root
last = root[0]
last[1] = root[0] = self.__map[key] = [last, root, key]
dict_setitem(self, key, value)
def __delitem__(self, key, dict_delitem=dict.__delitem__):
'od.__delitem__(y) <==> del od[y]'
# Deleting an existing item uses self.__map to find the link which is
# then removed by updating the links in the predecessor and successor nodes.
dict_delitem(self, key)
link_prev, link_next, key = self.__map.pop(key)
link_prev[1] = link_next
link_next[0] = link_prev
def __iter__(self):
'od.__iter__() <==> iter(od)'
root = self.__root
curr = root[1]
while curr is not root:
yield curr[2]
curr = curr[1]
def __reversed__(self):
'od.__reversed__() <==> reversed(od)'
root = self.__root
curr = root[0]
while curr is not root:
yield curr[2]
curr = curr[0]
def clear(self):
'od.clear() -> None. Remove all items from od.'
try:
for node in self.__map.itervalues():
del node[:]
root = self.__root
root[:] = [root, root, None]
self.__map.clear()
except AttributeError:
pass
dict.clear(self)
def popitem(self, last=True):
'''od.popitem() -> (k, v), return and remove a (key, value) pair.
Pairs are returned in LIFO order if last is true or FIFO order if false.
'''
if not self:
raise KeyError('dictionary is empty')
root = self.__root
if last:
link = root[0]
link_prev = link[0]
link_prev[1] = root
root[0] = link_prev
else:
link = root[1]
link_next = link[1]
root[1] = link_next
link_next[0] = root
key = link[2]
del self.__map[key]
value = dict.pop(self, key)
return key, value
# -- the following methods do not depend on the internal structure --
def keys(self):
'od.keys() -> list of keys in od'
return list(self)
def values(self):
'od.values() -> list of values in od'
return [self[key] for key in self]
def items(self):
'od.items() -> list of (key, value) pairs in od'
return [(key, self[key]) for key in self]
def iterkeys(self):
'od.iterkeys() -> an iterator over the keys in od'
return iter(self)
def itervalues(self):
'od.itervalues -> an iterator over the values in od'
for k in self:
yield self[k]
def iteritems(self):
'od.iteritems -> an iterator over the (key, value) items in od'
for k in self:
yield (k, self[k])
def update(*args, **kwds):
'''od.update(E, **F) -> None. Update od from dict/iterable E and F.
If E is a dict instance, does: for k in E: od[k] = E[k]
If E has a .keys() method, does: for k in E.keys(): od[k] = E[k]
Or if E is an iterable of items, does: for k, v in E: od[k] = v
In either case, this is followed by: for k, v in F.items(): od[k] = v
'''
if len(args) > 2:
raise TypeError('update() takes at most 2 positional '
'arguments (%d given)' % (len(args),))
elif not args:
raise TypeError('update() takes at least 1 argument (0 given)')
self = args[0]
# Make progressively weaker assumptions about "other"
other = ()
if len(args) == 2:
other = args[1]
if isinstance(other, dict):
for key in other:
self[key] = other[key]
elif hasattr(other, 'keys'):
for key in other.keys():
self[key] = other[key]
else:
for key, value in other:
self[key] = value
for key, value in kwds.items():
self[key] = value
__update = update # let subclasses override update without breaking __init__
__marker = object()
def pop(self, key, default=__marker):
'''od.pop(k[,d]) -> v, remove specified key and return the corresponding value.
If key is not found, d is returned if given, otherwise KeyError is raised.
'''
if key in self:
result = self[key]
del self[key]
return result
if default is self.__marker:
raise KeyError(key)
return default
def setdefault(self, key, default=None):
'od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od'
if key in self:
return self[key]
self[key] = default
return default
def __repr__(self, _repr_running={}):
'od.__repr__() <==> repr(od)'
call_key = id(self), _get_ident()
if call_key in _repr_running:
return '...'
_repr_running[call_key] = 1
try:
if not self:
return '%s()' % (self.__class__.__name__,)
return '%s(%r)' % (self.__class__.__name__, self.items())
finally:
del _repr_running[call_key]
def __reduce__(self):
'Return state information for pickling'
items = [[k, self[k]] for k in self]
inst_dict = vars(self).copy()
for k in vars(OrderedDict()):
inst_dict.pop(k, None)
if inst_dict:
return (self.__class__, (items,), inst_dict)
return self.__class__, (items,)
def copy(self):
'od.copy() -> a shallow copy of od'
return self.__class__(self)
@classmethod
def fromkeys(cls, iterable, value=None):
'''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S
and values equal to v (which defaults to None).
'''
d = cls()
for key in iterable:
d[key] = value
return d
def __eq__(self, other):
'''od.__eq__(y) <==> od==y. Comparison to another OD is order-sensitive
while comparison to a regular mapping is order-insensitive.
'''
if isinstance(other, OrderedDict):
return len(self)==len(other) and self.items() == other.items()
return dict.__eq__(self, other)
def __ne__(self, other):
return not self == other
# -- the following methods are only used in Python 2.7 --
def viewkeys(self):
"od.viewkeys() -> a set-like object providing a view on od's keys"
return KeysView(self)
def viewvalues(self):
"od.viewvalues() -> an object providing a view on od's values"
return ValuesView(self)
def viewitems(self):
"od.viewitems() -> a set-like object providing a view on od's items"
return ItemsView(self)
\ No newline at end of file
@echo off
:addPath pathVar /B
::
:: Safely appends the path contained within variable pathVar to the end
:: of PATH if and only if the path does not already exist within PATH.
::
:: If the case insensitive /B option is specified, then the path is
:: inserted into the front (Beginning) of PATH instead.
::
:: If the pathVar path is fully qualified, then it is logically compared
:: to each fully qualified path within PATH. The path strings are
:: considered a match if they are logically equivalent.
::
:: If the pathVar path is relative, then it is strictly compared to each
:: relative path within PATH. Case differences and double quotes are
:: ignored, but otherwise the path strings must match exactly.
::
:: Before appending the pathVar path, all double quotes are stripped, and
:: then the path is enclosed in double quotes if and only if the path
:: contains at least one semicolon.
::
:: addPath aborts with ERRORLEVEL 2 if pathVar is missing or undefined
:: or if PATH is undefined.
::
::------------------------------------------------------------------------
::
:: Error checking
if "%~1"=="" exit /b 2
if not defined %~1 exit /b 2
if not defined path exit /b 2
::
:: Determine if function was called while delayed expansion was enabled
setlocal
set "NotDelayed=!"
::
:: Prepare to safely parse PATH into individual paths
setlocal DisableDelayedExpansion
set "var=%path:"=""%"
set "var=%var:^=^^%"
set "var=%var:&=^&%"
set "var=%var:|=^|%"
set "var=%var:<=^<%"
set "var=%var:>=^>%"
set "var=%var:;=^;^;%"
set var=%var:""="%
set "var=%var:"=""Q%"
set "var=%var:;;="S"S%"
set "var=%var:^;^;=;%"
set "var=%var:""="%"
setlocal EnableDelayedExpansion
set "var=!var:"Q=!"
set "var=!var:"S"S=";"!"
::
:: Remove quotes from pathVar and abort if it becomes empty
set "new=!%~1:"^=!"
if not defined new exit /b 2
::
:: Determine if pathVar is fully qualified
echo("!new!"|findstr /i /r /c:^"^^\"[a-zA-Z]:[\\/][^\\/]" ^
/c:^"^^\"[\\][\\]" >nul ^
&& set "abs=1" || set "abs=0"
::
:: For each path in PATH, check if path is fully qualified and then
:: do proper comparison with pathVar. Exit if a match is found.
:: Delayed expansion must be disabled when expanding FOR variables
:: just in case the value contains !
for %%A in ("!new!\") do for %%B in ("!var!") do (
if "!!"=="" setlocal disableDelayedExpansion
for %%C in ("%%~B\") do (
echo(%%B|findstr /i /r /c:^"^^\"[a-zA-Z]:[\\/][^\\/]" ^
/c:^"^^\"[\\][\\]" >nul ^
&& (if %abs%==1 if /i "%%~sA"=="%%~sC" exit /b 0) ^
|| (if %abs%==0 if /i %%A==%%C exit /b 0)
)
)
::
:: Build the modified PATH, enclosing the added path in quotes
:: only if it contains ;
setlocal enableDelayedExpansion
if "!new:;=!" neq "!new!" set new="!new!"
if /i "%~2"=="/B" (set "rtn=!new!;!path!") else set "rtn=!path!;!new!"
::
:: rtn now contains the modified PATH. We need to safely pass the
:: value accross the ENDLOCAL barrier
::
:: Make rtn safe for assignment using normal expansion by replacing
:: % and " with not yet defined FOR variables
set "rtn=!rtn:%%=%%A!"
set "rtn=!rtn:"=%%B!"
::
:: Escape ^ and ! if function was called while delayed expansion was enabled.
:: The trailing ! in the second assignment is critical and must not be removed.
if not defined NotDelayed set "rtn=!rtn:^=^^^^!"
if not defined NotDelayed set "rtn=%rtn:!=^^^!%" !
::
:: Pass the rtn value accross the ENDLOCAL barrier using FOR variables to
:: restore the % and " characters. Again the trailing ! is critical.
for /f "usebackq tokens=1,2" %%A in ('%%^ ^"') do (
endlocal & endlocal & endlocal & endlocal & endlocal
set "path=%rtn%" !
)
exit /b 0
\ No newline at end of file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Main program of the Client written for CIRCLE Cloud.
The Client job is to help the ease of use of the cloud system.
"""
import argparse
import logging
import platform
import tempfile
from time import gmtime, strftime
class Struct:
"""
A struct used for parameter passing
Keyword arguments:
state -- State of the Virtual Computer (running, etc..)
protocol -- SSH and RDP possible
host -- Address of the Virtual Computer
port -- The port where we can access the Virtual Computer
user -- Username used for the connection
password -- Password used for the connection
"""
pass
def parse_arguments():
"""
Argument parser, based on the argparse module
Keyword arguments:
@return args -- arguments given by console
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"uri", type=str, help="Specific schema handler", nargs='?',
default=None)
parser.add_argument(
"-l", "--loglevel",
help="The level of logging severity", type=str,
choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
default="INFO")
parser.add_argument(
"-f", "--logfile",
help="Explicit location of the wanted logfile location and name",
type=str,
default=("%(directory)s\\%(file)s" % {
'directory': tempfile.gettempdir(),
'file': 'circle_client.log'}))
args = parser.parse_args()
return args
def main():
"""
Main program
"""
args = parse_arguments()
logging.basicConfig(filename='%s' % args.logfile,
format='%(levelname)s:%(message)s')
logger = logging.getLogger()
logger.setLevel(args.loglevel)
logger.info("----------------------------")
logger.info("Client started running at %s",
strftime("%Y-%d-%m %H:%M:%S GMT", gmtime()))
try:
if args.uri is not None:
vm = Struct()
x, vm.protocol, vm.user, vm.password, vm.host, vm.port = \
args.uri.split(':', 5)
logger.info(("Received the following URI: %(handler)s:"
"%(protocol)s:%(user)s:password:%(host)s:%(port)s" % {
'handler': x,
'protocol': vm.protocol,
'user': vm.user,
'host': vm.host,
'port': vm.port
}))
vm.protocol = vm.protocol.upper()
logger.debug("The Client split it followingly: protocol -> %s | "
"user -> %s | password -> %s | "
"host -> %s | port -> %s",
vm.protocol, vm.user, vm.password, vm.host, vm.port)
else:
logger.critical("Client did not receive an URI which would be "
"necessary to continue")
if platform.system() == "Windows":
logger.debug('Windows OS found, proceeding to connect methods')
from cloud_connect_from_windows import connect
connect(vm)
except:
logger.exception("An exception was raised before connect methods"
"could be invoked")
print("Unknown error occurred! Please contact the developers!")
if __name__ == "__main__":
main()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Configuration of the Windows specific tools to enhance the ease of use
of the CIRCLE cloud. Handles the auto launch and auto configuration
of these specific connectivity programs.
"""
import binascii
import glob
import locale
import logging
import os
import subprocess
import time
import tempfile
import win32crypt
def connect(vm):
"""
Handles to connection to the Virtual Machines from the local
machine
Keyword arguments:
vm.protocol -- SSH and RDP possible
vm.host -- Address of the Virtual Computer
vm.port -- The port where we can access the Virtual Computer
vm.user -- Username used for the connection
vm.password -- Password used for the connection
"""
logger = logging.getLogger()
logger.debug('Connect methods started')
if vm.protocol == "SSH":
logger.info('SSH protocol received')
arguments = str("-ssh -P %(port)s -pw %(password)s"
" %(user)s@%(host)s" % {
'port': vm.port,
'password': vm.password,
'user': vm.user,
'host': vm.host})
directory = os.path.dirname(os.path.abspath(__file__))
logger.info('Popen: "%s\\putty.exe"', directory)
logger.debug('Determined arguments: %s', arguments)
subprocess.Popen('"%(path)s\\putty.exe" %(arguments)s' % {
'path': directory,
'arguments': arguments}, shell=True)
elif vm.protocol == "RDP":
logger.debug('RDP protocol received')
full_address = "full address:s:%s:%s" % (vm.host, vm.port)
user = "username:s:%s" % vm.user
config_file = "%s%s" % (
tempfile.gettempdir(),
"\\circle_" + vm.user + str(int(time.time() * 1000)) + ".rdp")
logger.info('Creating config file %s' % config_file)
password = win32crypt.CryptProtectData(vm.password.encode('utf-16-le'), 'psw', None, None, None, 0).hex()
config = RPD_template.format(vm.user, vm.host, vm.port, password)
f = open(config_file, 'w')
f.write(config)
f.close()
logger.debug('Popen the config file: %s', config_file)
subprocess.Popen([config_file], shell=True).wait()
os.remove(config_file)
logger.info('Client finished working')
RPD_template = """username:s:{}
full address:s:{}:{}
authentication level:i:0
password 51:b:{}"""
#!/usr/bin/env python
# flake8: noqa
"""Bootstrap setuptools installation
To use setuptools in your package's setup.py, include this
file in the same directory and add this to the top of your setup.py::
from ez_setup import use_setuptools
use_setuptools()
To require a specific version of setuptools, set a download
mirror, or use an alternate download directory, simply supply
the appropriate options to ``use_setuptools()``.
This file can also be run as a script to install or upgrade setuptools.
"""
import os
import shutil
import sys
import tempfile
import zipfile
import optparse
import subprocess
import platform
import textwrap
import contextlib
from distutils import log
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
try:
from site import USER_SITE
except ImportError:
USER_SITE = None
DEFAULT_VERSION = "5.8"
DEFAULT_URL = "https://pypi.python.org/packages/source/s/setuptools/"
def _python_cmd(*args):
"""
Return True if the command succeeded.
"""
args = (sys.executable,) + args
return subprocess.call(args) == 0
def _install(archive_filename, install_args=()):
with archive_context(archive_filename):
# installing
log.warn('Installing Setuptools')
if not _python_cmd('setup.py', 'install', *install_args):
log.warn('Something went wrong during the installation.')
log.warn('See the error message above.')
# exitcode will be 2
return 2
def _build_egg(egg, archive_filename, to_dir):
with archive_context(archive_filename):
# building an egg
log.warn('Building a Setuptools egg in %s', to_dir)
_python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir)
# returning the result
log.warn(egg)
if not os.path.exists(egg):
raise IOError('Could not build the egg.')
class ContextualZipFile(zipfile.ZipFile):
"""
Supplement ZipFile class to support context manager for Python 2.6
"""
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
self.close()
def __new__(cls, *args, **kwargs):
"""
Construct a ZipFile or ContextualZipFile as appropriate
"""
if hasattr(zipfile.ZipFile, '__exit__'):
return zipfile.ZipFile(*args, **kwargs)
return super(ContextualZipFile, cls).__new__(cls)
@contextlib.contextmanager
def archive_context(filename):
# extracting the archive
tmpdir = tempfile.mkdtemp()
log.warn('Extracting in %s', tmpdir)
old_wd = os.getcwd()
try:
os.chdir(tmpdir)
with ContextualZipFile(filename) as archive:
archive.extractall()
# going in the directory
subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
os.chdir(subdir)
log.warn('Now working in %s', subdir)
yield
finally:
os.chdir(old_wd)
shutil.rmtree(tmpdir)
def _do_download(version, download_base, to_dir, download_delay):
egg = os.path.join(to_dir, 'setuptools-%s-py%d.%d.egg'
% (version, sys.version_info[0], sys.version_info[1]))
if not os.path.exists(egg):
archive = download_setuptools(version, download_base,
to_dir, download_delay)
_build_egg(egg, archive, to_dir)
sys.path.insert(0, egg)
# Remove previously-imported pkg_resources if present (see
# https://bitbucket.org/pypa/setuptools/pull-request/7/ for details).
if 'pkg_resources' in sys.modules:
del sys.modules['pkg_resources']
import setuptools
setuptools.bootstrap_install_from = egg
def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
to_dir=os.curdir, download_delay=15):
to_dir = os.path.abspath(to_dir)
rep_modules = 'pkg_resources', 'setuptools'
imported = set(sys.modules).intersection(rep_modules)
try:
import pkg_resources
except ImportError:
return _do_download(version, download_base, to_dir, download_delay)
try:
pkg_resources.require("setuptools>=" + version)
return
except pkg_resources.DistributionNotFound:
return _do_download(version, download_base, to_dir, download_delay)
except pkg_resources.VersionConflict as VC_err:
if imported:
msg = textwrap.dedent("""
The required version of setuptools (>={version}) is not available,
and can't be installed while this script is running. Please
install a more recent version first, using
'easy_install -U setuptools'.
(Currently using {VC_err.args[0]!r})
""").format(VC_err=VC_err, version=version)
sys.stderr.write(msg)
sys.exit(2)
# otherwise, reload ok
del pkg_resources, sys.modules['pkg_resources']
return _do_download(version, download_base, to_dir, download_delay)
def _clean_check(cmd, target):
"""
Run the command to download target. If the command fails, clean up before
re-raising the error.
"""
try:
subprocess.check_call(cmd)
except subprocess.CalledProcessError:
if os.access(target, os.F_OK):
os.unlink(target)
raise
def download_file_powershell(url, target):
"""
Download the file at url to target using Powershell (which will validate
trust). Raise an exception if the command cannot complete.
"""
target = os.path.abspath(target)
ps_cmd = (
"[System.Net.WebRequest]::DefaultWebProxy.Credentials = "
"[System.Net.CredentialCache]::DefaultCredentials; "
"(new-object System.Net.WebClient).DownloadFile(%(url)r, %(target)r)"
% vars()
)
cmd = [
'powershell',
'-Command',
ps_cmd,
]
_clean_check(cmd, target)
def has_powershell():
if platform.system() != 'Windows':
return False
cmd = ['powershell', '-Command', 'echo test']
with open(os.path.devnull, 'wb') as devnull:
try:
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
except Exception:
return False
return True
download_file_powershell.viable = has_powershell
def download_file_curl(url, target):
cmd = ['curl', url, '--silent', '--output', target]
_clean_check(cmd, target)
def has_curl():
cmd = ['curl', '--version']
with open(os.path.devnull, 'wb') as devnull:
try:
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
except Exception:
return False
return True
download_file_curl.viable = has_curl
def download_file_wget(url, target):
cmd = ['wget', url, '--quiet', '--output-document', target]
_clean_check(cmd, target)
def has_wget():
cmd = ['wget', '--version']
with open(os.path.devnull, 'wb') as devnull:
try:
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
except Exception:
return False
return True
download_file_wget.viable = has_wget
def download_file_insecure(url, target):
"""
Use Python to download the file, even though it cannot authenticate the
connection.
"""
src = urlopen(url)
try:
# Read all the data in one block.
data = src.read()
finally:
src.close()
# Write all the data in one block to avoid creating a partial file.
with open(target, "wb") as dst:
dst.write(data)
download_file_insecure.viable = lambda: True
def get_best_downloader():
downloaders = (
download_file_powershell,
download_file_curl,
download_file_wget,
download_file_insecure,
)
viable_downloaders = (dl for dl in downloaders if dl.viable())
return next(viable_downloaders, None)
def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
to_dir=os.curdir, delay=15, downloader_factory=get_best_downloader):
"""
Download setuptools from a specified location and return its filename
`version` should be a valid setuptools version number that is available
as an sdist for download under the `download_base` URL (which should end
with a '/'). `to_dir` is the directory where the egg will be downloaded.
`delay` is the number of seconds to pause before an actual download
attempt.
``downloader_factory`` should be a function taking no arguments and
returning a function for downloading a URL to a target.
"""
# making sure we use the absolute path
to_dir = os.path.abspath(to_dir)
zip_name = "setuptools-%s.zip" % version
url = download_base + zip_name
saveto = os.path.join(to_dir, zip_name)
if not os.path.exists(saveto): # Avoid repeated downloads
log.warn("Downloading %s", url)
downloader = downloader_factory()
downloader(url, saveto)
return os.path.realpath(saveto)
def _build_install_args(options):
"""
Build the arguments to 'python setup.py install' on the setuptools package
"""
return ['--user'] if options.user_install else []
def _parse_args():
"""
Parse the command line for options
"""
parser = optparse.OptionParser()
parser.add_option(
'--user', dest='user_install', action='store_true', default=False,
help='install in user site package (requires Python 2.6 or later)')
parser.add_option(
'--download-base', dest='download_base', metavar="URL",
default=DEFAULT_URL,
help='alternative URL from where to download the setuptools package')
parser.add_option(
'--insecure', dest='downloader_factory', action='store_const',
const=lambda: download_file_insecure, default=get_best_downloader,
help='Use internal, non-validating downloader'
)
parser.add_option(
'--version', help="Specify which version to download",
default=DEFAULT_VERSION,
)
options, args = parser.parse_args()
# positional arguments are ignored
return options
def main():
"""Install or upgrade setuptools and EasyInstall"""
options = _parse_args()
archive = download_setuptools(
version=options.version,
download_base=options.download_base,
downloader_factory=options.downloader_factory,
)
return _install(archive, _build_install_args(options))
if __name__ == '__main__':
sys.exit(main())
@echo off
:inPath pathVar
::
:: Tests if the path stored within variable pathVar exists within PATH.
::
:: The result is returned as the ERRORLEVEL:
:: 0 if the pathVar path is found in PATH.
:: 1 if the pathVar path is not found in PATH.
:: 2 if pathVar is missing or undefined or if PATH is undefined.
::
:: If the pathVar path is fully qualified, then it is logically compared
:: to each fully qualified path within PATH. The path strings don't have
:: to match exactly, they just need to be logically equivalent.
::
:: If the pathVar path is relative, then it is strictly compared to each
:: relative path within PATH. Case differences and double quotes are
:: ignored, but otherwise the path strings must match exactly.
::
::------------------------------------------------------------------------
::
:: Error checking
if "%~1"=="" exit /b 2
if not defined %~1 exit /b 2
if not defined path exit /b 2
::
:: Prepare to safely parse PATH into individual paths
setlocal DisableDelayedExpansion
set "var=%path:"=""%"
set "var=%var:^=^^%"
set "var=%var:&=^&%"
set "var=%var:|=^|%"
set "var=%var:<=^<%"
set "var=%var:>=^>%"
set "var=%var:;=^;^;%"
set var=%var:""="%
set "var=%var:"=""Q%"
set "var=%var:;;="S"S%"
set "var=%var:^;^;=;%"
set "var=%var:""="%"
setlocal EnableDelayedExpansion
set "var=!var:"Q=!"
set "var=!var:"S"S=";"!"
::
:: Remove quotes from pathVar and abort if it becomes empty
set "new=!%~1:"=!"
if not defined new exit /b 2
::
:: Determine if pathVar is fully qualified
echo("!new!"|findstr /i /r /c:^"^^\"[a-zA-Z]:[\\/][^\\/]" ^
/c:^"^^\"[\\][\\]" >nul ^
&& set "abs=1" || set "abs=0"
::
:: For each path in PATH, check if path is fully qualified and then do
:: proper comparison with pathVar.
:: Exit with ERRORLEVEL 0 if a match is found.
:: Delayed expansion must be disabled when expanding FOR variables
:: just in case the value contains !
for %%A in ("!new!\") do for %%B in ("!var!") do (
if "!!"=="" endlocal
for %%C in ("%%~B\") do (
echo(%%B|findstr /i /r /c:^"^^\"[a-zA-Z]:[\\/][^\\/]" ^
/c:^"^^\"[\\][\\]" >nul ^
&& (if %abs%==1 if /i "%%~sA"=="%%~sC" exit /b 0) ^
|| (if %abs%==0 if /i "%%~A"=="%%~C" exit /b 0)
)
)
:: No match was found so exit with ERRORLEVEL 1
exit /b 1
\ No newline at end of file
@echo off
cls
setLocal EnableDelayedExpansion
rem Get the running directory for later ease of use
SET running_directory=%~dp0
rem Set where this file will install the rest of the files
SET "location=%1"
IF NOT [!location!]==[] (
SET install_location=!location:"=!
) else (
SET "install_location=%APPDATA%\CIRCLE"
)
rem Set where this file will install the .rdp folder
SET "run_location=%2"
IF NOT [!run_location!]==[] (
SET running_location=!run_location:"=!
) else (
SET "running_location=%APPDATA%\CIRCLE"
)
rem Set whether we want output info on screen or not
IF NOT [%3]==[] (
SET "output_on_screen=%3"
) else (
SET "output_on_screen=True"
)
rem Set whether we want to install NX Client or not
IF NOT [%4]==[] (
SET "install_nx=%4"
) else (
SET "install_nx=False"
)
if NOT "!install_nx!"=="False" (
SET "nx_install= -n"
)
rem Set which website should the icon point to
SET "site=^"http://cloud.bme.hu/^""
IF NOT [%5]==[] (
SET site=%5
)
SET my_site=!site:"=!
SET "website= -t ^"!my_site!^""
rem Set Python bit count (32 or 64) if we know it
IF NOT [%6]==[] (
SET "architecture=%6"
) else (
SET "architecture="
)
rem Set Python version if we know it
IF NOT [%7]==[] (
SET "version=%7"
) else (
SET "version="
)
rem Set Python location if we know it
SET "python_location=%8"
IF NOT [!python_location!]==[] (
SET install_path=!python_location:"=!
) else (
SET "install_path="
)
:BatchCheckElevated
:-------------------------------------
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
IF NOT "!output_on_screen!"=="False" (
@echo Requesting administrative privileges...>CON
)
@echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > ^"%temp%\getadmin.vbs^"
set vbs_site=!site:"=""!
set vbs_installpath=!python_location:"=""!
echo UAC.ShellExecute "cmd.exe", "/c %~s0 !install_location! !output_on_screen! !install_nx! !vbs_site! !architecture! !version! !vbs_installpath!", "", "runas", 1 >> "%temp%\getadmin.vbs"
^"%temp%\getadmin.vbs^"
del "%temp%\getadmin.vbs"
exit /B
:gotAdmin
pushd "%CD%"
CD /D "%~dp0"
IF NOT "!output_on_screen!"=="False" (
@echo Elevated rights recived from UAC>CON
)
@echo Elevated rights recived from UAC
:--------------------------------------
rem Start the installation script
IF NOT "!output_on_screen!"=="False" (
@echo Starting CIRCLE Client install script>CON
@echo.>CON
)
@echo Starting CIRCLE Client install script
@echo.
IF NOT "!install_path!"=="" (
IF NOT "!output_on_screen!"=="False" (
@echo Python location got from input parameter.>CON
)
@echo Python location got from input parameter.
GOTO HASPYTHON
)
if "!architecture!"=="" (
call :SUB_ARCHITECTURE architecture
)
:PYTHON_CHECK_MODULE
rem Decide whether python 2.x is installed or not
SET "python_registry="
:PYTHON_CHECK
SET index=8
:loop
SET /a index-=1
IF %index% LSS 6 (
if "!architecture!"=="64" (
if "%python_registry%"=="" (
SET "python_registry=Wow6432Node\"
GOTO PYTHON_CHECK
) else (
GOTO NOPYTHON
)
) else (
GOTO NOPYTHON
)
)
SET version=2.%index%
SET @query="hklm\SOFTWARE\%python_registry%Python\PythonCore\!version!"
reg>nul query %@query% 2>nul
IF ERRORLEVEL 1 GOTO loop
IF ERRORLEVEL 0 GOTO HASPYTHON
pause
GOTO NOPYTHON
rem No 2.6+ Python is installed
:NOPYTHON
IF NOT "!output_on_screen!"=="False" (
@echo No 2.6^+ Python is detected on the system.>CON
)
@echo No 2.6^+ Python is detected on the system.
if "!architecture!"=="64" (
IF NOT "!output_on_screen!"=="False" (
@echo 64 bit system detected, commencing the install>CON
)
@echo 64 bit system detected, commencing the install
start "Python Installer" /WAIT ^"!running_directory!x64^\python-2.7.10.amd64.msi^"
GOTO NOWHASPYTHON
)
if "!architecture!"=="32" (
IF NOT "!output_on_screen!"=="False" (
@echo 32 bit system detected, commencing the install>CON
)
@echo 32 bit system detected, commencing the install
start "Python Installer" /WAIT ^"!running_directory!x86^\python-2.7.10.msi^"
GOTO NOWHASPYTHON
)
GOTO ERR
rem Subroutine to decide whether it is 32 or 64 bit
:SUB_ARCHITECTURE
rem Decide what architecture the system is using
if /i "%processor_architecture%"=="AMD64" (
SET %1=64
GOTO END
)
if /i "%PROCESSOR_ARCHITEW6432%"=="AMD64" (
SET %1=64
GOTO END
)
if /i "%processor_architecture%"=="x86" (
SET %1=32
GOTO END
)
GOTO ERR
rem Error within the installation
:ERR
IF NOT "!output_on_screen!"=="False" (
@echo Unsupported architecture! Please install files manually>CON
@echo Please visit: https://www.python.org/downloads/>CON
@echo Please visit: http://www.mozilla.org/en/firefox/new/>CON
pause
)
@echo Unsupported architecture! Please install files manually 1>&2
@echo Please visit: https://www.python.org/downloads/ 1>&2
@echo Please visit: http://www.mozilla.org/en/firefox/new/ 1>&2
GOTO END
rem The install program closed. Check whether the Python installation was successful
:NOWHASPYTHON
SET version=2.7
IF NOT "!output_on_screen!"=="False" (
@echo Python install finished, rechecking registry>CON
)
@echo Python install finished, rechecking registry
GOTO PYTHON_CHECK_MODULE
rem We have Python but let's check if it's in the PATH
:HASPYTHON
IF NOT "!output_on_screen!"=="False" (
@echo !version! Python is found, checking PATH variable>CON
)
@echo !version! Python is found, checking PATH variable
rem Check Python install path
IF "!install_path!"=="" (
for /f "tokens=2,*" %%a in ('reg query "hklm\SOFTWARE\%python_registry%Python\PythonCore\!version!\InstallPath"') do (
set install_path=%%b
)
)
rem Check whether python.exe is in the install path (python uninstall doesn't delete registry entrys)
if NOT EXIST "!install_path!python.exe" (
IF NOT "!output_on_screen!"=="False" (
@echo !version! Python was installed but it is NOT now. Restarting the search for python^^!>CON
)
@echo !version! Python was installed but it is NOT now. Restarting the search for python^^!
goto loop
) else (
IF "!python_registry!"=="Wow6432Node\" (
SET "architecture=32"
)
set test=%install_path:~0,-1%
call ^"!running_directory!inPath^" ^"test^" && (IF NOT "!output_on_screen!"=="False" (@echo !test! is already in PATH>CON) && @echo !test! is already in PATH) || (call ^"!running_directory!addPath^" ^"test^" & setx>nul PATH "%PATH%;!test!" /m & IF NOT "!output_on_screen!"=="False" ( @echo !test! set to PATH>CON) && @echo !test! set to PATH)
set test=%install_path%Scripts
call ^"!running_directory!inPath^" ^"test^" && (IF NOT "!output_on_screen!"=="False" (@echo !test! is already in PATH>CON) && @echo !test! is already in PATH) || (call ^"!running_directory!addPath^" ^"test^" & setx>nul PATH "%PATH%;!test!" /m & IF NOT "!output_on_screen!"=="False" ( @echo !test! set to PATH>CON) && @echo !test! set to PATH)
)
GOTO PIP_INSTALL
:INSTALL_EASY_INSTALL
IF NOT "!output_on_screen!"=="False" (
@echo Failed. Commencing installation of easy_install>CON
)
@echo Failed. Commencing installation of easy_install
CALL python ^"!running_directory!ez_setup.py^"
IF NOT "!output_on_screen!"=="False" (
@echo Done.>CON
)
@echo Done.
GOTO PIP_INSTALL
:PIP_INSTALL
IF NOT "!output_on_screen!"=="False" (
@echo Commencing PIP reinstall to solve compatibility issues>CON
)
@echo Commencing PIP reinstall to solve compatibility issues
CALL easy_install pip
IF ERRORLEVEL 1 GOTO INSTALL_EASY_INSTALL
SET "pip_program=requirements.txt"
IF NOT "!output_on_screen!"=="False" (
@echo Installing python modules>CON
)
@echo Installing python modules
GOTO PIP_PACKAGE_INSTALL
rem Check if the PIP package is installed or not
:PIP_PACKAGE_CHECK
IF NOT "!output_on_screen!"=="False" (
@echo.>CON
@echo Check whether !pip_program! is installed>CON
)
@echo.
@echo Check whether !pip_program! is installed
for /f "tokens=1,2 delims===" %%a in ('call python -m pip freeze') do (
if "%%a"=="!pip_program!" (
IF NOT "!output_on_screen!"=="False" (
@echo %%b !pip_program! is found>CON
)
@echo %%b !pip_program! is found
GOTO CHECK_PACKAGE_LIST
)
)
IF NOT "!output_on_screen!"=="False" (
@echo No !pip_program! version is found, commencing install>CON
)
@echo No !pip_program! version is found, commencing install
GOTO PIP_PACKAGE_INSTALL
rem Try to install the PIP packages via PIP
:PIP_PACKAGE_INSTALL
if "!pip_program!"=="pywin32" (
call python ^"!running_directory!pywin_installer.py^" ^-m !architecture!
) else (
call python -m pip install -r !pip_program!
)
goto CHECK_PACKAGE_LIST
:CHECK_PACKAGE_LIST
if "!pip_program!"=="requirements.txt" (
set "pip_program=pywin32"
goto PIP_PACKAGE_CHECK
)
goto FIN
rem Finish up the install
:FIN
rem Create folder if needed and set it to PATH
IF NOT "!output_on_screen!"=="False" (
@echo Checking wheter ^'!install_location!^\^' exists already>CON
)
@echo Checking wheter ^'!install_location!^\^' exists already
call ^"!running_directory!inPath^" ^"install_location^" && (IF NOT "!output_on_screen!"=="False" ( @echo !install_location! is already in PATH>CON) && @echo !install_location! is already in PATH) || (call ^"!running_directory!addPath^" ^"install_location^" & setx>nul PATH "%PATH%;!install_location!" /m & IF NOT "!output_on_screen!"=="False" ( @echo !install_location! set to PATH>CON) && @echo !install_location! set to PATH)
if not exist "!install_location!\" (
mkdir ^"!install_location!^"
)
@echo Checking wheter ^'!running_location!^\^' exists already
if not exist "!running_location!\" (
mkdir ^"!running_location!^"
)
if not exist "!running_location!\.rdp\" (
mkdir ^"!running_location!\.rdp^"
)
rem Copy the files to the folder
IF NOT "!output_on_screen!"=="False" (
@echo Copying files to ^'!install_location!^'>CON
)
@echo Copying files to ^'!install_location!^'
xcopy "!running_directory!cloud.py" "!install_location!\" /y
xcopy "!running_directory!cloud_connect_from_windows.py" "!install_location!\" /y
xcopy "!running_directory!win_install.py" "!install_location!\" /y
xcopy "!running_directory!windowsclasses.py" "!install_location!\" /y
xcopy "!running_directory!OrderedDict.py" "!install_location!\" /y
xcopy "!running_directory!putty.exe" "!install_location!\" /y
IF NOT "!output_on_screen!"=="False" (
@echo Done>CON
@echo.>CON
)
@echo Done
@echo.
IF NOT "!output_on_screen!"=="False" (
@echo Starting the python installation script>CON
)
@echo Starting the python installation script
call python ^"!running_directory!win_install.py^"!nx_install! ^-l "!install_location!\\"!website!
IF NOT "!output_on_screen!"=="False" (
@echo Done>CON
@echo Installation complete>CON
)
@echo Done
@echo Installation complete
GOTO END
:LCase
:UCase
:: Converts to upper/lower case variable contents
:: Syntax: CALL :UCase _VAR1 _VAR2
:: Syntax: CALL :LCase _VAR1 _VAR2
:: _VAR1 = Variable NAME whose VALUE is to be converted to upper/lower case
:: _VAR2 = NAME of variable to hold the converted value
:: Note: Use variable NAMES in the CALL, not values (pass "by reference")
SET _UCase=A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
SET _LCase=a b c d e f g h i j k l m n o p q r s t u v w x y z
SET _Lib_UCase_Tmp=!%1!
IF /I "%0"==":UCase" SET _Abet=%_UCase%
IF /I "%0"==":LCase" SET _Abet=%_LCase%
FOR %%Z IN (%_Abet%) DO SET _Lib_UCase_Tmp=!_Lib_UCase_Tmp:%%Z=%%Z!
SET %2=%_Lib_UCase_Tmp%
GOTO END
rem Subroutine to get the exact path out from a file location, but strip the file name
:Split
SET %2=%~dp1
GOTO END
:END
\ No newline at end of file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Pywin32 installer for CIRCLE client application
"""
import os
import sys
import subprocess
import windowsclasses
import argparse
if windowsclasses.DecideArchitecture.Is64Windows():
default_mode = '64'
else:
default_mode = '32'
def parse_arguments():
"""
Argument parser, based on argparse module
Keyword arguments:
@return args -- arguments given by console
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"-m", "--mode",
help="Python running mode (32bit or 64bit)", type=str,
required=True, choices=['32', '64'], default=default_mode)
args = parser.parse_args()
return args
def main():
"""
Main program
Job:
Install Pywin32 to the computer
"""
args = parse_arguments()
if args.mode != default_mode:
change_architect = True
else:
change_architect = False
if sys.hexversion < 0x02060000:
print "Not a 2.6+ version Python is running, commencing update"
subprocess.Popen(
"%s\\install.cmd" % os.path.dirname(
os.path.realpath(__file__)))
sys.exit(1)
else:
pywin32_version = str(219)
if sys.hexversion < 0x02070000:
if (windowsclasses.DecideArchitecture.Is64Windows()
and not change_architect):
subprocess.Popen(
"%s\\x64\\pywin32-%s.win-amd64-py2.6.exe" % (
os.path.dirname(os.path.realpath(__file__)),
pywin32_version)).wait()
else:
subprocess.Popen(
"%s\\x86\\pywin32-%s.win32-py2.6.exe" % (
os.path.dirname(os.path.realpath(__file__)),
pywin32_version)).wait()
elif sys.hexversion < 0x02080000:
if (windowsclasses.DecideArchitecture.Is64Windows()
and not change_architect):
subprocess.Popen(
"%s\\x64\\pywin32-%s.win-amd64-py2.7.exe" % (
os.path.dirname(os.path.realpath(__file__)),
pywin32_version)).wait()
else:
subprocess.Popen(
"%s\\x86\\pywin32-%s.win32-py2.7.exe" % (
os.path.dirname(os.path.realpath(__file__)),
pywin32_version)).wait()
else:
print "Unsupported Python version is found!"
if __name__ == "__main__":
main()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Windows installer for CIRCLE client application
"""
import os
import argparse
import subprocess
import pythoncom
import shutil
import sys
from win32com.shell import shell, shellcon
import windowsclasses
try:
from collections import * # noqa
except ImportError:
from OrderedDict import * # noqa
def parse_arguments():
"""
Argument parser, based on argparse module
Keyword arguments:
@return args -- arguments given by console
"""
parser = argparse.ArgumentParser()
if windowsclasses.DecideArchitecture.Is64Windows():
local_default = (windowsclasses.DecideArchitecture.GetProgramFiles64()
+ "\\CIRCLE\\")
else:
local_default = (windowsclasses.DecideArchitecture.GetProgramFiles32()
+ "\\CIRCLE\\")
if (not os.path.exists(local_default[:-1]) and
os.path.exists(os.environ['APPDATA'] + "\\CIRCLE")):
local_default = os.environ['APPDATA'] + "\\CIRCLE\\"
parser.add_argument(
"-l", "--location", help="Location of the client files in the system",
type=unicode, default=local_default, required=False)
parser.add_argument(
"-r", "--remove",
help="Remove installed files instead of creating them",
action="store_true", required=False)
parser.add_argument(
"-n", "--nx",
help="Whether we want to install the NX Client or not",
action="store_true", required=False)
parser.add_argument(
"-t", "--target",
help="If this is an URL icon, where should it point",
type=unicode, default="https://cloud.bme.hu/", required=False)
args = parser.parse_args()
return args
def custom_protocol_register(custom_protocol):
"""
Custom protocol register based on RegistryHandler module
Can raise AttributeError on wrongly provided dictionary chain
Keyword arguments:
@param dict_chain -- OrderedDictionary chain of the registry tree
"""
if not isinstance(custom_protocol, OrderedDict):
raise AttributeError
print "\t" + custom_protocol.iterkeys().next()
try:
custom_arguments = windowsclasses.Struct()
custom_arguments.registry = "HKCR"
handler = windowsclasses.RegistryHandler(custom_arguments)
handler.create_registry_from_dict_chain(custom_protocol, True)
print "\t\tDone!"
except:
raise
def main():
try:
args = parse_arguments()
shortcut = pythoncom.CoCreateInstance(
shell.CLSID_ShellLink,
None,
pythoncom.CLSCTX_INPROC_SERVER,
shell.IID_IShellLink
)
desktop_path = shell.SHGetFolderPath(
0, shellcon.CSIDL_DESKTOP, 0, 0)
if args.remove:
location = os.path.join(desktop_path, "CIRCLE Client")
if os.path.isfile("%s%s" % (location, ".lnk")):
os.remove("%s%s" % (location, ".lnk"))
print "%s%s file successfully removed" % (location, ".lnk")
if os.path.isfile("%s%s" % (location, ".url")):
os.remove("%s%s" % (location, ".url"))
print "%s%s file successfully removed" % (location, ".url")
for subdir, dirs, files in os.walk(args.location):
for current_file in files:
path = os.path.join(subdir, current_file)
fileName, fileExtension = os.path.splitext(path)
if ((fileExtension == '.pyc' or
fileExtension == '.lnk' or
fileExtension == '.url' or
fileExtension == '.log') and
"windowsclasses" not in fileName and
"uninstall" not in fileName):
os.remove(path)
print "%s file successfully removed" % path
else:
print "Creating custom URL protocol handler"
try:
custom_protocol = OrderedDict([
('circle', ["default",
"URL:circle Protocol",
"URL Protocol",
""]),
('circle\\URL Protocol', ""),
('circle\\DefaultIcon', args.location + "cloud.ico"),
('circle\\shell', {'open': {
'command': (
"\"%(prefix)s\pythonw.exe\""
" \"%(location)s"
"cloud.py\" " % {
'prefix': sys.exec_prefix,
'location': args.location
} + r'"%1"')
}})
])
custom_protocol_register(custom_protocol)
except:
print "Error! URL Protocol handler installation aborted!"
print "Creating icon in the installation folder"
location = os.path.join(desktop_path, "CIRCLE Client.url")
shortcut = open(location, "w")
shortcut.write('[InternetShortcut]\n')
shortcut.write('URL=' + args.target)
shortcut.close()
shutil.copy(location, args.location)
print "Icon successfully created"
except:
print "Unknown error occurred! Please contact the developers!"
if __name__ == "__main__":
main()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Place holder for all windows specific frequently used classes.
Currently here:
RegistryHandler - Registry based operations
DecideArchitecture - Accurate way to decide operating system architecture
"""
import os
import argparse
import errno
from _winreg import * # noqa
try:
from collections import * # noqa
except ImporError:
from OrderedDict import * # noqa
def parse_arguments():
"""
Argument parser, based on argparse module
Keyword arguments:
@return args -- arguments given by console
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"-g", "--global",
help="Whether we want to edit registry globally or just locally",
action="store_true")
parser.add_argument(
"-d", "--different",
help="Only handle the architecture specific registry area",
action="store_true")
parser.add_argument(
"-r", "--registry",
help="Which HKEY_* const registry type the program should use",
type=str, choices=['HKLM', 'HKCR', 'HKCU', 'HKU', 'HKPD', 'HKCC'],
default="HKLM")
args = parser.parse_args()
return args
def main():
return RegistryHandler(parse_arguments())
class Struct:
"""
Parameter bypassing struct
"""
pass
class ClientRegistry:
@staticmethod
def directory():
custom_param = Struct()
custom_param.registry = "HKCU"
handler = RegistryHandler(custom_param)
directory = None
try:
directory = handler.get_key_value(
"Software\CIRCLE Cloud Client", "running_directory")
except LookupError:
directory = os.path.dirname(os.path.abspath(__file__))
return directory
class RegistryHandler:
"""
Registry handling class, makes registry based queries and
manipulations easier.
This class can handle WOW64 based application differently and
similarly (default)
"""
def __init__(self, args=None):
"""Initialise RegistryHandler
Keyword arguments:
@param args -- The arguments that decide how the we should
handle the registry
args.registry -- What base registry should we use
(default: HKLM)
Raises AttributeError if not supported base registry type is
given
args.different -- Whether we handle registry redirection or not
"""
if args is None:
self.args = Struct()
self.args.different = None
self.args.registry = None
else:
if not hasattr(args, 'different'):
args.different = None
if not hasattr(args, 'registry'):
args.registry = None
self.args = args
if self.args.different is None:
self.args.different = False
if self.args.registry is None or self.args.registry == "HKLM":
self.args.registry = HKEY_LOCAL_MACHINE
elif self.args.registry == "HKCR":
self.args.registry = HKEY_CLASSES_ROOT
elif self.args.registry == "HKCU":
self.args.registry = HKEY_CURRENT_USER
elif self.args.registry == "HKU":
self.args.registry = HKEY_USERS
elif self.args.registry == "HKPD":
self.args.registry = HKEY_PERFORMANCE_DATA
elif self.args.registry == "HKCC":
self.args.registry = HKEY_CURRENT_CONFIG
else:
# print "Non supported registry type"
raise AttributeError
def connect_registry(self):
"""
Getting a registry open
Keyword arguments:
@return connected_registy -- Reference to the newly opened
registry
"""
return ConnectRegistry(None, self.args.registry)
def create_registry_from_dict_chain(
self, dict_chain, both=False, architect=KEY_WOW64_64KEY,
needed_rights=KEY_ALL_ACCESS):
""""
Create registry key and value multilevel tree by chained
dictionaries.
Can raise AttributeError if the provided dict chain isn't
correct
Keyword arguments:
@param key_value_chain -- The dict chain containing all the
information
@param both -- Whether create the registry in WOW64
node too
@param architect -- The current registry view (
only change it if we want to fill the
WOW6432 registry only [both = False],
on x64 windows)
@param needed_rights -- SAM rights to access the key
"""
if both and architect is KEY_WOW64_64KEY:
self.create_registry_from_dict_chain(
dict_chain, False, KEY_WOW64_32KEY, needed_rights)
if not DecideArchitecture.Is64Windows():
architect = 0
connected_registy = self.connect_registry()
if (isinstance(dict_chain, dict)
or isinstance(dict_chain, OrderedDict)):
for key, value in dict_chain.iteritems():
if isinstance(value, dict) or isinstance(value, OrderedDict):
temp_dict = OrderedDict()
for my_key, my_value in value.iteritems():
temp_dict[key + "\\" + my_key] = my_value
self.create_registry_from_dict_chain(
temp_dict, False, architect, needed_rights)
else:
if isinstance(value, list):
if len(value) % 2 != 0:
# print "Not enough member in the list"
raise AttributeError
else:
new_key = CreateKeyEx(
connected_registy, key, 0,
needed_rights | architect)
temp_dict = OrderedDict(
value[i:i + 2] for i in range(
0, len(value), 2))
for my_key, my_value in temp_dict.iteritems():
if my_key == "default":
my_key = None
SetValueEx(
new_key, my_key, 0, REG_SZ, my_value)
else:
new_key = CreateKeyEx(
connected_registy, key, 0,
needed_rights | architect)
SetValueEx(new_key, None, 0, REG_SZ, value)
else:
print("The provided attribute wasn't a dictionary chain")
raise AttributeError
def get_key(self, key_name, needed_rights=KEY_ALL_ACCESS):
"""
Getting a registry value by it's key's name
Can raise KeyError if key is not found in the registry
Keyword arguments:
@param key_name -- The specific key name of which value we
are interested in
@param needed_rights -- SAM rights to access the key
@return -- [key, architect]
key -- Reference to the opened
key handler
architect -- 0 for x86
KEY_WOW64_32KEY or
KEY_WOW64_64KEY
depending where we
found the key on x64
"""
connected_registy = self.connect_registry()
architect = 0
if DecideArchitecture.Is64Windows():
architect = KEY_WOW64_64KEY
try:
key = OpenKey(connected_registy, key_name, 0,
needed_rights | architect)
except WindowsError:
if DecideArchitecture.Is64Windows() and not self.args.different:
try:
architect = KEY_WOW64_32KEY
key = OpenKey(connected_registy, key_name,
0, needed_rights | architect)
except WindowsError:
raise KeyError
else:
raise KeyError
return [key, architect]
def get_key_values(
self, key_name, subkey_list, subroutine=False,
depth="subkeys"):
"""
Getting registry subkeys value by it's key's name and subkeys
name
Can raise LookupError exception if there are missing data
Can raise AttributeError exception if depth attribute is wrong
Keyword arguments:
@param key_name -- The specific key name of which subkey's
we are interested in
@param subkey_list -- List containing all the subkeys names
which values we are interested in
@param subroutine -- Whether suppress exception about not
having enough results or not
(default: False)
@param depth -- How depth the search should go for
[options: key, subkeys, all]
(default: subkeys)
@return results{} -- Dictionary with the subkey_name - value
combinations as keys and values
"""
if depth == "key":
int_depth = 0
elif depth == "subkeys":
int_depth = 1
elif depth == "all":
int_depth = 2
else:
raise AttributeError
try:
key_and_architect = self.get_key(key_name)
key = key_and_architect[0]
architect = key_and_architect[1]
except KeyError:
# print "%s doesn't exist in the registry" % key_name
raise LookupError
# print "%s found in the registry" % key_name
results = {}
if int_depth >= 1:
for i in xrange(0, QueryInfoKey(key)[0] - 1):
skey_name = EnumKey(key, i)
skey = OpenKey(key, skey_name, 0, KEY_ALL_ACCESS | architect)
if int_depth == 2 and QueryInfoKey(skey)[0] > 0:
for key, value in self.get_key_values(
skey_name, subkey_list, True, depth).iteritems():
results[key] = value
for subkey_name in subkey_list:
try:
results[subkey_name] = QueryValueEx(
skey, subkey_name)[0]
except OSError as e:
if e.errno == errno.ENOENT:
# print ("%s doesn't exist in this" % subkey_name
# " subkey")
pass
skey.Close()
if not results or len(results) != len(subkey_list):
for subkey_name in subkey_list:
try:
results[subkey_name] = QueryValueEx(key, subkey_name)[0]
except OSError as e:
pass
key.Close()
if len(results) != len(subkey_list):
# print "We are missing important variables"
raise LookupError
return results
def get_key_value(
self, key_name, subkey_name, subroutine=None, depth=None):
"""
This is a wrapper for the get_key_values to be easier to use
for single subkeys.
Getting registry subkey value by it's key's name and subkey
name
Keyword arguments:
@param key_name -- The specific key name of which subkey's
we are interested in
@param subkey_name -- The specific subkey name which value we
are interested in
@param subroutine -- can be found at: get_key_values
@param depth -- can be found at: get_key_values
@return value -- Value of the specific subkey
"""
try:
if subroutine is None:
return self.get_key_values(
key_name, [subkey_name])[subkey_name]
elif depth is None:
return self.get_key_values(
key_name, [subkey_name], subroutine)[subkey_name]
else:
return self.get_key_values(
key_name, [subkey_name], subroutine, depth)[subkey_name]
except:
raise
class DecideArchitecture:
"""
Helper class to get the true ProgramFiles directory.
This class doesn't depend on Phyton or Windows architecture.
"""
@staticmethod
def Is64Windows():
return 'PROGRAMFILES(X86)' in os.environ
@staticmethod
def GetProgramFiles32():
if DecideArchitecture.Is64Windows():
return os.environ['PROGRAMFILES(X86)']
else:
return os.environ['PROGRAMFILES']
@staticmethod
def GetProgramFiles64():
if DecideArchitecture.Is64Windows():
return os.environ['PROGRAMW6432']
else:
return None
@echo off
cls
setLocal EnableDelayedExpansion
rem Set where this file will install the rest of the files
IF NOT "%1"=="" (
SET "location=%1"
SET install_location=!location:"=!
) else (
SET "install_location=%APPDATA%\CIRCLE"
)
rem Set whether we want output info on screen or not
IF NOT "%2"=="" (
SET "output_on_screen=%2"
) else (
SET "output_on_screen=True"
)
rem Starting the uninstall script
IF NOT "!output_on_screen!"=="False" (
@echo Starting CIRCLE Client uninstall script>CON
@echo.>CON
)
@echo Starting CIRCLE Client uninstall script
@echo.
rem Get the running directory for later ease of use
SET running_directory=%~dp0
rem Check the install location whether it exists
if not exist "%install_location%\" (
IF NOT "!output_on_screen!"=="False" (
@echo Installation direcory not found^^! Please delete ^'CIRCLE^' direcory manually>CON
pause
)
@echo Installation direcory not found^^! Please delete ^'CIRCLE^' direcory manually 1>&2
goto end
)
IF NOT "!output_on_screen!"=="False" (
@echo Installation direcory found at ^'%install_location%^'>CON
)
@echo Installation direcory found at ^'%install_location%^'
rem Delete files and directory
IF NOT "!output_on_screen!"=="False" (
@echo Removing desktop icon>CON
)
@echo Removing desktop icon
call python "%install_location%\win_install.py" ^-r ^-l "%install_location%\\"
IF NOT "!output_on_screen!"=="False" (
@echo Done>CON
)
@echo Done
:end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment