Newer
Older
# -*- coding: utf-8 -*-
"""
***************************************************************************
deploy.py
Script to build the HUB-TimeSeriesViewer from Repository code
---------------------
Date : September 2017
Copyright : (C) 2017 by Benjamin Jakimow
Email : benjamin.jakimow@geo.hu-berlin.de
***************************************************************************
* *
* 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
import os, sys, re, shutil, zipfile, datetime
from timeseriesviewer import DIR_REPO
from timeseriesviewer.utils import file_search, jp
import timeseriesviewer
DIR_BUILD = jp(DIR_REPO, 'build')
DIR_DEPLOY = jp(DIR_REPO, 'deploy')
#list of deploy options:
# ZIP - add zipped plugin to DIR_DEPLOY
# UNZIPPED - add the non-zipped plugin to DIR_DEPLOY
DEPLOY_OPTIONS = ['ZIP', 'UNZIPPED']
ADD_TESTDATA = True
#directories below the <enmapbox-repository> folder whose content is to be copied without filtering
PLAIN_COPY_SUBDIRS = ['site-packages']
########## End of config section
timestamp = ''.join(np.datetime64(datetime.datetime.now()).astype(str).split(':')[0:-1])
timestamp = re.sub('[-T]','', timestamp)
v = timeseriesviewer.VERSION.split('.')
buildID = '{}.{}.{}'.format(v[0], v[1], timestamp)
timeseriesviewer.VERSION = buildID
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
dirBuildPlugin = jp(DIR_BUILD, 'timeseriesviewerplugin')
def rm(p):
"""
Remove files or directory 'p'
:param p: path of file or directory to be removed.
"""
if os.path.isfile(p):
os.remove(p)
elif os.path.isdir(p):
shutil.rmtree(p)
def cleanDir(d):
"""
Remove content from directory 'd'
:param d: directory to be cleaned.
"""
assert os.path.isdir(d)
for root, dirs, files in os.walk(d):
for p in dirs + files: rm(jp(root,p))
break
def mkDir(d, delete=False):
"""
Make directory.
:param d: path of directory to be created
:param delete: set on True to delete the directory contents, in case the directory already existed.
"""
if delete and os.path.isdir(d):
cleanDir(d)
if not os.path.isdir(d):
os.makedirs(d)
if __name__ == "__main__":
#the directory to build the "enmapboxplugin" folder
DIR_DEPLOY = jp(DIR_REPO, 'deploy')
# DIR_DEPLOY = r'E:\_EnMAP\temp\temp_bj\enmapbox_deploys\most_recent_version'
import make
make.updateMetadataTxt()
#update version
p = timeseriesviewer.__file__
with open(p,'r') as file:
lines = file.readlines()
found = False
for i, line in enumerate(lines):
if re.search(r'VERSION = \'{}\.{}.*'.format(v[0],v[1]), line):
lines[i] = 'VERSION = \'{}\'\n'.format(buildID)
found = True
break
assert found
with open(p, 'w') as file:
file.writelines(lines)
cfg = pb_tool.get_config(pathCfg)
cdir = os.path.dirname(pathCfg)
dirPlugin = jp(DIR_DEPLOY, pluginname)
os.chdir(cdir)

Benjamin Jakimow
committed
make.updateMetadataTxt()
#1. clean an existing directory = the timeseriesviewer folder
#2. Compile. Basically call pyrcc to create the resources.rc file
#I don't know how to call this from pure python
pb_tool.compile_files(cfg)
#3. Deploy = write the data to the new enmapboxplugin folder
pb_tool.deploy_files(pathCfg, DIR_DEPLOY, quick=True, confirm=False)
#4. As long as we can not specify in the pb_tool.cfg which file types are not to deploy,
# we need to remove them afterwards.
# issue: https://github.com/g-sherman/plugin_build_tool/issues/5
print('Remove files...')
for f in file_search(DIR_DEPLOY, re.compile('(svg|pyc)$'), recursive=True):
os.remove(f)
for d in file_search(DIR_DEPLOY, '__pycache__', recursive=True, directories=True):
os.removedirs(d)
#5. create a zip
print('Create zipfile...')
from timeseriesviewer.utils import zipdir
pathZip = jp(DIR_DEPLOY, '{}.{}.QGIS3.zip'.format(pluginname,buildID))
zipdir(dirPlugin, pathZip)
#os.chdir(dirPlugin)
#shutil.make_archive(pathZip, 'zip', '..', dirPlugin)

benjamin.jakimow@geo.hu-berlin.de
committed