|
2 | 2 | # Apache License 2.0, Copyright 2019 Tebel.Automation Private Limited
|
3 | 3 | # https://github.com/tebelorg/TagUI-Python/blob/master/LICENSE.txt
|
4 | 4 | __author__ = 'Ken Soh <[email protected]>'
|
5 |
| -__version__ = '1.13.0' |
| 5 | +__version__ = '1.14.0' |
6 | 6 |
|
7 | 7 | import subprocess
|
8 | 8 | import os
|
@@ -270,21 +270,37 @@ def setup():
|
270 | 270 | else:
|
271 | 271 | print('[TAGUI][ERROR] - unknown ' + platform.system() + ' operating system to setup TagUI')
|
272 | 272 | 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 |
273 | 284 |
|
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 |
276 | 290 |
|
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) |
282 | 295 |
|
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 |
288 | 304 |
|
289 | 305 | # set correct tagui folder for different operating systems
|
290 | 306 | if platform.system() == 'Windows':
|
@@ -539,6 +555,39 @@ def init(visual_automation = False, chrome_browser = True):
|
539 | 555 | _tagui_started = False
|
540 | 556 | return False
|
541 | 557 |
|
| 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 | + |
542 | 591 | def _ready():
|
543 | 592 | """internal function to check if tagui is ready to receive instructions after init() is called"""
|
544 | 593 |
|
|
0 commit comments