Skip to content

Commit

Permalink
#257 - tagui_location() for custom TagUI folder
Browse files Browse the repository at this point in the history
* add configurable installation directory to init and setup function
* add .tagui for custome path
* add custom folder ability to pack and update function
* add custom installation dir explanation
* add custom installation dir explanation
* modify installation dir explanation
* fix path composition
* implementation using a tagui_location()
* bump readme to v1.36

Co-authored-by: Ken Soh <kensoh@gmail.com>
  • Loading branch information
fi-do and kensoh authored May 23, 2021
1 parent 450a528 commit 3fae088
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# RPA for Python :snake:

[**v1.35**](https://github.com/tebelorg/RPA-Python/releases)&ensp;|&ensp;[**Use Cases**](#use-cases)&ensp;|&ensp;[**API Reference**](#api-reference)&ensp;|&ensp;[**About & Credits**](#about--credits)&ensp;|&ensp;[**PyCon Video**](https://www.youtube.com/watch?v=F2aQKWx_EAE)&ensp;|&ensp;[**Run in Colab**](https://colab.research.google.com/drive/13bQO6G_hzE1teX35a3NZ4T5K-ICFFdB5?usp=sharing)&ensp;|&ensp;[**Telegram Chat**](https://t.me/rpa_chat)
[**v1.36**](https://github.com/tebelorg/RPA-Python/releases)&ensp;|&ensp;[**Use Cases**](#use-cases)&ensp;|&ensp;[**API Reference**](#api-reference)&ensp;|&ensp;[**About & Credits**](#about--credits)&ensp;|&ensp;[**PyCon Video**](https://www.youtube.com/watch?v=F2aQKWx_EAE)&ensp;|&ensp;[**Run in Colab**](https://colab.research.google.com/drive/13bQO6G_hzE1teX35a3NZ4T5K-ICFFdB5?usp=sharing)&ensp;|&ensp;[**Telegram Chat**](https://t.me/rpa_chat)

>_This tool was previously known as TagUI for Python. [More details](https://github.com/tebelorg/RPA-Python/issues/100) on the name change, which is backward compatible so existing scripts written with `import tagui as t` and `t.function()` will still work._
Expand Down
36 changes: 25 additions & 11 deletions tagui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Apache License 2.0, Copyright 2019 Tebel.Automation Private Limited
# https://github.com/tebelorg/RPA-Python/blob/master/LICENSE.txt
__author__ = 'Ken Soh <opensource@tebel.org>'
__version__ = '1.35.0'
__version__ = '1.36.0'

import subprocess
import os
Expand Down Expand Up @@ -37,6 +37,12 @@
# to track the original directory when init() was called
_tagui_init_directory = ''

# to track location of TagUI (default user home folder)
if platform.system() == 'Windows':
_tagui_location = os.environ['APPDATA']
else:
_tagui_location = os.path.expanduser('~')

# delete tagui temp output text file to avoid reading old data
if os.path.isfile('rpa_python.txt'): os.remove('rpa_python.txt')

Expand Down Expand Up @@ -218,8 +224,8 @@ def _tagui_delta(base_directory = None):

def _patch_macos_pjs():
"""patch PhantomJS to latest v2.1.1 that plays well with new macOS versions"""
if platform.system() == 'Darwin' and not os.path.isdir(os.path.expanduser('~') + '/.tagui/src/phantomjs_old'):
original_directory = os.getcwd(); os.chdir(os.path.expanduser('~') + '/.tagui/src')
if platform.system() == 'Darwin' and not os.path.isdir(tagui_location() + '/.tagui/src/phantomjs_old'):
original_directory = os.getcwd(); os.chdir(tagui_location() + '/.tagui/src')
print('[RPA][INFO] - downloading latest PhantomJS to fix OpenSSL issue')
download('https://github.com/tebelorg/Tump/releases/download/v1.0.0/phantomjs-2.1.1-macosx.zip', 'phantomjs.zip')
if not os.path.isfile('phantomjs.zip'):
Expand All @@ -242,6 +248,12 @@ def debug(on_off = None):
if on_off is not None: _tagui_debug = on_off
return _tagui_debug

def tagui_location(location = None):
"""function to set location of TagUI installation"""
global _tagui_location
if location is not None: _tagui_location = location
return _tagui_location

def unzip(file_to_unzip = None, unzip_location = None):
"""function to unzip zip file to specified location"""
import zipfile
Expand All @@ -267,10 +279,7 @@ def setup():
"""function to setup TagUI to user home folder on Linux / macOS / Windows"""

# get user home folder location to setup tagui
if platform.system() == 'Windows':
home_directory = os.environ['APPDATA']
else:
home_directory = os.path.expanduser('~')
home_directory = tagui_location()

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

Expand Down Expand Up @@ -434,9 +443,9 @@ def init(visual_automation = False, chrome_browser = True, headless_mode = False

# get user home folder location to locate tagui executable
if platform.system() == 'Windows':
tagui_directory = os.environ['APPDATA'] + '/' + 'tagui'
tagui_directory = tagui_location() + '/' + 'tagui'
else:
tagui_directory = os.path.expanduser('~') + '/' + '.tagui'
tagui_directory = tagui_location() + '/' + '.tagui'

tagui_executable = tagui_directory + '/' + 'src' + '/' + 'tagui'
end_processes_executable = tagui_directory + '/' + 'src' + '/' + 'end_processes'
Expand Down Expand Up @@ -585,13 +594,13 @@ def pack():

# next download jython to tagui/src/sikulix folder (after init() it can be moved away)
if platform.system() == 'Windows':
tagui_directory = os.environ['APPDATA'] + '/' + 'tagui'
tagui_directory = tagui_location() + '/' + 'tagui'
# pack in Visual C++ MSVCR110.dll dependency from PHP for offline installation
vcredist_x86_url = 'https://raw.githubusercontent.com/tebelorg/Tump/master/vcredist_x86.exe'
if not download(vcredist_x86_url, tagui_directory + '/vcredist_x86.exe'):
return False
else:
tagui_directory = os.path.expanduser('~') + '/' + '.tagui'
tagui_directory = tagui_location() + '/' + '.tagui'
sikulix_directory = tagui_directory + '/' + 'src' + '/' + 'sikulix'
sikulix_jython_url = 'https://github.com/tebelorg/Tump/releases/download/v1.0.0/jython-standalone-2.7.1.jar'
if not download(sikulix_jython_url, sikulix_directory + '/' + 'jython-standalone-2.7.1.jar'):
Expand Down Expand Up @@ -662,6 +671,10 @@ def update():
base_directory = os.environ['APPDATA'] + '/tagui'
else:
base_directory = os.path.expanduser('~') + '/.tagui'
# uncomment below to define and use custom TagUI folder
#base_directory = 'your_full_path'
r.unzip('update.zip', base_directory + '/src')
if os.path.isfile('update.zip'): os.remove('update.zip')
Expand Down Expand Up @@ -696,6 +709,7 @@ def update():
if os.path.isfile('rpa_update.zip'): os.remove('rpa_update.zip')
print('[RPA][INFO] - done. copy or email update.py to your target computer and run')
print('[RPA][INFO] - python update.py to update RPA for Python to version ' + rpa_python_py)
print('[RPA][INFO] - to use custom TagUI folder, set base_directory in update.py')
return True

except Exception as e:
Expand Down

0 comments on commit 3fae088

Please sign in to comment.