Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
app_zip
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tarun.madamanchi
app_zip
Commits
da4b6674
Commit
da4b6674
authored
Jan 10, 2024
by
tarun2512
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
third commit
parent
d8ce502c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
135 additions
and
20 deletions
+135
-20
.env
.env
+1
-1
app_publish_script.py
app_publish_script.py
+134
-19
No files found.
.env
View file @
da4b6674
MONGO_URI=mongodb://iLens:iLens%231234@20.83.1.150:2717/?authMechanism=DEFAULT&directConnection=true
BASE_URI=https://dmpc.demo.rockwellautomation.com/
LOGIN_TOKEN=c
a2b218efefe4a1cbf6c79f2e361691c
LOGIN_TOKEN=c
eac9fbbbd14449286862bc1e5d54dd6
USER_ID=fpWx7Aw4NJzzXWxcE6w5dU
PROJECT_ID=project_448
APP_NAME=FT Energy Manager
...
...
app_publish_script.py
View file @
da4b6674
...
...
@@ -50,6 +50,11 @@ class Connection(Database):
self
.
category_apps
=
self
.
configuration
[
"category_apps"
]
self
.
dashboard_category
=
self
.
widget
[
"category"
]
self
.
widget_col
=
self
.
widget
[
"widget"
]
self
.
units
=
self
.
configuration
[
"units"
]
self
.
units_group
=
self
.
configuration
[
"unit_group"
]
self
.
tags
=
self
.
configuration
[
"tags"
]
self
.
tag_groups
=
self
.
configuration
[
"tag_groups"
]
self
.
tag_category
=
self
.
configuration
[
"tag_category"
]
def
iterate_through_children_mapping
(
each_children_obj
,
required_ids
,
required_type
):
...
...
@@ -117,12 +122,12 @@ def dashboard_ids_fetch(children_data):
return
module_ids
def
dashboard_categories_zip
(
dashboard_category_ids
,
folder_path
,
prefix
=
None
):
def
dashboard_categories_zip
(
dashboard_category_ids
,
folder_path
,
pr
oject_id
,
pr
efix
=
None
):
connection
=
Connection
(
prefix
=
prefix
)
database
=
Database
(
prefix
=
prefix
)
dashboard_category_details
=
list
(
connection
.
dashboard_category
.
find
(
{
"dashboard_category_id"
:
{
"$in"
:
dashboard_category_ids
},
"project_id"
:
pr
efix
},
{
"_id"
:
0
}
{
"dashboard_category_id"
:
{
"$in"
:
dashboard_category_ids
},
"project_id"
:
pr
oject_id
},
{
"_id"
:
0
}
)
)
dashboard_category_folder
=
f
"{database.widget.name}.category"
...
...
@@ -134,19 +139,19 @@ def dashboard_categories_zip(dashboard_category_ids, folder_path, prefix=None):
file
.
close
()
def
dashboard_zip
(
dashboard_ids
,
folder_path
,
prefix
=
None
):
def
dashboard_zip
(
dashboard_ids
,
folder_path
,
pr
oject_id
,
pr
efix
=
None
):
connection
=
Connection
(
prefix
=
prefix
)
database
=
Database
(
prefix
=
prefix
)
dashboard_details
=
list
(
connection
.
dashboard
.
find
(
{
"dashboard_id"
:
{
"$in"
:
dashboard_ids
},
"project_id"
:
pr
efix
},
{
"_id"
:
0
}
{
"dashboard_id"
:
{
"$in"
:
dashboard_ids
},
"project_id"
:
pr
oject_id
},
{
"_id"
:
0
}
)
)
widget_ids
,
dashboard_categories_list
=
[],
[]
for
dashboard
in
dashboard_details
:
widget_ids
.
extend
(
dashboard
.
get
(
"widget_order"
))
dashboard_categories_list
.
append
(
dashboard
.
get
(
"category"
))
dashboard_categories_zip
(
dashboard_categories_list
,
folder_path
,
prefix
)
dashboard_categories_zip
(
dashboard_categories_list
,
folder_path
,
pr
oject_id
,
pr
efix
)
dashboard_folder
=
f
"{database.widget.name}.dashboard"
dashboard_data_folder_path
=
os
.
path
.
join
(
folder_path
,
dashboard_folder
)
os
.
makedirs
(
dashboard_data_folder_path
)
...
...
@@ -157,14 +162,124 @@ def dashboard_zip(dashboard_ids, folder_path, prefix=None):
return
list
(
set
(
widget_ids
))
def
widget_zip
(
widget_ids
,
folder_path
,
prefix
=
None
):
def
tag_category
(
tag_category_ids
,
folder_path
,
project_id
,
prefix
=
None
):
connection
=
Connection
(
prefix
=
prefix
)
database
=
Database
(
prefix
=
prefix
)
tag_category_details
=
list
(
connection
.
tag_category
.
find
(
{
"tag_category_id"
:
{
"$in"
:
tag_category_ids
},
"project_id"
:
project_id
},
{
"_id"
:
0
}
)
)
tag_category_folder
=
f
"{database.configuration.name}.tag_category"
tag_category_data_folder_path
=
os
.
path
.
join
(
folder_path
,
tag_category_folder
)
os
.
makedirs
(
tag_category_data_folder_path
)
app_data_file_path
=
os
.
path
.
join
(
tag_category_data_folder_path
,
f
"{tag_category_folder}.json"
)
with
open
(
app_data_file_path
,
'w'
)
as
file
:
json
.
dump
(
tag_category_details
,
file
)
file
.
close
()
def
tag_group
(
tag_group_ids
,
folder_path
,
project_id
,
prefix
=
None
):
connection
=
Connection
(
prefix
=
prefix
)
database
=
Database
(
prefix
=
prefix
)
tag_group_details
=
list
(
connection
.
tag_groups
.
find
(
{
"id"
:
{
"$in"
:
tag_group_ids
},
"project_id"
:
project_id
},
{
"_id"
:
0
}
)
)
tag_group_folder
=
f
"{database.configuration.name}.tag_groups"
tag_group_data_folder_path
=
os
.
path
.
join
(
folder_path
,
tag_group_folder
)
os
.
makedirs
(
tag_group_data_folder_path
)
app_data_file_path
=
os
.
path
.
join
(
tag_group_data_folder_path
,
f
"{tag_group_folder}.json"
)
with
open
(
app_data_file_path
,
'w'
)
as
file
:
json
.
dump
(
tag_group_details
,
file
)
file
.
close
()
def
tag_zip
(
parameter_ids
,
folder_path
,
project_id
,
prefix
=
None
):
connection
=
Connection
(
prefix
=
prefix
)
database
=
Database
(
prefix
=
prefix
)
parameter_details
=
list
(
connection
.
tags
.
find
(
{
"id"
:
{
"$in"
:
parameter_ids
},
"project_id"
:
project_id
},
{
"_id"
:
0
}
)
)
tag_group_ids
,
tag_category_ids
=
[],
[]
for
tag
in
parameter_details
:
tag_group_ids
.
append
(
tag
.
get
(
"tag_group_id"
))
tag_category_ids
.
append
(
tag
.
get
(
"tag_category_id"
))
tag_group
(
tag_group_ids
,
folder_path
,
project_id
,
prefix
)
tag_category
(
tag_category_ids
,
folder_path
,
project_id
,
prefix
)
tags_folder
=
f
"{database.configuration.name}.tags"
tags_data_folder_path
=
os
.
path
.
join
(
folder_path
,
tags_folder
)
os
.
makedirs
(
tags_data_folder_path
)
app_data_file_path
=
os
.
path
.
join
(
tags_data_folder_path
,
f
"{tags_folder}.json"
)
with
open
(
app_data_file_path
,
'w'
)
as
file
:
json
.
dump
(
parameter_details
,
file
)
file
.
close
()
def
unit_group_zip
(
unit_group_ids
,
folder_path
,
project_id
,
prefix
=
None
):
connection
=
Connection
(
prefix
=
prefix
)
database
=
Database
(
prefix
=
prefix
)
unit_group_details
=
list
(
connection
.
units_group
.
find
(
{
"id"
:
{
"$in"
:
list
(
set
(
unit_group_ids
))},
"project_id"
:
project_id
},
{
"_id"
:
0
}
)
)
unit_group_folder
=
f
"{database.configuration.name}.unit_group"
unit_group_data_folder_path
=
os
.
path
.
join
(
folder_path
,
unit_group_folder
)
os
.
makedirs
(
unit_group_data_folder_path
)
app_data_file_path
=
os
.
path
.
join
(
unit_group_data_folder_path
,
f
"{unit_group_folder}.json"
)
with
open
(
app_data_file_path
,
'w'
)
as
file
:
json
.
dump
(
unit_group_details
,
file
)
file
.
close
()
def
units_zip
(
unit_ids
,
folder_path
,
project_id
,
prefix
=
None
):
connection
=
Connection
(
prefix
=
prefix
)
database
=
Database
(
prefix
=
prefix
)
unit_details
=
list
(
connection
.
units
.
find
(
{
"id"
:
{
"$in"
:
unit_ids
},
"project_id"
:
project_id
},
{
"_id"
:
0
}
)
)
unit_group_ids
=
[]
for
unit
in
unit_details
:
unit_group_ids
.
append
(
unit
.
get
(
"unit_group_id"
))
unit_group_zip
(
unit_group_ids
,
folder_path
,
project_id
,
prefix
)
units_folder
=
f
"{database.configuration.name}.units"
units_data_folder_path
=
os
.
path
.
join
(
folder_path
,
units_folder
)
os
.
makedirs
(
units_data_folder_path
)
app_data_file_path
=
os
.
path
.
join
(
units_data_folder_path
,
f
"{units_folder}.json"
)
with
open
(
app_data_file_path
,
'w'
)
as
file
:
json
.
dump
(
unit_details
,
file
)
file
.
close
()
def
find_units_and_parameters
(
widget_details
):
unit_id_list
=
[]
parameter_id_list
=
[]
for
each_widget
in
widget_details
:
chart_options
=
each_widget
[
"widget_data"
][
"cData"
][
"chartOptions"
]
if
chart_options
.
get
(
"yaxis"
):
for
data
in
chart_options
.
get
(
"yaxis"
):
unit_id_list
.
append
(
data
.
get
(
"unitInfo"
,
{})
.
get
(
"value"
))
parameter_id_list
.
append
(
data
.
get
(
"tag"
,
{})
.
get
(
"value"
))
return
unit_id_list
,
parameter_id_list
def
widget_zip
(
widget_ids
,
folder_path
,
project_id
,
prefix
=
None
):
connection
=
Connection
(
prefix
=
prefix
)
database
=
Database
(
prefix
=
prefix
)
widget_details
=
list
(
connection
.
widget_col
.
find
(
{
"widget_id"
:
{
"$in"
:
widget_ids
},
"project_id"
:
pr
efix
},
{
"_id"
:
0
}
{
"widget_id"
:
{
"$in"
:
widget_ids
},
"project_id"
:
pr
oject_id
},
{
"_id"
:
0
}
)
)
unit_ids
,
parameter_ids
=
find_units_and_parameters
(
widget_details
)
units_zip
(
unit_ids
,
folder_path
,
project_id
,
prefix
)
tag_zip
(
parameter_ids
,
folder_path
,
project_id
,
prefix
)
widget_folder
=
f
"{database.widget.name}.widget"
widget_data_folder_path
=
os
.
path
.
join
(
folder_path
,
widget_folder
)
os
.
makedirs
(
widget_data_folder_path
)
...
...
@@ -174,12 +289,12 @@ def widget_zip(widget_ids, folder_path, prefix=None):
file
.
close
()
def
app_category_zip
(
app_data
,
folder_path
,
prefix
=
None
):
def
app_category_zip
(
app_data
,
folder_path
,
pr
oject_id
,
pr
efix
=
None
):
connection
=
Connection
(
prefix
=
prefix
)
database
=
Database
(
prefix
=
prefix
)
app_category_details
=
list
(
connection
.
category_apps
.
find
(
{
"app_category_id"
:
app_data
.
get
(
"app_category_id"
),
"project_id"
:
pr
efix
},
{
"_id"
:
0
}
{
"app_category_id"
:
app_data
.
get
(
"app_category_id"
),
"project_id"
:
pr
oject_id
},
{
"_id"
:
0
}
)
)
app_category_folder
=
f
"{database.configuration.name}.category_apps"
...
...
@@ -197,10 +312,10 @@ def modify_app_data(app_data):
app_data
[
"access_list"
][
"access_groups"
]
=
[]
def
dashboard_image_zip
(
dashboard_ids
,
folder_path
,
prefix
=
None
):
def
dashboard_image_zip
(
dashboard_ids
,
folder_path
,
pr
oject_id
,
pr
efix
=
None
):
database
=
Database
(
prefix
=
prefix
)
for
dashboard_id
in
dashboard_ids
:
image_url
=
f
"{dashboard_image_url}{dashboard_id}&project_id={pr
efix
}&lastmod={time.time() * 1000}"
image_url
=
f
"{dashboard_image_url}{dashboard_id}&project_id={pr
oject_id
}&lastmod={time.time() * 1000}"
with
httpx
.
Client
()
as
client
:
response
=
client
.
get
(
url
=
image_url
,
...
...
@@ -240,7 +355,7 @@ def app_image_zip(images, folder_path):
print
(
f
"Failed to download image. Status code: {response.status_code}"
)
def
app_zip
(
app_name
,
prefix
=
None
):
def
app_zip
(
app_name
,
pr
oject_id
,
pr
efix
=
None
):
connection
=
Connection
(
prefix
=
prefix
)
database
=
Database
(
prefix
=
prefix
)
folder_path
=
os
.
path
.
join
(
BASE_PATH
,
MOUNT_DIR
,
app_name
)
...
...
@@ -249,17 +364,17 @@ def app_zip(app_name, prefix=None):
lookups
=
app_data
.
get
(
"lookups"
,
[])
lookup_details
=
list
(
connection
.
lookup_table
.
find
(
{
"lookup_name"
:
{
"$in"
:
lookups
},
"project_id"
:
pr
efix
},
{
"_id"
:
0
}
{
"lookup_name"
:
{
"$in"
:
lookups
},
"project_id"
:
pr
oject_id
},
{
"_id"
:
0
}
)
)
dashboard_ids_publish
=
dashboard_ids_fetch
(
app_data
.
get
(
"children"
,
[]))
widget_ids
=
dashboard_zip
(
dashboard_ids_publish
,
folder_path
,
prefix
)
dashboard_image_zip
(
dashboard_ids_publish
,
folder_path
,
prefix
)
widget_zip
(
widget_ids
,
folder_path
,
prefix
)
widget_ids
=
dashboard_zip
(
dashboard_ids_publish
,
folder_path
,
pr
oject_id
,
pr
efix
)
dashboard_image_zip
(
dashboard_ids_publish
,
folder_path
,
pr
oject_id
,
pr
efix
)
widget_zip
(
widget_ids
,
folder_path
,
pr
oject_id
,
pr
efix
)
images
=
{
'app_image'
:
app_data
.
get
(
"meta"
,
{})
.
get
(
"image"
,
{})
.
get
(
"file_name"
,
""
),
'app_logo'
:
app_data
.
get
(
"meta"
,
{})
.
get
(
"app_logo"
,
{})
.
get
(
"file_name"
,
""
)}
app_category_zip
(
app_data
,
folder_path
,
prefix
)
app_category_zip
(
app_data
,
folder_path
,
pr
oject_id
,
pr
efix
)
modify_app_data
(
app_data
)
app_image_zip
(
images
,
folder_path
)
app_data_folder
=
f
"{database.configuration.name}.customer_apps"
...
...
@@ -276,7 +391,7 @@ def app_zip(app_name, prefix=None):
lookup_data_file_path
=
os
.
path
.
join
(
lookup_data_folder_path
,
f
"{lookup_data_folder}.json"
)
with
open
(
lookup_data_file_path
,
'w'
)
as
file
:
json
.
dump
(
lookup_details
,
file
)
zip_folder
(
folder_path
,
app_name
)
zip_folder
(
folder_path
,
folder_path
)
shutil
.
rmtree
(
folder_path
)
...
...
@@ -285,4 +400,4 @@ def zip_folder(folder_path, zip_filename):
if
__name__
==
"__main__"
:
app_zip
(
APP_NAME
,
PREFIX
)
app_zip
(
APP_NAME
,
PR
OJECT_ID
,
PR
EFIX
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment