Skip to content

Commit 41fe9ac

Browse files
committed
#36 - deploy on PCs without internet
see issue #36 for details
1 parent 0c360b8 commit 41fe9ac

File tree

3 files changed

+69
-19
lines changed

3 files changed

+69
-19
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# TagUI for Python
44

5-
[**Use Cases**](#use-cases) | [**API Reference**](#api-reference) | [**About & Credits**](#about--credits) | [**v1.13**](https://github.com/tebelorg/TagUI-Python/releases)
5+
[**Use Cases**](#use-cases) | [**API Reference**](#api-reference) | [**About & Credits**](#about--credits) | [**v1.14**](https://github.com/tebelorg/TagUI-Python/releases)
66

77
![TagUI for Python demo in Jupyter notebook](https://raw.githubusercontent.com/tebelorg/Tump/master/tagui_python.gif)
88

@@ -16,7 +16,7 @@ To use TagUI for Python in Jupyter notebook, Python script or interactive shell
1616
import tagui as t
1717
```
1818

19-
To deploy in environments without internet access, join the discussion here -
19+
To deploy in environments without internet access, add your constraints here -
2020
```py
2121
t.init(); t.url('https://github.com/tebelorg/TagUI-Python/issues/36')
2222
```
@@ -61,7 +61,7 @@ t.init(visual_automation = True, chrome_browser = False)
6161
t.keyboard('[cmd][space]')
6262
t.keyboard('safari[enter]')
6363
t.keyboard('[cmd]t')
64-
t.keyboard('avengers[enter]')
64+
t.keyboard('joker[enter]')
6565
t.wait(2.5)
6666
t.snap('page.png', 'results.png')
6767
t.close()
@@ -96,11 +96,12 @@ Function|Parameters|Purpose
9696
init()|visual_automation = False, chrome_browser = True|start TagUI, auto-call setup() on first run
9797
close()||close TagUI, Chrome browser, SikuliX
9898
setup()||setup TagUI to user home folder
99+
pack()|(beta feature - [see this issue](https://github.com/tebelorg/TagUI-Python/issues/36))|for deployment without internet
99100

100101
#### DEBUG FUNCTIONS
101102
Function|Parameters|Purpose
102103
:-------|:---------|:------
103-
debug()|True or False|toggle debug mode, eg print and log debug info
104+
debug()|True or False|toggle debug mode, ie print and log debug info
104105
send()|tagui_instruction|send TagUI instruction to TagUI for execution
105106

106107
#### BASIC FUNCTIONS
@@ -163,7 +164,7 @@ TagUI is the number #1 open-source RPA software with thousands of active users.
163164

164165
Over the past 2 months I took on a daddy role full-time, taking care of my newborn baby girl and wife. In between nannying and caregiving, I decided to use my time pockets to create a Python package for TagUI. I would like to bring RPA into the heart of machine learning - the Python ecosystem. I hope that TagUI for Python and ML frameworks would be a match made in heaven, and `pip install tagui` would make lives easier for Python users.
165166

166-
Lastly, at only 1k lines of code (excluding comments), it would make my day to see developers of other languages porting this project over to their favourite programming language. It would be an interesting exercise and not too difficult, given the ample comments I sprinkled all over this single-file package (tagui.py), and its intuitive architecture.
167+
Lastly, at only ~1k lines of code, it would make my day to see developers of other languages porting this project over to their favourite programming language. It would be an interesting exercise and not too difficult, given the ample comments I sprinkled across this [single-file package (tagui.py)](https://github.com/tebelorg/TagUI-Python/blob/master/tagui.py), and its intuitive architecture.
167168

168169
![TagUI for Python architecture](https://raw.githubusercontent.com/tebelorg/Tump/master/TagUI-Python/architecture.png)
169170

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='tagui',
5-
version='1.13.0',
5+
version='1.14.0',
66
py_modules=['tagui'],
77
author='Ken Soh',
88
author_email='[email protected]',

tagui.py

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Apache License 2.0, Copyright 2019 Tebel.Automation Private Limited
33
# https://github.com/tebelorg/TagUI-Python/blob/master/LICENSE.txt
44
__author__ = 'Ken Soh <[email protected]>'
5-
__version__ = '1.13.0'
5+
__version__ = '1.14.0'
66

77
import subprocess
88
import os
@@ -270,21 +270,37 @@ def setup():
270270
else:
271271
print('[TAGUI][ERROR] - unknown ' + platform.system() + ' operating system to setup TagUI')
272272
return False
273+
274+
if not os.path.isfile('tagui_python.zip'):
275+
# primary installation pathway by downloading from internet, requiring internet access
276+
print('[TAGUI][INFO] - downloading TagUI (~200MB) and unzipping to below folder...')
277+
print('[TAGUI][INFO] - ' + home_directory)
278+
279+
# set tagui zip download url and download zip for respective operating systems
280+
tagui_zip_url = 'https://github.com/tebelorg/Tump/releases/download/v1.0.0/' + tagui_zip_file
281+
if not download(tagui_zip_url, home_directory + '/' + tagui_zip_file):
282+
# error message is shown by download(), no need for message here
283+
return False
273284

274-
print('[TAGUI][INFO] - downloading TagUI (~200MB) and unzipping to below folder...')
275-
print('[TAGUI][INFO] - ' + home_directory)
285+
# unzip downloaded zip file to user home folder
286+
unzip(home_directory + '/' + tagui_zip_file, home_directory)
287+
if not os.path.isfile(home_directory + '/' + 'tagui' + '/' + 'src' + '/' + 'tagui'):
288+
print('[TAGUI][ERROR] - unable to unzip TagUI to ' + home_directory)
289+
return False
276290

277-
# set tagui zip download url and download zip for respective operating systems
278-
tagui_zip_url = 'https://github.com/tebelorg/Tump/releases/download/v1.0.0/' + tagui_zip_file
279-
if not download(tagui_zip_url, home_directory + '/' + tagui_zip_file):
280-
# error message is shown by download(), no need for message here
281-
return False
291+
else:
292+
# secondary installation pathway by using the tagui_python.zip generated from pack()
293+
print('[TAGUI][INFO] - unzipping TagUI (~200MB) from tagui_python.zip to below folder...')
294+
print('[TAGUI][INFO] - ' + home_directory)
282295

283-
# unzip downloaded zip file to user home folder
284-
unzip(home_directory + '/' + tagui_zip_file, home_directory)
285-
if not os.path.isfile(home_directory + '/' + 'tagui' + '/' + 'src' + '/' + 'tagui'):
286-
print('[TAGUI][ERROR] - unable to unzip TagUI to ' + home_directory)
287-
return False
296+
import shutil
297+
shutil.move('tagui_python.zip', home_directory + '/' + tagui_zip_file)
298+
299+
if not os.path.isdir(home_directory + '/tagui'): os.mkdir(home_directory + '/tagui')
300+
unzip(home_directory + '/' + tagui_zip_file, home_directory + '/tagui')
301+
if not os.path.isfile(home_directory + '/' + 'tagui' + '/' + 'src' + '/' + 'tagui'):
302+
print('[TAGUI][ERROR] - unable to unzip TagUI to ' + home_directory)
303+
return False
288304

289305
# set correct tagui folder for different operating systems
290306
if platform.system() == 'Windows':
@@ -539,6 +555,39 @@ def init(visual_automation = False, chrome_browser = True):
539555
_tagui_started = False
540556
return False
541557

558+
def pack():
559+
"""function to pack TagUI files for installation on an air-gapped computer without internet"""
560+
561+
print('[TAGUI][INFO] - detecting and zipping your TagUI installation to tagui_python.zip ...')
562+
563+
# first make sure TagUI files have been downloaded and synced to latest stable delta files
564+
global _tagui_started
565+
if _tagui_started:
566+
if not close():
567+
return False
568+
if not init(False, False):
569+
return False
570+
if not close():
571+
return False
572+
573+
# next download jython to tagui/src/sikulix folder (after init() it can be moved away)
574+
if platform.system() == 'Windows':
575+
tagui_directory = os.environ['APPDATA'] + '/' + 'tagui'
576+
else:
577+
tagui_directory = os.path.expanduser('~') + '/' + '.tagui'
578+
sikulix_directory = tagui_directory + '/' + 'src' + '/' + 'sikulix'
579+
sikulix_jython_url = 'https://github.com/tebelorg/Tump/releases/download/v1.0.0/jython-standalone-2.7.1.jar'
580+
if not download(sikulix_jython_url, sikulix_directory + '/' + 'jython-standalone-2.7.1.jar'):
581+
return False
582+
583+
# next zip entire TagUI installation and save a copy of tagui.py to the current folder
584+
import shutil
585+
shutil.make_archive('tagui_python', 'zip', tagui_directory)
586+
shutil.copyfile(os.path.dirname(__file__) + '/tagui.py', 'tagui.py')
587+
588+
print('[TAGUI][INFO] - done. copy tagui_python.zip and tagui.py to your target computer.')
589+
print('[TAGUI][INFO] - then install and use with import tagui as t followed by t.init()')
590+
542591
def _ready():
543592
"""internal function to check if tagui is ready to receive instructions after init() is called"""
544593

0 commit comments

Comments
 (0)