Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to define custom TagUI installation folder #207

Merged
merged 10 commits into from
May 23, 2021
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,13 @@ An element identifier helps to tell RPA for Python exactly which element on the
#### CORE FUNCTIONS
Function|Parameters|Purpose
:-------|:---------|:------
init()|visual_automation = False, chrome_browser = True|start TagUI, auto-setup on first run
init()|visual_automation = False, chrome_browser = True, installation_dir = "path"|start TagUI, auto-setup on first run
close()||close TagUI, Chrome browser, SikuliX
pack()||for deploying package without internet
pack()|installation_dir = "path"|for deploying package without internet
update()||for updating package without internet

>_to print and log debug info to rpa_python.log use debug(True), to switch off use debug(False)_
>_to print and log debug info to rpa_python.log use debug(True), to switch off use debug(False)._
>_to set custome installation path use r.init(installation_dir="/home/user/opt/.tagui")._

#### BASIC FUNCTIONS
Function|Parameters|Purpose
Expand Down
49 changes: 43 additions & 6 deletions tagui.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def unzip(file_to_unzip = None, unzip_location = None):
zip_file.close()
return True

def setup():
def setup(installation_dir = None):
"""function to setup TagUI to user home folder on Linux / macOS / Windows"""

# get user home folder location to setup tagui
Expand All @@ -256,6 +256,10 @@ def setup():
else:
home_directory = os.path.expanduser('~')

# override home folder when manual path is set
if installation_dir:
home_directory = installation_dir

print('[RPA][INFO] - setting up TagUI for use in your Python environment')

# special check for macOS - download() will fail due to no SSL certs for Python 3
Expand Down Expand Up @@ -308,6 +312,10 @@ def setup():
else:
tagui_directory = home_directory + '/' + '.tagui'

# override with custom dir
if installation_dir:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since home_directory = installation_dir is set above, this if block is not needed. The if else right above will take care of adding the appropriate name based on OS. Do note my comment below, it seems that the expectation of installation_dir is different in setup and init.

tagui_directory = installation_dir + '/' + '.tagui'

# overwrite tagui to .tagui folder for Linux / macOS

# first rename existing .tagui folder to .tagui_previous
Expand Down Expand Up @@ -437,7 +445,7 @@ def setup():

return True

def init(visual_automation = False, chrome_browser = True):
def init(visual_automation = False, chrome_browser = True, installation_dir = None):
"""start and connect to tagui process by checking tagui live mode readiness"""

global _process, _tagui_started, _tagui_id, _tagui_visual, _tagui_chrome, _tagui_init_directory
Expand All @@ -458,12 +466,21 @@ def init(visual_automation = False, chrome_browser = True):
else:
tagui_directory = os.path.expanduser('~') + '/' + '.tagui'

# check if custom installation path is set
if installation_dir:
if "tagui" in installation_dir:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it is expected that installation_dir contains tagui folder, but then installation_dir gets passed to setup function where .tagui is getting appended again.

print('[RPA][INFO] - It was detected to use a custom directory.')
tagui_directory = installation_dir
else:
print('[RPA][ERROR] - Please use path with target directory name tagui.')
sys.exit(1)

tagui_executable = tagui_directory + '/' + 'src' + '/' + 'tagui'
end_processes_executable = tagui_directory + '/' + 'src' + '/' + 'end_processes'

# if tagui executable is not found, initiate setup() to install tagui
if not os.path.isfile(tagui_executable):
if not setup():
if not setup(installation_dir):
# error message is shown by setup(), no need for message here
return False

Expand Down Expand Up @@ -586,19 +603,26 @@ def init(visual_automation = False, chrome_browser = True):
_tagui_started = False
return False

def pack():
def pack(installation_dir = None):
"""function to pack TagUI files for installation on an air-gapped computer without internet"""

print('[RPA][INFO] - pack() is to deploy RPA for Python to a computer without internet')
print('[RPA][INFO] - update() is to update an existing installation deployed from pack()')
print('[RPA][INFO] - detecting and zipping your TagUI installation to rpa_python.zip ...')

# check custom installation path
if installation_dir:
print('[RPA][INFO] - It was detected to use a custom directory as source for packing.')
if not os.path.isdir(installation_dir + "/src"):
print('[RPA][ERROR] - Your target destination is not a valid path.')
sys.exit(1)

# first make sure TagUI files have been downloaded and synced to latest stable delta files
global _tagui_started
if _tagui_started:
if not close():
return False
if not init(False, False):
if not init(False, False, installation_dir):
return False
if not close():
return False
Expand Down Expand Up @@ -677,11 +701,24 @@ def update():
update_zip_file.write(base64.b64decode(rpa_update_zip))
update_zip_file.close()

# unzip update.zip to tagui folder in user home directory
# check tagui path
if platform.system() == 'Windows':
base_directory = os.environ['APPDATA'] + '/tagui'
else:
base_directory = os.path.expanduser('~') + '/.tagui'

if len(sys.argv) == 2:
print('[RPA][INFO] - It was detected to use a custom directory for updating.')
if os.path.isdir(sys.argv[1]):
if "tagui" in sys.argv[1]:
base_directory = sys.argv[1]
else:
print('[RPA][ERROR] - Please use path with target directory name tagui.')
sys.exit(1)
else:
print('[RPA][ERROR] - Your target destination is not a valid path.')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we not exit in this case?


# unzip update.zip to tagui folder in target directory
r.unzip('update.zip', base_directory + '/src')
if os.path.isfile('update.zip'): os.remove('update.zip')

Expand Down