deckbridge 0.1.0__py3-none-any.whl

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.
deckbridge/__init__.py ADDED
@@ -0,0 +1,7 @@
1
+ """Package initialization."""
2
+
3
+ from ._git_version import get_versions # noqa
4
+ from ._version import __version__ # noqa
5
+
6
+ __git_version__ = get_versions()["version"]
7
+ del get_versions
@@ -0,0 +1,547 @@
1
+ # This file helps to compute a version number in source trees obtained from
2
+ # git-archive tarball (such as those provided by githubs download-from-tag
3
+ # feature). Distribution tarballs (built by setup.py sdist) and build
4
+ # directories (produced by setup.py build) will contain a much shorter file
5
+ # that just contains the computed version number.
6
+
7
+ # This file is released into the public domain. Generated by
8
+ # versioneer-0.18 (https://github.com/warner/python-versioneer)
9
+
10
+ """Git implementation of _version.py."""
11
+
12
+ import errno
13
+ import os
14
+ import re
15
+ import subprocess
16
+ import sys
17
+ from typing import Any
18
+
19
+
20
+ def get_keywords():
21
+ """Get the keywords needed to look up the version information."""
22
+ # these strings will be replaced by git during git-archive.
23
+ # setup.py/versioneer.py will grep for the variable names, so they must
24
+ # each be defined on a line of their own. _version.py will just call
25
+ # get_keywords().
26
+ git_refnames = "$Format:%d$"
27
+ git_full = "$Format:%H$"
28
+ git_date = "$Format:%ci$"
29
+ keywords = {"refnames": git_refnames, "full": git_full, "date": git_date}
30
+ return keywords
31
+
32
+
33
+ class VersioneerConfig:
34
+ """Container for Versioneer configuration parameters."""
35
+
36
+
37
+ def get_config():
38
+ """Create, populate and return the VersioneerConfig() object."""
39
+ # these strings are filled in when 'setup.py versioneer' creates
40
+ # _version.py
41
+ cfg = VersioneerConfig()
42
+ cfg.VCS = "git"
43
+ cfg.style = "pep440"
44
+ cfg.tag_prefix = ""
45
+ cfg.parentdir_prefix = "None"
46
+ cfg.versionfile_source = "diffxpy/_version.py"
47
+ cfg.verbose = False
48
+ return cfg
49
+
50
+
51
+ class NotThisMethod(Exception):
52
+ """Exception raised if a method is not valid for the current scenario."""
53
+
54
+
55
+ LONG_VERSION_PY: dict[Any, Any] = {}
56
+ HANDLERS = {}
57
+
58
+
59
+ def register_vcs_handler(vcs, method): # decorator
60
+ """Create decorator to mark a method as the handler for a particular VCS."""
61
+
62
+ def decorate(f):
63
+ """Store f in HANDLERS[vcs][method]."""
64
+ if vcs not in HANDLERS:
65
+ HANDLERS[vcs] = {}
66
+ HANDLERS[vcs][method] = f
67
+ return f
68
+
69
+ return decorate
70
+
71
+
72
+ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=None):
73
+ """Call the given command(s)."""
74
+ assert isinstance(commands, list)
75
+ p = None
76
+ for c in commands:
77
+ try:
78
+ dispcmd = str([c] + args)
79
+ # remember shell=False, so use git.cmd on windows, not just git
80
+ p = subprocess.Popen(
81
+ [c] + args,
82
+ cwd=cwd,
83
+ env=env,
84
+ stdout=subprocess.PIPE,
85
+ stderr=(subprocess.PIPE if hide_stderr else None),
86
+ )
87
+ break
88
+ except EnvironmentError:
89
+ e = sys.exc_info()[1]
90
+ if e.errno == errno.ENOENT:
91
+ continue
92
+ if verbose:
93
+ print("unable to run %s" % dispcmd)
94
+ print(e)
95
+ return None, None
96
+ else:
97
+ if verbose:
98
+ print("unable to find command, tried %s" % (commands,))
99
+ return None, None
100
+ stdout = p.communicate()[0].strip()
101
+ if sys.version_info[0] >= 3:
102
+ stdout = stdout.decode()
103
+ if p.returncode != 0:
104
+ if verbose:
105
+ print("unable to run %s (error)" % dispcmd)
106
+ print("stdout was %s" % stdout)
107
+ return None, p.returncode
108
+ return stdout, p.returncode
109
+
110
+
111
+ def versions_from_parentdir(parentdir_prefix, root, verbose):
112
+ """Try to determine the version from the parent directory name.
113
+
114
+ Source tarballs conventionally unpack into a directory that includes both
115
+ the project name and a version string. We will also support searching up
116
+ two directory levels for an appropriately named parent directory
117
+ """
118
+ rootdirs = []
119
+
120
+ for i in range(3):
121
+ dirname = os.path.basename(root)
122
+ if dirname.startswith(parentdir_prefix):
123
+ return {
124
+ "version": dirname[len(parentdir_prefix) :],
125
+ "full-revisionid": None,
126
+ "dirty": False,
127
+ "error": None,
128
+ "date": None,
129
+ }
130
+ else:
131
+ rootdirs.append(root)
132
+ root = os.path.dirname(root) # up a level
133
+
134
+ if verbose:
135
+ print("Tried directories %s but none started with prefix %s" % (str(rootdirs), parentdir_prefix))
136
+ raise NotThisMethod("rootdir doesn't start with parentdir_prefix")
137
+
138
+
139
+ @register_vcs_handler("git", "get_keywords")
140
+ def git_get_keywords(versionfile_abs):
141
+ """Extract version information from the given file."""
142
+ # the code embedded in _version.py can just fetch the value of these
143
+ # keywords. When used from setup.py, we don't want to import _version.py,
144
+ # so we do it with a regexp instead. This function is not used from
145
+ # _version.py.
146
+ keywords = {}
147
+ try:
148
+ f = open(versionfile_abs, "r")
149
+ for line in f.readlines():
150
+ if line.strip().startswith("git_refnames ="):
151
+ mo = re.search(r'=\s*"(.*)"', line)
152
+ if mo:
153
+ keywords["refnames"] = mo.group(1)
154
+ if line.strip().startswith("git_full ="):
155
+ mo = re.search(r'=\s*"(.*)"', line)
156
+ if mo:
157
+ keywords["full"] = mo.group(1)
158
+ if line.strip().startswith("git_date ="):
159
+ mo = re.search(r'=\s*"(.*)"', line)
160
+ if mo:
161
+ keywords["date"] = mo.group(1)
162
+ f.close()
163
+ except EnvironmentError:
164
+ pass
165
+ return keywords
166
+
167
+
168
+ @register_vcs_handler("git", "keywords")
169
+ def git_versions_from_keywords(keywords, tag_prefix, verbose):
170
+ """Get version information from git keywords."""
171
+ if not keywords:
172
+ raise NotThisMethod("no keywords at all, weird")
173
+ date = keywords.get("date")
174
+ if date is not None:
175
+ # git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant
176
+ # datestamp. However we prefer "%ci" (which expands to an "ISO-8601
177
+ # -like" string, which we must then edit to make compliant), because
178
+ # it's been around since git-1.5.3, and it's too difficult to
179
+ # discover which version we're using, or to work around using an
180
+ # older one.
181
+ date = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
182
+ refnames = keywords["refnames"].strip()
183
+ if refnames.startswith("$Format"):
184
+ if verbose:
185
+ print("keywords are unexpanded, not using")
186
+ raise NotThisMethod("unexpanded keywords, not a git-archive tarball")
187
+ refs = {r.strip() for r in refnames.strip("()").split(",")}
188
+ # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
189
+ # just "foo-1.0". If we see a "tag: " prefix, prefer those.
190
+ TAG = "tag: "
191
+ tags = {r[len(TAG) :] for r in refs if r.startswith(TAG)}
192
+ if not tags:
193
+ # Either we're using git < 1.8.3, or there really are no tags. We use
194
+ # a heuristic: assume all version tags have a digit. The old git %d
195
+ # expansion behaves like git log --decorate=short and strips out the
196
+ # refs/heads/ and refs/tags/ prefixes that would let us distinguish
197
+ # between branches and tags. By ignoring refnames without digits, we
198
+ # filter out many common branch names like "release" and
199
+ # "stabilization", as well as "HEAD" and "master".
200
+ tags = {r for r in refs if re.search(r"\d", r)}
201
+ if verbose:
202
+ print("discarding '%s', no digits" % ",".join(refs - tags))
203
+ if verbose:
204
+ print("likely tags: %s" % ",".join(sorted(tags)))
205
+ for ref in sorted(tags):
206
+ # sorting will prefer e.g. "2.0" over "2.0rc1"
207
+ if ref.startswith(tag_prefix):
208
+ r = ref[len(tag_prefix) :]
209
+ if verbose:
210
+ print("picking %s" % r)
211
+ return {
212
+ "version": r,
213
+ "full-revisionid": keywords["full"].strip(),
214
+ "dirty": False,
215
+ "error": None,
216
+ "date": date,
217
+ }
218
+ # no suitable tags, so version is "0+unknown", but full hex is still there
219
+ if verbose:
220
+ print("no suitable tags, using unknown + full revision id")
221
+ return {
222
+ "version": "0+unknown",
223
+ "full-revisionid": keywords["full"].strip(),
224
+ "dirty": False,
225
+ "error": "no suitable tags",
226
+ "date": None,
227
+ }
228
+
229
+
230
+ @register_vcs_handler("git", "pieces_from_vcs")
231
+ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
232
+ """Get version from 'git describe' in the root of the source tree.
233
+
234
+ This only gets called if the git-archive 'subst' keywords were *not*
235
+ expanded, and _version.py hasn't already been rewritten with a short
236
+ version string, meaning we're inside a checked out source tree.
237
+ """
238
+ GITS = ["git"]
239
+ if sys.platform == "win32":
240
+ GITS = ["git.cmd", "git.exe"]
241
+
242
+ _, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root, hide_stderr=True)
243
+ if rc != 0:
244
+ if verbose:
245
+ print("Directory %s not under git control" % root)
246
+ raise NotThisMethod("'git rev-parse --git-dir' returned error")
247
+
248
+ # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
249
+ # if there isn't one, this yields HEX[-dirty] (no NUM)
250
+ describe_out, rc = run_command(
251
+ GITS,
252
+ [
253
+ "describe",
254
+ "--tags",
255
+ "--dirty",
256
+ "--always",
257
+ "--long",
258
+ "--match",
259
+ "%s*" % tag_prefix,
260
+ ],
261
+ cwd=root,
262
+ )
263
+ # --long was added in git-1.5.5
264
+ if describe_out is None:
265
+ raise NotThisMethod("'git describe' failed")
266
+ describe_out = describe_out.strip()
267
+ full_out, rc = run_command(GITS, ["rev-parse", "HEAD"], cwd=root)
268
+ if full_out is None:
269
+ raise NotThisMethod("'git rev-parse' failed")
270
+ full_out = full_out.strip()
271
+
272
+ pieces = {}
273
+ pieces["long"] = full_out
274
+ pieces["short"] = full_out[:7] # maybe improved later
275
+ pieces["error"] = None
276
+
277
+ # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty]
278
+ # TAG might have hyphens.
279
+ git_describe = describe_out
280
+
281
+ # look for -dirty suffix
282
+ dirty = git_describe.endswith("-dirty")
283
+ pieces["dirty"] = dirty
284
+ if dirty:
285
+ git_describe = git_describe[: git_describe.rindex("-dirty")]
286
+
287
+ # now we have TAG-NUM-gHEX or HEX
288
+
289
+ if "-" in git_describe:
290
+ # TAG-NUM-gHEX
291
+ mo = re.search(r"^(.+)-(\d+)-g([0-9a-f]+)$", git_describe)
292
+ if not mo:
293
+ # unparseable. Maybe git-describe is misbehaving?
294
+ pieces["error"] = "unable to parse git-describe output: '%s'" % describe_out
295
+ return pieces
296
+
297
+ # tag
298
+ full_tag = mo.group(1)
299
+ if not full_tag.startswith(tag_prefix):
300
+ if verbose:
301
+ fmt = "tag '%s' doesn't start with prefix '%s'"
302
+ print(fmt % (full_tag, tag_prefix))
303
+ pieces["error"] = "tag '%s' doesn't start with prefix '%s'" % (
304
+ full_tag,
305
+ tag_prefix,
306
+ )
307
+ return pieces
308
+ pieces["closest-tag"] = full_tag[len(tag_prefix) :]
309
+
310
+ # distance: number of commits since tag
311
+ pieces["distance"] = int(mo.group(2))
312
+
313
+ # commit: short hex revision ID
314
+ pieces["short"] = mo.group(3)
315
+
316
+ else:
317
+ # HEX: no tags
318
+ pieces["closest-tag"] = None
319
+ count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"], cwd=root)
320
+ pieces["distance"] = int(count_out) # total number of commits
321
+
322
+ # commit date: see ISO-8601 comment in git_versions_from_keywords()
323
+ date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"], cwd=root)[0].strip()
324
+ pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
325
+
326
+ return pieces
327
+
328
+
329
+ def plus_or_dot(pieces):
330
+ """Return a + if we don't already have one, else return a ."""
331
+ if "+" in pieces.get("closest-tag", ""):
332
+ return "."
333
+ return "+"
334
+
335
+
336
+ def render_pep440(pieces):
337
+ """Build up version string, with post-release "local version identifier".
338
+
339
+ Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you
340
+ get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty
341
+ Exceptions:
342
+ 1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty]
343
+ """
344
+ if pieces["closest-tag"]:
345
+ rendered = pieces["closest-tag"]
346
+ if pieces["distance"] or pieces["dirty"]:
347
+ rendered += plus_or_dot(pieces)
348
+ rendered += "%d.g%s" % (pieces["distance"], pieces["short"])
349
+ if pieces["dirty"]:
350
+ rendered += ".dirty"
351
+ else:
352
+ # exception #1
353
+ rendered = "0+untagged.%d.g%s" % (pieces["distance"], pieces["short"])
354
+ if pieces["dirty"]:
355
+ rendered += ".dirty"
356
+ return rendered
357
+
358
+
359
+ def render_pep440_pre(pieces):
360
+ """TAG[.post.devDISTANCE] -- No -dirty.
361
+
362
+ Exceptions:
363
+ 1: no tags. 0.post.devDISTANCE
364
+ """
365
+ if pieces["closest-tag"]:
366
+ rendered = pieces["closest-tag"]
367
+ if pieces["distance"]:
368
+ rendered += ".post.dev%d" % pieces["distance"]
369
+ else:
370
+ # exception #1
371
+ rendered = "0.post.dev%d" % pieces["distance"]
372
+ return rendered
373
+
374
+
375
+ def render_pep440_post(pieces):
376
+ """TAG[.postDISTANCE[.dev0]+gHEX] .
377
+
378
+ The ".dev0" means dirty. Note that .dev0 sorts backwards
379
+ (a dirty tree will appear "older" than the corresponding clean one),
380
+ but you shouldn't be releasing software with -dirty anyways.
381
+ Exceptions:
382
+ 1: no tags. 0.postDISTANCE[.dev0]
383
+ """
384
+ if pieces["closest-tag"]:
385
+ rendered = pieces["closest-tag"]
386
+ if pieces["distance"] or pieces["dirty"]:
387
+ rendered += ".post%d" % pieces["distance"]
388
+ if pieces["dirty"]:
389
+ rendered += ".dev0"
390
+ rendered += plus_or_dot(pieces)
391
+ rendered += "g%s" % pieces["short"]
392
+ else:
393
+ # exception #1
394
+ rendered = "0.post%d" % pieces["distance"]
395
+ if pieces["dirty"]:
396
+ rendered += ".dev0"
397
+ rendered += "+g%s" % pieces["short"]
398
+ return rendered
399
+
400
+
401
+ def render_pep440_old(pieces):
402
+ """TAG[.postDISTANCE[.dev0]] .
403
+
404
+ The ".dev0" means dirty.
405
+ Exceptions:
406
+ 1: no tags. 0.postDISTANCE[.dev0]
407
+ """
408
+ if pieces["closest-tag"]:
409
+ rendered = pieces["closest-tag"]
410
+ if pieces["distance"] or pieces["dirty"]:
411
+ rendered += ".post%d" % pieces["distance"]
412
+ if pieces["dirty"]:
413
+ rendered += ".dev0"
414
+ else:
415
+ # exception #1
416
+ rendered = "0.post%d" % pieces["distance"]
417
+ if pieces["dirty"]:
418
+ rendered += ".dev0"
419
+ return rendered
420
+
421
+
422
+ def render_git_describe(pieces):
423
+ """TAG[-DISTANCE-gHEX][-dirty].
424
+
425
+ Like 'git describe --tags --dirty --always'.
426
+ Exceptions:
427
+ 1: no tags. HEX[-dirty] (note: no 'g' prefix)
428
+ """
429
+ if pieces["closest-tag"]:
430
+ rendered = pieces["closest-tag"]
431
+ if pieces["distance"]:
432
+ rendered += "-%d-g%s" % (pieces["distance"], pieces["short"])
433
+ else:
434
+ # exception #1
435
+ rendered = pieces["short"]
436
+ if pieces["dirty"]:
437
+ rendered += "-dirty"
438
+ return rendered
439
+
440
+
441
+ def render_git_describe_long(pieces):
442
+ """TAG-DISTANCE-gHEX[-dirty].
443
+
444
+ Like 'git describe --tags --dirty --always -long'.
445
+ The distance/hash is unconditional.
446
+ Exceptions:
447
+ 1: no tags. HEX[-dirty] (note: no 'g' prefix)
448
+ """
449
+ if pieces["closest-tag"]:
450
+ rendered = pieces["closest-tag"]
451
+ rendered += "-%d-g%s" % (pieces["distance"], pieces["short"])
452
+ else:
453
+ # exception #1
454
+ rendered = pieces["short"]
455
+ if pieces["dirty"]:
456
+ rendered += "-dirty"
457
+ return rendered
458
+
459
+
460
+ def render(pieces, style):
461
+ """Render the given version pieces into the requested style."""
462
+ if pieces["error"]:
463
+ return {
464
+ "version": "unknown",
465
+ "full-revisionid": pieces.get("long"),
466
+ "dirty": None,
467
+ "error": pieces["error"],
468
+ "date": None,
469
+ }
470
+
471
+ if not style or style == "default":
472
+ style = "pep440" # the default
473
+
474
+ if style == "pep440":
475
+ rendered = render_pep440(pieces)
476
+ elif style == "pep440-pre":
477
+ rendered = render_pep440_pre(pieces)
478
+ elif style == "pep440-post":
479
+ rendered = render_pep440_post(pieces)
480
+ elif style == "pep440-old":
481
+ rendered = render_pep440_old(pieces)
482
+ elif style == "git-describe":
483
+ rendered = render_git_describe(pieces)
484
+ elif style == "git-describe-long":
485
+ rendered = render_git_describe_long(pieces)
486
+ else:
487
+ raise ValueError("unknown style '%s'" % style)
488
+
489
+ return {
490
+ "version": rendered,
491
+ "full-revisionid": pieces["long"],
492
+ "dirty": pieces["dirty"],
493
+ "error": None,
494
+ "date": pieces.get("date"),
495
+ }
496
+
497
+
498
+ def get_versions():
499
+ """Get version information or return default if unable to do so."""
500
+ # I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have
501
+ # __file__, we can work backwards from there to the root. Some
502
+ # py2exe/bbfreeze/non-CPython implementations don't do __file__, in which
503
+ # case we can only use expanded keywords.
504
+
505
+ cfg = get_config()
506
+ verbose = cfg.verbose
507
+
508
+ try:
509
+ return git_versions_from_keywords(get_keywords(), cfg.tag_prefix, verbose)
510
+ except NotThisMethod:
511
+ pass
512
+
513
+ try:
514
+ root = os.path.realpath(__file__)
515
+ # versionfile_source is the relative path from the top of the source
516
+ # tree (where the .git directory might live) to this file. Invert
517
+ # this to find the root from __file__.
518
+ for i in cfg.versionfile_source.split("/"):
519
+ root = os.path.dirname(root)
520
+ except NameError:
521
+ return {
522
+ "version": "0+unknown",
523
+ "full-revisionid": None,
524
+ "dirty": None,
525
+ "error": "unable to find root of source tree",
526
+ "date": None,
527
+ }
528
+
529
+ try:
530
+ pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose)
531
+ return render(pieces, cfg.style)
532
+ except NotThisMethod:
533
+ pass
534
+
535
+ try:
536
+ if cfg.parentdir_prefix:
537
+ return versions_from_parentdir(cfg.parentdir_prefix, root, verbose)
538
+ except NotThisMethod:
539
+ pass
540
+
541
+ return {
542
+ "version": "0+unknown",
543
+ "full-revisionid": None,
544
+ "dirty": None,
545
+ "error": "unable to compute version",
546
+ "date": None,
547
+ }
deckbridge/_version.py ADDED
@@ -0,0 +1,3 @@
1
+ """Package version."""
2
+
3
+ __version__ = "0.1.0"
File without changes
@@ -0,0 +1,24 @@
1
+ class DriveFolderManager:
2
+ def __init__(self, drive_service):
3
+ self.drive = drive_service
4
+
5
+ def get_or_create_folder(self, name, parent_id=None):
6
+ query = f"name='{name}' and mimeType='application/vnd.google-apps.folder' and trashed=false"
7
+
8
+ if parent_id:
9
+ query += f" and '{parent_id}' in parents"
10
+
11
+ results = self.drive.files().list(q=query, fields="files(id, name)").execute()
12
+
13
+ files = results.get("files", [])
14
+
15
+ if files:
16
+ return files[0]["id"]
17
+
18
+ body = {"name": name, "mimeType": "application/vnd.google-apps.folder"}
19
+
20
+ if parent_id:
21
+ body["parents"] = [parent_id]
22
+
23
+ folder = self.drive.files().create(body=body, fields="id").execute()
24
+ return folder["id"]
@@ -0,0 +1,36 @@
1
+ import os
2
+ import pickle
3
+
4
+ from google.auth.transport.requests import Request
5
+ from google_auth_oauthlib.flow import InstalledAppFlow
6
+ from googleapiclient.discovery import build
7
+
8
+ SCOPES = [
9
+ "https://www.googleapis.com/auth/presentations",
10
+ "https://www.googleapis.com/auth/spreadsheets",
11
+ "https://www.googleapis.com/auth/drive",
12
+ ]
13
+
14
+
15
+ def get_google_services():
16
+ creds = None
17
+
18
+ if os.path.exists("token.pickle"):
19
+ with open("token.pickle", "rb") as token:
20
+ creds = pickle.load(token)
21
+
22
+ if not creds or not creds.valid:
23
+ if creds and creds.expired and creds.refresh_token:
24
+ creds.refresh(Request())
25
+ else:
26
+ flow = InstalledAppFlow.from_client_secrets_file("credentials.json", SCOPES)
27
+ creds = flow.run_local_server(port=0)
28
+
29
+ with open("token.pickle", "wb") as token:
30
+ pickle.dump(creds, token)
31
+
32
+ slides_service = build("slides", "v1", credentials=creds)
33
+ sheets_service = build("sheets", "v4", credentials=creds)
34
+ drive_service = build("drive", "v3", credentials=creds)
35
+
36
+ return slides_service, sheets_service, drive_service
@@ -0,0 +1,63 @@
1
+ from datetime import datetime
2
+
3
+ from deckbridge.config import DEFAULT_GSLIDES_TEMPLATE_ID
4
+
5
+ from .drive_folders import DriveFolderManager
6
+ from .google_auth import get_google_services
7
+
8
+
9
+ def copy_presentation_template(drive_service, template_id, new_title):
10
+ file = drive_service.files().copy(fileId=template_id, body={"name": new_title}).execute()
11
+
12
+ return file["id"]
13
+
14
+
15
+ def create_gslides_session(title: str = "Deckbridge Deck", template_id=None):
16
+
17
+ slides_service, sheets_service, drive_service = get_google_services()
18
+
19
+ folder_mgr = DriveFolderManager(drive_service)
20
+
21
+ # -----------------------
22
+ # Root folder
23
+ # -----------------------
24
+ root_folder_id = folder_mgr.get_or_create_folder("deckbridge")
25
+
26
+ # -----------------------
27
+ # Run folder (unique per execution)
28
+ # -----------------------
29
+ timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
30
+ run_folder_name = f"{title}_{timestamp}"
31
+
32
+ run_folder_id = folder_mgr.get_or_create_folder(run_folder_name, parent_id=root_folder_id)
33
+
34
+ # -----------------------
35
+ # Create presentation
36
+ # -----------------------
37
+ if template_id is None:
38
+ template_id = DEFAULT_GSLIDES_TEMPLATE_ID
39
+
40
+ presentation_id = copy_presentation_template(drive_service, template_id, title)
41
+
42
+ # move to Drive folder
43
+ drive_service.files().update(fileId=presentation_id, addParents=run_folder_id, fields="id, parents").execute()
44
+
45
+ # -----------------------
46
+ # Create spreadsheet
47
+ # -----------------------
48
+ spreadsheet = sheets_service.spreadsheets().create(body={"properties": {"title": f"{title} - Data"}}).execute()
49
+
50
+ spreadsheet_id = spreadsheet["spreadsheetId"]
51
+
52
+ # move spreadsheet into folder
53
+ drive_service.files().update(fileId=spreadsheet_id, addParents=run_folder_id, fields="id, parents").execute()
54
+
55
+ # -----------------------
56
+ # Return session
57
+ # -----------------------
58
+ return {
59
+ "presentation_id": presentation_id,
60
+ "spreadsheet_id": spreadsheet_id,
61
+ "slides_service": slides_service,
62
+ "sheets_service": sheets_service,
63
+ }
File without changes
@@ -0,0 +1,3 @@
1
+ class BaseBackend:
2
+ def render(self, deck):
3
+ raise NotImplementedError