xlwings-utils 0.0.0__tar.gz → 0.0.0.post0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of xlwings-utils might be problematic. Click here for more details.

@@ -0,0 +1,43 @@
1
+ Metadata-Version: 2.4
2
+ Name: xlwings_utils
3
+ Version: 0.0.0.post0
4
+ Summary: xlwings_utils
5
+ Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
6
+ Project-URL: Homepage, https://github.com/salabim/xlwings_utils
7
+ Project-URL: Repository, https://github.com/salabim/xlwings_utils
8
+ Classifier: Development Status :: 5 - Production/Stable
9
+ Classifier: Programming Language :: Python :: 3 :: Only
10
+ Requires-Python: >=3.9
11
+ Description-Content-Type: text/markdown
12
+ Requires-Dist: dropbox
13
+
14
+ # xlwings_utils
15
+
16
+ ## Introduction
17
+
18
+ This module provides some useful functiona to be used in xlwings lite.
19
+ The xlwings lite system does not provide access to the local file system. With this
20
+ module, files can be copied between dropbox and the pyodide file systen. And
21
+ therefore, it is possible to indirectly use the local file system.
22
+
23
+ On top of that, this module makes it possible to capture stdout writes, which
24
+ can then be copied to a worksheet in a later stage.
25
+
26
+ ## Installation
27
+
28
+ Just add xlwings-utils to the requirement tab.
29
+
30
+ ## Dropbox support
31
+
32
+ xlwings_lite only works with full access dropbox apps.
33
+
34
+ In order to use dropbox, is is necessary to initialize the module with credentials.
35
+
36
+ ## Capture stdout support
37
+
38
+ Badges
39
+
40
+ ![PyPI](https://img.shields.io/pypi/v/xlwings-utils) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/xlwings-utils) ![PyPI - Implementation](https://img.shields.io/pypi/implementation/xlwings-utils)
41
+ ![PyPI - License](https://img.shields.io/pypi/l/xlwings-utils) ![ruff](https://img.shields.io/badge/style-ruff-41B5BE?style=flat)
42
+ ![GitHub last commit](https://img.shields.io/github/last-commit/salabim/peek)
43
+
@@ -0,0 +1,30 @@
1
+ # xlwings_utils
2
+
3
+ ## Introduction
4
+
5
+ This module provides some useful functiona to be used in xlwings lite.
6
+ The xlwings lite system does not provide access to the local file system. With this
7
+ module, files can be copied between dropbox and the pyodide file systen. And
8
+ therefore, it is possible to indirectly use the local file system.
9
+
10
+ On top of that, this module makes it possible to capture stdout writes, which
11
+ can then be copied to a worksheet in a later stage.
12
+
13
+ ## Installation
14
+
15
+ Just add xlwings-utils to the requirement tab.
16
+
17
+ ## Dropbox support
18
+
19
+ xlwings_lite only works with full access dropbox apps.
20
+
21
+ In order to use dropbox, is is necessary to initialize the module with credentials.
22
+
23
+ ## Capture stdout support
24
+
25
+ Badges
26
+
27
+ ![PyPI](https://img.shields.io/pypi/v/xlwings-utils) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/xlwings-utils) ![PyPI - Implementation](https://img.shields.io/pypi/implementation/xlwings-utils)
28
+ ![PyPI - License](https://img.shields.io/pypi/l/xlwings-utils) ![ruff](https://img.shields.io/badge/style-ruff-41B5BE?style=flat)
29
+ ![GitHub last commit](https://img.shields.io/github/last-commit/salabim/peek)
30
+
@@ -10,7 +10,7 @@ authors = [
10
10
  { name = "Ruud van der Ham", email = "rt.van.der.ham@gmail.com" },
11
11
  ]
12
12
  description = "xlwings_utils"
13
- version = "0.0.0"
13
+ version = "0.0.0.post0"
14
14
  readme = "README.md"
15
15
  requires-python = ">=3.9"
16
16
  dependencies = [
@@ -0,0 +1,232 @@
1
+ # _ _ _ _ _
2
+ # __ __| |__ __(_) _ __ __ _ ___ _ _ | |_ (_)| | ___
3
+ # \ \/ /| |\ \ /\ / /| || '_ \ / _` |/ __| | | | || __|| || |/ __|
4
+ # > < | | \ V V / | || | | || (_| |\__ \ | |_| || |_ | || |\__ \
5
+ # /_/\_\|_| \_/\_/ |_||_| |_| \__, ||___/ _____ \__,_| \__||_||_||___/
6
+ # |___/ |_____|
7
+
8
+ __version__ = "0.0.0"
9
+
10
+
11
+ import dropbox
12
+ from pathlib import Path
13
+ import sys
14
+
15
+ _captured_stdout = []
16
+ dbx = None
17
+
18
+
19
+ def dropbox_init(refresh_token, app_key, app_secret):
20
+ '''
21
+ dropbox initialize
22
+
23
+ This function has to be called prior to using any dropbox function
24
+
25
+ Parameters
26
+ ----------
27
+ refresh_token : str
28
+ oauth2 refreshntoken
29
+
30
+ app_key : str
31
+ app key
32
+
33
+ app_secret : str
34
+ app secret
35
+
36
+
37
+ Returns
38
+ -------
39
+ -
40
+ '''
41
+ global dbx
42
+ dbx = dropbox.Dropbox(oauth2_refresh_token=refresh_token, app_key=app_key, app_secret=app_secret)
43
+
44
+ def _check_dbx():
45
+ if dbx is None:
46
+ raise ValueError('not initialized. Please call dropbox_init()')
47
+
48
+
49
+ def list_dropbox(path="", recursive=False):
50
+ '''
51
+ list_dropbox
52
+
53
+ returns all dropbox files in path
54
+
55
+ Parameters
56
+ ----------
57
+ path : str or Pathlib.Path
58
+ path from which to list all files (default: '')
59
+
60
+
61
+ recursive : bool
62
+ if True, recursively list files. if False (default) no recursion
63
+
64
+ Returns
65
+ -------
66
+ files, relative to path : list
67
+ '''
68
+ _check_dbx()
69
+ out = []
70
+ result = dbx.files_list_folder(path, recursive=recursive)
71
+
72
+ for entry in result.entries:
73
+ if isinstance(entry, dropbox.files.FileMetadata):
74
+ out.append(entry.path_display)
75
+
76
+ while result.has_more:
77
+ result = dbx.files_list_folder_continue(result.cursor)
78
+ for entry in result.entries:
79
+ if isinstance(entry, dropbox.files.FileMetadata):
80
+ out.append(entry.path_display)
81
+
82
+ return out
83
+
84
+
85
+ def read_dropbox(dropbox_path):
86
+ '''
87
+ read_dropbox
88
+
89
+ read from dopbox at given path
90
+
91
+ Parameters
92
+ ----------
93
+ path : str or Pathlib.Path
94
+ path to read from
95
+
96
+ Returns
97
+ -------
98
+ contents of the dropbox file : bytes
99
+ '''
100
+
101
+ _check_dbx()
102
+ metadata, response = dbx.files_download(dropbox_path)
103
+ file_content = response.content
104
+ return file_content
105
+
106
+
107
+ def write_dropbox(dropbox_path, contents):
108
+ _check_dbx()
109
+ dbx.files_upload(contents, dropbox_path, mode=dropbox.files.WriteMode.overwrite)
110
+
111
+
112
+ def list_pyodide(path):
113
+ path = Path(path)
114
+ return list(path.iterdir())
115
+
116
+
117
+ def write_pyodide(path, contents):
118
+ path = Path(path)
119
+ path.parent.mkdir(parents=True, exist_ok=True)
120
+ with open(path, "wb") as f:
121
+ f.write(contents)
122
+
123
+
124
+ def read_pyodide(path):
125
+ path = Path(path)
126
+ with open(path, "rb") as f:
127
+ contents = f.read()
128
+
129
+
130
+ def clear_captured_stdout():
131
+ """
132
+ empties the captured stdout
133
+ """
134
+ _captured_stdout.clear()
135
+
136
+
137
+ def captured_stdout_as_str():
138
+ """
139
+ returns the captured stdout as a list of strings
140
+
141
+ Returns
142
+ -------
143
+ captured stdout : list
144
+ each line is an element of the list
145
+ """
146
+
147
+ return "".join(_captured_stdout)
148
+
149
+
150
+ def captured_stdout_as_range():
151
+ """
152
+ returns the captured stdout as a list of strings
153
+
154
+ Returns
155
+ -------
156
+ captured stdout : list
157
+ each line is an element of the list
158
+ """
159
+
160
+ return [[line] for line in captured_stdout_as_str().splitlines()]
161
+
162
+
163
+ class capture_stdout:
164
+ """
165
+ specifies how to capture stdout
166
+
167
+ Parameters
168
+ ----------
169
+ include_print : bool
170
+ if True (default), the output is also printed out as normal
171
+
172
+ if False, no output is printed
173
+
174
+ Note
175
+ ----
176
+ This function is normally used as a context manager, like ::
177
+
178
+ with capture_stdout():
179
+ ...
180
+ """
181
+
182
+ def __init__(self, include_print: bool = True):
183
+ self.stdout = sys.stdout
184
+ self.include_print = include_print
185
+
186
+ def __enter__(self):
187
+ sys.stdout = self
188
+
189
+ def __exit__(self, exc_type, exc_value, tb):
190
+ sys.stdout = self.stdout
191
+
192
+ def write(self, data):
193
+ _captured_stdout.append(data)
194
+ if self.include_print:
195
+ self.stdout.write(data)
196
+
197
+ def flush(self):
198
+ if self.include_print:
199
+ self.stdout.flush()
200
+ _captured_stdout.append("\n")
201
+
202
+
203
+ if __name__ == "__main__":
204
+ ...
205
+
206
+
207
+ # @xw.script
208
+ # def test_stdout(book: xw.Book):
209
+ # with capture_stdout():
210
+ # for i in range(10):
211
+ # print(10 * f'{i}')
212
+ # book.sheets.active.range("A1").value=captured_stdout_as_range()
213
+
214
+
215
+ # @xw.script
216
+ # def test(book: xw.Book):
217
+ # dropbox_init(
218
+ # refresh_token=REFRESH_TOKEN,
219
+ # app_key=APP_KEY,
220
+ # app_secret=APP_SECRET,
221
+ # )
222
+
223
+ # files =list_dropbox("/Downloads",recursive=True)
224
+ # peek(files)
225
+ # write_pyodide("Test/x.x", b"abc")
226
+ # files = list_pyodide("Test")
227
+
228
+ # # files=list_dropbox_files("/Downloads")
229
+ # # peek(files)
230
+ # contents = read_dropbox("/Downloads/dropbox setup.py")
231
+ # write_dropbox("/Downloads/dropbox setup1.py", contents)
232
+ # peek("done")
@@ -0,0 +1,43 @@
1
+ Metadata-Version: 2.4
2
+ Name: xlwings_utils
3
+ Version: 0.0.0.post0
4
+ Summary: xlwings_utils
5
+ Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
6
+ Project-URL: Homepage, https://github.com/salabim/xlwings_utils
7
+ Project-URL: Repository, https://github.com/salabim/xlwings_utils
8
+ Classifier: Development Status :: 5 - Production/Stable
9
+ Classifier: Programming Language :: Python :: 3 :: Only
10
+ Requires-Python: >=3.9
11
+ Description-Content-Type: text/markdown
12
+ Requires-Dist: dropbox
13
+
14
+ # xlwings_utils
15
+
16
+ ## Introduction
17
+
18
+ This module provides some useful functiona to be used in xlwings lite.
19
+ The xlwings lite system does not provide access to the local file system. With this
20
+ module, files can be copied between dropbox and the pyodide file systen. And
21
+ therefore, it is possible to indirectly use the local file system.
22
+
23
+ On top of that, this module makes it possible to capture stdout writes, which
24
+ can then be copied to a worksheet in a later stage.
25
+
26
+ ## Installation
27
+
28
+ Just add xlwings-utils to the requirement tab.
29
+
30
+ ## Dropbox support
31
+
32
+ xlwings_lite only works with full access dropbox apps.
33
+
34
+ In order to use dropbox, is is necessary to initialize the module with credentials.
35
+
36
+ ## Capture stdout support
37
+
38
+ Badges
39
+
40
+ ![PyPI](https://img.shields.io/pypi/v/xlwings-utils) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/xlwings-utils) ![PyPI - Implementation](https://img.shields.io/pypi/implementation/xlwings-utils)
41
+ ![PyPI - License](https://img.shields.io/pypi/l/xlwings-utils) ![ruff](https://img.shields.io/badge/style-ruff-41B5BE?style=flat)
42
+ ![GitHub last commit](https://img.shields.io/github/last-commit/salabim/peek)
43
+
@@ -1,23 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: xlwings_utils
3
- Version: 0.0.0
4
- Summary: xlwings_utils
5
- Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
6
- Project-URL: Homepage, https://github.com/salabim/xlwings_utils
7
- Project-URL: Repository, https://github.com/salabim/xlwings_utils
8
- Classifier: Development Status :: 5 - Production/Stable
9
- Classifier: Programming Language :: Python :: 3 :: Only
10
- Requires-Python: >=3.9
11
- Description-Content-Type: text/markdown
12
- Requires-Dist: dropbox
13
-
14
- # xlwings_utils
15
-
16
- ## Introduction
17
-
18
- Badges
19
-
20
- ![PyPI](https://img.shields.io/pypi/v/xlwings_utils) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/xlwings_utils) ![PyPI - Implementation](https://img.shields.io/pypi/implementation/xlwings_utils)
21
- ![PyPI - License](https://img.shields.io/pypi/l/xlwings_utils) ![ruff](https://img.shields.io/badge/style-ruff-41B5BE?style=flat)
22
- ![GitHub last commit](https://img.shields.io/github/last-commit/salabim/peek)
23
-
@@ -1,10 +0,0 @@
1
- # xlwings_utils
2
-
3
- ## Introduction
4
-
5
- Badges
6
-
7
- ![PyPI](https://img.shields.io/pypi/v/xlwings_utils) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/xlwings_utils) ![PyPI - Implementation](https://img.shields.io/pypi/implementation/xlwings_utils)
8
- ![PyPI - License](https://img.shields.io/pypi/l/xlwings_utils) ![ruff](https://img.shields.io/badge/style-ruff-41B5BE?style=flat)
9
- ![GitHub last commit](https://img.shields.io/github/last-commit/salabim/peek)
10
-
@@ -1,9 +0,0 @@
1
- # _ _ _ _ _
2
- # __ __| |__ __(_) _ __ __ _ ___ _ _ | |_ (_)| | ___
3
- # \ \/ /| |\ \ /\ / /| || '_ \ / _` |/ __| | | | || __|| || |/ __|
4
- # > < | | \ V V / | || | | || (_| |\__ \ | |_| || |_ | || |\__ \
5
- # /_/\_\|_| \_/\_/ |_||_| |_| \__, ||___/ _____ \__,_| \__||_||_||___/
6
- # |___/ |_____|
7
-
8
- __version__ = "0.0.0"
9
-
@@ -1,23 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: xlwings_utils
3
- Version: 0.0.0
4
- Summary: xlwings_utils
5
- Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
6
- Project-URL: Homepage, https://github.com/salabim/xlwings_utils
7
- Project-URL: Repository, https://github.com/salabim/xlwings_utils
8
- Classifier: Development Status :: 5 - Production/Stable
9
- Classifier: Programming Language :: Python :: 3 :: Only
10
- Requires-Python: >=3.9
11
- Description-Content-Type: text/markdown
12
- Requires-Dist: dropbox
13
-
14
- # xlwings_utils
15
-
16
- ## Introduction
17
-
18
- Badges
19
-
20
- ![PyPI](https://img.shields.io/pypi/v/xlwings_utils) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/xlwings_utils) ![PyPI - Implementation](https://img.shields.io/pypi/implementation/xlwings_utils)
21
- ![PyPI - License](https://img.shields.io/pypi/l/xlwings_utils) ![ruff](https://img.shields.io/badge/style-ruff-41B5BE?style=flat)
22
- ![GitHub last commit](https://img.shields.io/github/last-commit/salabim/peek)
23
-