├── AssetManagerKV.iml ├── config.py ├── assetEE.py ├── README.md ├── .gitignore ├── assetman.kv ├── LICENSE └── main.py /AssetManagerKV.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # colors dict 3 | import ee 4 | ee.Initialize() 5 | 6 | COLORS = {"red": (1, 0, 0, 0.8), 7 | "green": (0, 1, 0, 0.8), 8 | "blue": (0, 0, 1, 0.8), 9 | "black": (0, 0, 0, 0.8)} 10 | 11 | # coltype dict 12 | COLTYPE = {"Folder": COLORS["blue"], 13 | "ImageCollection": COLORS["green"], 14 | "Image": COLORS["red"], 15 | "unk": COLORS["black"]} 16 | 17 | USER = ee.data.getAssetRoots()[0]['id'] -------------------------------------------------------------------------------- /assetEE.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python2 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Created on Mon May 22 10:46:12 2017 5 | 6 | @author: Rodrigo E. Principe 7 | """ 8 | import ee 9 | ee.Initialize() 10 | 11 | def recrusive_delete_asset(assetId): 12 | try: 13 | content = ee.data.getList({'id':assetId}) 14 | except: 15 | return 16 | 17 | if len(content) == 0: 18 | ee.data.deleteAsset(assetId) 19 | else: 20 | for asset in content: 21 | path = asset['id'] 22 | ty = asset['type'] 23 | if ty == 'Image': 24 | ee.data.deleteAsset(path) 25 | else: 26 | recrusive_delete_asset(path) 27 | 28 | def getAssetAcl(assetId): 29 | return ee.data.getAssetAcl(assetId) 30 | 31 | def setAssetAcl(assetId, aclUpdate): 32 | return ee.data.setAssetAcl(assetId, aclUpdate) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Standalone Asset Manager for Google Earth Engine 2 | ###### *Made with kivy framework* 3 | #### It's main purpose is to perform some task over many assets, like delete or share. 4 | 5 | ## How to run it 6 | 7 | ### Install dependencies 8 | 1. [Kivy](https://kivy.org/docs/installation/installation.html) 9 | 2. [Google Earth Engine Python API](https://developers.google.com/earth-engine/python_install) 10 | 11 | *Tested only in Linux Mint 18 MATE (more coming..)* 12 | 13 | ### Download source code 14 | ######*(not binaries yet)* 15 | If you have [git](https://git-scm.com/) do: 16 | 17 | > git clone https://github.com/fitoprincipe/AssetManagerKV 18 | 19 | If you have not git and don't want to install it, download from [github](https://github.com/fitoprincipe/AssetManagerKV) 20 | 21 | ### Execute 22 | 23 | - Open a terminal (in Windows a *prompt* or *cmd*) 24 | - Navigate to the source code folder 25 | - Write: 26 | 27 | > python main.py 28 | 29 | ## Some aspects 30 | 31 | ### Colors 32 | 33 | - **Folders** are blue 34 | - **ImageCollection** are green 35 | - **Image** are red 36 | 37 | The header color is random 38 | 39 | ### Others 40 | - Refresh button don't work yet 41 | - When you delete or share several assets it seems like it hungs, and may hang, but usually does not hang -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Python template 3 | # Byte-compiled / optimized / DLL files 4 | __pycache__/ 5 | *.py[cod] 6 | *$py.class 7 | 8 | # C extensions 9 | *.so 10 | 11 | # Distribution / packaging 12 | .Python 13 | build/ 14 | develop-eggs/ 15 | dist/ 16 | downloads/ 17 | eggs/ 18 | .eggs/ 19 | lib/ 20 | lib64/ 21 | parts/ 22 | sdist/ 23 | var/ 24 | wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | .hypothesis/ 50 | 51 | # Translations 52 | *.mo 53 | *.pot 54 | 55 | # Django stuff: 56 | *.log 57 | .static_storage/ 58 | .media/ 59 | local_settings.py 60 | 61 | # Flask stuff: 62 | instance/ 63 | .webassets-cache 64 | 65 | # Scrapy stuff: 66 | .scrapy 67 | 68 | # Sphinx documentation 69 | docs/_build/ 70 | 71 | # PyBuilder 72 | target/ 73 | 74 | # Jupyter Notebook 75 | .ipynb_checkpoints 76 | 77 | # pyenv 78 | .python-version 79 | 80 | # celery beat schedule file 81 | celerybeat-schedule 82 | 83 | # SageMath parsed files 84 | *.sage.py 85 | 86 | # Environments 87 | .env 88 | .venv 89 | env/ 90 | venv/ 91 | ENV/ 92 | env.bak/ 93 | venv.bak/ 94 | 95 | # Spyder project settings 96 | .spyderproject 97 | .spyproject 98 | 99 | # Rope project settings 100 | .ropeproject 101 | 102 | # mkdocs documentation 103 | /site 104 | 105 | # mypy 106 | .mypy_cache/ 107 | 108 | # IDEA 109 | .idea 110 | AssetManagerKV.iml 111 | -------------------------------------------------------------------------------- /assetman.kv: -------------------------------------------------------------------------------- 1 | #:import ran random.random 2 | 3 | : 4 | # BoxLayout 5 | orientation: "vertical" 6 | Menu: 7 | id: menu 8 | 9 | : 10 | delete: delete_button 11 | share: share_button 12 | 13 | orientation: "vertical" 14 | size_hint: 1, None 15 | height: 40 16 | canvas: 17 | Color: 18 | rgba: ran(), ran(), ran(), 0.6 19 | Rectangle: 20 | pos: self.pos 21 | size: self.size 22 | Button: 23 | id: delete_button 24 | text: "Delete" 25 | size_hint: None, 1 26 | width: 100 27 | on_press: root.click_delete() 28 | Button: 29 | id: share_button 30 | text: "Share" 31 | size_hint: None, 1 32 | width: 100 33 | on_press: root.click_share() 34 | 35 | : 36 | size_hint: 1, 1 37 | 38 | : 39 | # BoxLayout 40 | orientation: "horizontal" 41 | 42 | : 43 | cols: 1 44 | size_hint: 1, None 45 | 46 |
: 47 | # sync between id and ObjectProperty 48 | exit: exit_id 49 | reload: reload_id 50 | check: check_id 51 | 52 | orientation: "horizontal" 53 | size_hint: 1, None 54 | # height: 30 55 | # height: lab_enc.height 56 | height: header_label.height if header_label.height > 30 else 30 57 | CheckBox: 58 | id: check_id 59 | size_hint: None, 1 60 | width: 20 61 | Label: 62 | id: header_label 63 | text: root.text 64 | font_size: 14 65 | size_hint: 0.8, 1 66 | text_size: self.width, None 67 | height: self.texture_size[1] 68 | Button: 69 | id: reload_id 70 | text: "reload" 71 | font_size: 12 72 | size_hint: None, None 73 | width: 50 74 | height: 25 75 | valign: "center" 76 | Button: 77 | id: exit_id 78 | text: "x" 79 | font_size: 20 80 | size_hint: None, None 81 | width: 20 82 | height: 25 83 | valign: "center" 84 | on_press: root.close(self) 85 | 86 | : 87 | orientation: "horizontal" 88 | size_hint: 1, None 89 | height: 30 90 | button: row_label 91 | size: row_label.size 92 | CheckBox: 93 | id: check_row 94 | size_hint: None, 1 95 | width: 20 96 | Button: 97 | id: row_label 98 | text: root.text 99 | background_color: root.background_color 100 | color: 1, 1, 1, 1 101 | halign: "left" 102 | on_release: root.add_column() 103 | 104 | # WRAPPING 105 | size_hint: 1, None 106 | text_size: root.width-check_row.width, None 107 | height: self.texture_size[1] + 10 108 | # size: self.texture_size[0]+10, self.texture_size[1]+10 109 | 110 | # on_release: print "textura:", self.texture_size, ",tam boton:", self.size, "text_size:", self.text_size, "root.size:", root.size 111 | 112 | : 113 | orientation: "vertical" 114 | Logger: 115 | id: box_log 116 | 117 | : 118 | cols: 1 119 | size_hint: 1, None 120 | 121 | : 122 | # BoxLayout 123 | orientation: "horizontal" 124 | size_hint: 1, None 125 | height: 150 126 | ScrollView: 127 | size_hint: 1, 1 128 | Label: 129 | id: logger 130 | text: root.text 131 | halign: "left" 132 | # from https://blog.kivy.org/2014/07/wrapping-text-in-kivys-label/ 133 | size_hint: 1, None 134 | text_size: self.width, None 135 | height: self.texture_size[1] 136 | BoxLayout: 137 | id: log_action 138 | size_hint: 1, 1 139 | 140 | : 141 | # BoxLayout 142 | orientation: "vertical" 143 | size_hint: 1, 1 144 | Label: 145 | text: root.message 146 | BoxLayout: 147 | orientation: "horizontal" 148 | Button: 149 | id: yes_button 150 | text: 'YES' 151 | on_press: root.on_yes(owner=self, root=root) 152 | Button: 153 | id: no_button 154 | text: 'NO' 155 | on_release: root.on_no(owner=self, root=root) 156 | 157 | : 158 | # BoxLayout 159 | orientation: "vertical" 160 | size_hint: 1, 1 161 | message: "customize with 'message' parameter" 162 | default_text: "" 163 | Label: 164 | id: label_input_box 165 | text: root.message 166 | TextInput: 167 | id: text_input 168 | text: root.default_text 169 | BoxLayout: 170 | orientation: 'horizontal' 171 | Button: 172 | id: accept_button 173 | text: 'accept' 174 | on_release: root.on_accept(owner=self, root=root) 175 | Button: 176 | id: cancel_button 177 | text: 'cancel' 178 | on_release: root.on_cancel(owner=self, root=root) 179 | 180 | : 181 | BoxLayout: 182 | width: 360 183 | size_hint: None, 1 184 | orientation: 'horizontal' 185 | CheckBox: 186 | id: read 187 | # size_hint_x: 0.1 188 | width: 20 189 | Label: 190 | text: 'read' 191 | halign: 'left' 192 | # size_hint_x: 0.4 193 | width: 100 194 | CheckBox: 195 | id: write 196 | # size_hint_x: 0.1 197 | width: 20 198 | Label: 199 | text: 'write' 200 | halign: 'left' 201 | # size_hint_x: 0.4 202 | width: 100 203 | CheckBox: 204 | id: remove 205 | # size_hint_x: 0.1 206 | width: 20 207 | Label: 208 | text: 'remove' 209 | halign: 'left' 210 | # size_hint_x: 0.4 211 | width: 100 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from kivy.app import App 4 | from kivy.uix.label import Label 5 | from kivy.uix.boxlayout import BoxLayout 6 | from kivy.uix.scrollview import ScrollView 7 | from kivy.uix.gridlayout import GridLayout 8 | from kivy.clock import Clock 9 | from kivy.uix.textinput import TextInput 10 | from kivy.uix.button import Button 11 | from kivy.uix.checkbox import CheckBox 12 | 13 | from kivy.properties import StringProperty, ObjectProperty, ListProperty, \ 14 | NumericProperty 15 | 16 | from functools import partial 17 | from kivy.logger import Logger as LoggerKV 18 | from assetEE import recrusive_delete_asset, getAssetAcl, setAssetAcl 19 | import ee 20 | import json 21 | 22 | try: 23 | from config import COLTYPE, USER 24 | except Exception as e: 25 | print(str(e)) 26 | 27 | # global variables to have access from any widget 28 | logbox = None 29 | logtext = None 30 | 31 | # Functions 32 | def on_checkbox_active(checkbox, value): 33 | """ Select all rows""" 34 | # checkbox.parent => Header() 35 | # Header().parent => AssetsContainer 36 | # AssetsContainer.children => Row (n), Header, Menu 37 | widgets_list = checkbox.parent.parent.children[0].children[0].children#[:-2] 38 | for widget in widgets_list: 39 | widget.check.active = value 40 | widget.children[1].active = value 41 | 42 | def add_column(): 43 | pass 44 | 45 | class Logger(BoxLayout): 46 | text = StringProperty() 47 | 48 | class YesNo(BoxLayout): 49 | message = StringProperty('') 50 | # pressed = NumericProperty(None) 51 | def __init__(self, **kwargs): 52 | super(YesNo, self).__init__(**kwargs) 53 | self.on_yes = kwargs.get('on_yes', self.on_yes) 54 | self.on_no = kwargs.get('on_no', self.on_no) 55 | 56 | def on_yes(self, **kwargs): 57 | pass 58 | 59 | def on_no(self, **kwargs): 60 | pass 61 | 62 | def remove(self): 63 | self.parent.remove_widget(self) 64 | 65 | class InputBox(BoxLayout): 66 | ''' General Input Box ''' 67 | message = StringProperty() 68 | default_text = StringProperty() 69 | def __init__(self, **kwargs): 70 | self.on_accept = kwargs.get('on_accept', self.on_accept) 71 | self.on_cancel = kwargs.get('on_cancel', self.on_cancel) 72 | super(InputBox, self).__init__(**kwargs) 73 | 74 | def on_accept(self, **kwargs): 75 | pass 76 | 77 | def on_cancel(self, **kwargs): 78 | pass 79 | 80 | def remove(self): 81 | self.parent.remove_widget(self) 82 | 83 | class ShareInput(InputBox): 84 | def __init__(self, **kwargs): 85 | super(ShareInput, self).__init__(**kwargs) 86 | 87 | 88 | class GlobalContainer(BoxLayout): 89 | def __init__(self, **kwargs): 90 | super(GlobalContainer, self).__init__(**kwargs) 91 | global logbox 92 | global logtext 93 | 94 | # redefine global variables 95 | log = self.ids["box_log"] 96 | logbox = log.ids["log_action"] 97 | logtext = log.ids["logger"] 98 | 99 | class Container(BoxLayout): 100 | """ This container is meant to change the layout direction to 101 | horizontal """ 102 | pass 103 | 104 | class Scrolling(ScrollView): 105 | pass 106 | 107 | class Column(BoxLayout): 108 | """ a Column contain a Menu Widget (in kv file) """ 109 | path = StringProperty(USER) # if no argument is passed, the root path is returned 110 | text = StringProperty() 111 | count = 0 112 | def __init__(self, **kwargs): 113 | super(Column, self).__init__(**kwargs) 114 | # Count Columns 115 | Column.count += 1 116 | self.assets_count = Column.count 117 | 118 | content = USER if self.path == USER else self.path.replace(USER, '') 119 | # Text for the column (name of the asset) 120 | self.text = '{} {}'.format(self.assets_count, content) 121 | # Menu is created on kv side 122 | 123 | # Create and add Header 124 | header = Header(text=self.text) 125 | header.check.bind(active=header.on_checkbox_active) 126 | self.add_widget(header) 127 | 128 | # Get content of the path 129 | try: 130 | path_data = ee.data.getList({'id':self.path}) 131 | except Exception as e: 132 | path_data = str(e) 133 | 134 | # Scroll 135 | scrolling = Scrolling() 136 | # Container 137 | container = AssetsContainer() 138 | 139 | # Add rows to the container 140 | for asset in path_data: 141 | # Get data 142 | path = asset['id'] 143 | # name = path.replace(USER, '') 144 | name = path.split('/')[-1] 145 | ty = asset['type'] 146 | # Create Row with data and add to container 147 | row = Row(path=path, text=name, asset_type = ty) 148 | container.add_widget(row) 149 | 150 | # Add container to scrolling 151 | scrolling.add_widget(container) 152 | 153 | # Add scrolling to the column 154 | self.add_widget(scrolling) 155 | 156 | class Menu(BoxLayout): 157 | """ The menu is placed above each list of folders and stay static. It has 158 | two buttons predefined in the kv file 159 | 160 | :param delete: a button to delete selected folders using AssetEE.delFolder 161 | :type delete: kivy.uix.Button 162 | """ 163 | delete = ObjectProperty() 164 | share = ObjectProperty() 165 | 166 | def __init__(self, **kwargs): 167 | super(Menu, self).__init__(**kwargs) 168 | 169 | def click_delete(self): 170 | """ callback function to delete all active rows """ 171 | # LoggerKV.info("delete") 172 | # get active rows 173 | active_rows = self.active() 174 | totaln = len(active_rows) 175 | 176 | if totaln == 0: # If no items selected 177 | logtext.text = 'No items selected to delete' 178 | return 179 | else: 180 | # log selected 181 | selected = 'Selected assets:\n{}'.format( 182 | '\n'.join([row.path for row in active_rows])) 183 | logtext.text = selected 184 | 185 | def yes(**kwargs): 186 | ''' function to call if press yes ''' 187 | logtext.text = '' 188 | for n, row in enumerate(active_rows): 189 | logtext.text = logtext.text + '\nErasing {} ({}/{})'.format( 190 | row.path, n+1, totaln) 191 | recrusive_delete_asset(row.path) 192 | row.parent.remove_widget(row) 193 | # logbox.remove_widget(yn) 194 | # Remove Widget 195 | kwargs['root'].remove() 196 | 197 | def no(**kwargs): 198 | ''' function to call if press no ''' 199 | # logbox.remove_widget(yn) 200 | # Remove Widget 201 | kwargs['root'].remove() 202 | logtext.text = 'No Asset Deleted' 203 | 204 | # Create YesNo Widget 205 | yn = YesNo(message='Are you sure you want to delete all selected assets?', 206 | on_yes=yes, on_no=no) 207 | logbox.add_widget(yn) 208 | 209 | def click_share(self): 210 | active_rows = self.active() 211 | totaln = len(active_rows) 212 | 213 | if totaln == 0: 214 | logtext.text = 'No items selected to share' 215 | return 216 | else: 217 | # log selected 218 | selected = 'Selected assets:\n{}'.format( 219 | '\n'.join([row.path for row in active_rows])) 220 | logtext.text = selected 221 | 222 | 223 | def accept(**kwargs): 224 | root = kwargs['root'] 225 | # Get checkboxes states 226 | read = root.ids['read'] 227 | state_read = read.active 228 | write = root.ids['write'] 229 | state_write = write.active 230 | remove = root.ids['remove'] 231 | state_remove = remove.active 232 | # get email 233 | email = root.ids['text_input'].text 234 | 235 | # yesno = YesNo(message='Are you sure you want to share the selected assets with {}?'.format(email)) 236 | 237 | # clear logtext 238 | log = '' 239 | logtext.text = log 240 | 241 | for n, row in enumerate(active_rows): 242 | acl = getAssetAcl(row.path) 243 | writers = acl['writers'] 244 | readers = acl['readers'] 245 | # read and write 246 | if state_read and state_write and not state_remove: 247 | readers.append(email) 248 | writers.append(email) 249 | log = log + '\n{} shared for read and write to {}'.format(row.path, email) 250 | # read 251 | elif state_read and not state_write and not state_remove: 252 | readers.append(email) 253 | log = log + '\n{} shared for read to {}'.format(row.path, email) 254 | # write 255 | elif state_write and not state_read and not state_remove: 256 | writers.append(email) 257 | log = log + '\n{} shared for write to {}'.format(row.path, email) 258 | # remove from writers 259 | elif state_write and not state_read and state_remove: 260 | if email in writers: 261 | writers.remove(email) 262 | log = log + '\n{} removed from writers'.format(row.path) 263 | else: 264 | log = log + '\n{} not in writers'.format(email) 265 | # remove from readers 266 | elif state_read and not state_write and state_remove: 267 | if email in readers: 268 | readers.remove(email) 269 | log = log + '\n{} removed from readers'.format(row.path) 270 | else: 271 | log = log + '\n{} not in readers'.format(email) 272 | # remove from readers and writers 273 | elif state_write and state_read and state_remove: 274 | if email in writers: 275 | writers.remove(email) 276 | log = log + '\n{} removed'.format(row.path) 277 | else: 278 | log = log + '\n{} not in readers or writers'.format(row.path) 279 | if email in readers: 280 | readers.remove(email) 281 | log = log + '\n{} removed from readers'.format(row.path) 282 | else: 283 | log = log + '\n{} not in assetAcl'.format(email) 284 | 285 | new = {'readers': readers, 286 | 'writers': writers} 287 | try: 288 | setAssetAcl(row.path, json.dumps(new)) 289 | logtext.text = log 290 | except: 291 | logtext.text = logtext.text +'\nFail sharing {}'.format(row.path) 292 | 293 | # Remove 294 | root.remove() 295 | 296 | def cancel(**kwargs): 297 | # Remove 298 | kwargs['root'].remove() 299 | logtext.text = 'Task Cancelled' 300 | 301 | # Create widget to specify share email address 302 | # input = InputBox( 303 | input = ShareInput( 304 | message='Select email to share assets', 305 | default_text='someone@mail.com', 306 | on_accept=accept, 307 | on_cancel=cancel 308 | ) 309 | logbox.add_widget(input) 310 | 311 | def active(self): 312 | """ Get active rows 313 | 314 | :return: a list of """ 315 | # Logger.info(rows) 316 | active_rows = [] 317 | 318 | columns = self.parent # a Column 319 | scrolling = columns.children[0] # a Scrolling 320 | asset_content = scrolling.children[0] # a AssetsContainer 321 | rows = asset_content.children # all rows 322 | 323 | for row in rows: 324 | check = row.check 325 | state = check.active 326 | if state: active_rows.append(row) 327 | 328 | return active_rows 329 | 330 | class LoggerLabel(GridLayout): 331 | def __init__(self, **kwargs): 332 | super(LoggerLabel, self).__init__(**kwargs) 333 | self.bind(minimum_height=self.setter('height')) # Makes the grid scroll into the scrollview 334 | 335 | class AssetsContainer(GridLayout): 336 | """ Assets container """ 337 | 338 | def __init__(self, **kwargs): 339 | """ Assets container """ 340 | super(AssetsContainer, self).__init__(**kwargs) 341 | self.bind(minimum_height=self.setter('height')) # Makes the grid scroll into the scrollview 342 | 343 | class Header(BoxLayout): 344 | """ The header is above the list of rows. Has a checkbox to select all 345 | children, a Label with the path name, and an X to close the Column""" 346 | 347 | # PROPERTIES 348 | text = StringProperty() 349 | exit = ObjectProperty() 350 | reload = ObjectProperty() 351 | check = ObjectProperty() 352 | 353 | def __init__(self, **kwargs): 354 | super(Header, self).__init__(**kwargs) 355 | 356 | def close(self, widget): 357 | t = widget.parent.text # text of self (Header) 358 | root = t.split(" ") # its a number and a path: 0 root 359 | 360 | # self.checkbox = self.ids['check_id'] 361 | # self.checkbox.bind(active=on_checkbox_active) 362 | 363 | if int(root[0]) > 1: 364 | column = widget.parent.parent # the Column 365 | container = column.parent # the Container 366 | container.remove_widget(column) 367 | else: 368 | logtext.text = "Can't close root folder" 369 | 370 | def on_checkbox_active(self, checkbox, value): 371 | """ Select all rows""" 372 | # checkbox.parent => Header() 373 | # Header().parent => AssetsContainer 374 | # AssetsContainer.children => Row (n), Header, Menu 375 | # widgets_list = checkbox.parent.parent.children[0].children[0].children#[:-2] 376 | columns = self.parent 377 | scrolling = columns.children[0] 378 | asset_container = scrolling.children[0] 379 | 380 | for widget in asset_container.children: 381 | widget.check.active = value 382 | widget.children[1].active = value 383 | 384 | class Row(BoxLayout): 385 | """ This Widget contains a and a CheckBox 386 | 387 | :param path: complete path of the asset 388 | :param asset_type: type of the asset 389 | :type asset_type: Image | ImageCollection | Folder 390 | """ 391 | path = StringProperty() 392 | asset_type = StringProperty() 393 | text = StringProperty() 394 | background_color = ListProperty() 395 | button = ObjectProperty() 396 | 397 | def __init__(self, **kwargs): 398 | """ This Widget contains a and a CheckBox 399 | 400 | :param path: complete path of the asset 401 | :param asset_type: type of the asset 402 | :type asset_type: Image | ImageCollection | Folder 403 | """ 404 | super(Row, self).__init__(**kwargs) 405 | self.check = self.ids["check_row"] 406 | self.thebutton = self.ids['row_label'] 407 | self.background_color = COLTYPE[self.asset_type] 408 | 409 | def create_column(self): 410 | """ Create a Column with the Row data """ 411 | try: 412 | return Column(path=self.path) 413 | except: 414 | return None 415 | 416 | def add_column(self): 417 | """ Add a column to the Container """ 418 | newcolumn = self.create_column() 419 | if self.parent and newcolumn: 420 | asset_container = self.parent # AssetContainer 421 | scroll = asset_container.parent # Scrolling 422 | column = scroll.parent # Column 423 | container = column.parent # Container 424 | container.add_widget(newcolumn) 425 | 426 | class AssetManApp(App): 427 | def __init__(self, **kwargs): 428 | super(AssetManApp, self).__init__(**kwargs) 429 | self.title = "Asset Manager KV ver 0.2beta" 430 | 431 | def close(self, instance): 432 | self.stop() 433 | 434 | def build(self): 435 | try: 436 | ee.Initialize() 437 | 438 | self.root = root = GlobalContainer() 439 | self.container = container = Container() 440 | 441 | # Root column 442 | root_column = Column() 443 | 444 | # Add root column to container 445 | container.add_widget(root_column) 446 | 447 | # Add container to global container 448 | root.add_widget(container) 449 | 450 | return root 451 | except Exception as e: 452 | label = Label(text=str(e)) 453 | return label 454 | 455 | if __name__ == "__main__": 456 | app = AssetManApp() 457 | app.run() --------------------------------------------------------------------------------