Skip to content

Commit a000866

Browse files
committed
fixing error on deleteLibrary and adding some method for setEnvironment in Lib
1 parent cca3f60 commit a000866

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

docs/releases.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Patch:
1515
* Support of extension added in `createTargetsLibrary`
1616
* Fixing dependency to `aepp` `som` module
1717
* Fixing renaming path to use `renameComponent` and using `syncComponent`
18+
* Adding capability to set environment to a lib in `Library` instance via `setEnvironment`
19+
* Capability to get a `Library` class from the `getLibrary` method in `Property` instance
20+
* Fixing code in `deleteLibrary`
1821

1922
## 0.4.4
2023
* adding a `getBuilds` method on the `Library` class instance

launchpy/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.4.5-5"
1+
__version__ = "0.4.5-6"

launchpy/library.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def updateExtensions(self, extensions_ids: list)->object:
313313

314314
def setEnvironments(self, environments_list: list, dev_name: str = None)->None:
315315
"""
316-
Save the different environments ids available.
316+
Save the different environments ids available in a config variable.
317317
It is required to use the library class.
318318
Arguments :
319319
environments_list : REQUIRED : list of environment retrieved by the getEnvironments method
@@ -340,14 +340,29 @@ def _setEnvironment(self, obj: dict,verbose:bool=False)->None:
340340
res = new_env
341341
return res
342342

343+
def setEnvironment(self, env_id: str,verbose:bool=False)->None:
344+
"""
345+
Set the environment of the library.
346+
Arguments:
347+
env_id : REQUIRED : The environment id you want to set.
348+
"""
349+
obj = {
350+
"data": {
351+
"id": env_id,
352+
"type": "environments"
353+
}
354+
}
355+
res = self._setEnvironment(obj,verbose=verbose)
356+
return res
357+
343358
def _removeEnvironment(self)->None:
344359
"""
345360
Remove environment
346361
"""
347362
path = f'/libraries/{self.id}/relationships/environment'
348363
new_env = self.connector.getData(self.endpoint+path)
349364
return new_env
350-
365+
351366
def updateLibrary(self,empty:bool=False)->dict:
352367
"""
353368
Update the library
@@ -383,12 +398,14 @@ def updateLibrary(self,empty:bool=False)->dict:
383398
return res
384399

385400

386-
def build(self,verbose:bool=False)->dict:
401+
def build(self,timesleep:int=20, verbose:bool=False)->dict:
387402
"""
388403
Build the library.
389404
Part of the code takes care of assigning the right environement before building the library.
390405
Returns the build when it is completed (succeed or not).
391-
It will check every 15 seconds for the build status, making sure it is not "pending".
406+
Arguments:
407+
timesleep : OPTIONAL : How many seconds to wait between each check of the build status. Default to 20 seconds.
408+
It will check every 20 seconds for the build status, making sure it is not "pending".
392409
"""
393410
if self.build_required == False and self.state != 'approved':
394411
return 'build is not required'
@@ -430,7 +447,7 @@ def build(self,verbose:bool=False)->dict:
430447
build_status = build['data']['attributes']['status']
431448
while build_status == 'pending':
432449
print('pending...')
433-
time.sleep(20)
450+
time.sleep(timesleep)
434451
# return the json directly
435452
build = self.connector.getData(
436453
config.endpoints['global']+'/builds/'+str(build_id))

launchpy/property.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ def getLibraries(self, state: str = None,**kwargs)->object:
603603
data = data + append_data
604604
return data
605605

606-
def getLibrary(self,libraryId:str=None)->dict:
606+
def getLibrary(self,libraryId:str=None,return_class:bool=False)->dict:
607607
"""
608608
get a library based on its ID.
609609
Arguments:
@@ -614,6 +614,8 @@ def getLibrary(self,libraryId:str=None)->dict:
614614
path = f"/libraries/{libraryId}"
615615
res = self.connector.getData(self.endpoint+path)
616616
if 'data' in res.keys():
617+
if return_class:
618+
return Library(res['data'],config_object=self.connector.config,header=self.header)
617619
return res['data']
618620
return res
619621

@@ -1278,18 +1280,22 @@ def deleteLibrary(self,library:str=None,components:bool=False)->str:
12781280
if library in librariesIds:
12791281
libraryId = library
12801282
else:
1281-
libraryId = librariesNameId[library]
1283+
try:
1284+
libraryId = librariesNameId[library]
1285+
except KeyError:
1286+
raise ValueError("Library name or ID provided not found.")
12821287
path = f"/libraries/{libraryId}"
12831288
if components==True:
12841289
myLib = self.getLibrary(libraryId)
12851290
libClass = Library(myLib)
12861291
rules = libClass.getRules()
12871292
dataelements = libClass.getDataElements()
12881293
res = self.connector.deleteData('https://reactor.adobe.io/'+path)
1289-
for rule in rules:
1290-
self.deleteRule(rule['id'])
1291-
for de in dataelements:
1292-
self.deleteDataElement(de['id'])
1294+
if components==True:
1295+
for rule in rules:
1296+
self.deleteRule(rule['id'])
1297+
for de in dataelements:
1298+
self.deleteDataElement(de['id'])
12931299
return res
12941300

12951301
def getProductionEndpoint(self)->dict:

0 commit comments

Comments
 (0)