From fff194c0243cf9d5b7065bd7861aeb50163f3c96 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Tue, 1 Jun 2021 12:51:38 +0200 Subject: [PATCH 1/3] print logbooks; added note on making url configurable --- example_scilog.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/example_scilog.py b/example_scilog.py index 74f093b..daf0b58 100755 --- a/example_scilog.py +++ b/example_scilog.py @@ -20,11 +20,13 @@ from scilog import Basesnippet, Paragraph tmp = Basesnippet() tmp.id = "2" -# url = "https://lnode2.psi.ch/api/v1" -url = "http://[::1]:3000/" +#TODO make this selectable +url = "https://lnode2.psi.ch/api/v1" +#url = "http://[::1]:3000/" log = SciLog(url) #print(log.token) logbooks = log.get_logbooks(ownerGroup=pgroup) +print(logbooks) assert len(logbooks) == 1 logbook = logbooks[0] From 9b3e27bb59e56ccbdccac4a77f91f59d44f45fab Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Tue, 1 Jun 2021 12:52:41 +0200 Subject: [PATCH 2/3] fixed import_dict(); fixed Snippet constr. arguments --- scilog/snippet.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scilog/snippet.py b/scilog/snippet.py index 906b4b6..bbfab50 100644 --- a/scilog/snippet.py +++ b/scilog/snippet.py @@ -34,10 +34,10 @@ def property_maker(name, dtype): class Snippet: - def __init__(self, snippetType="snippet", **kwargs): + def __init__(self, snippetType="snippet"): self._properties = [] + self.set_properties(snippetType=str) self.snippetType = snippetType - self.set_properties(**kwargs) def set_properties(self, **kwargs): for name, dtype in kwargs.items(): @@ -53,7 +53,8 @@ class Snippet: return {key: getattr(self, key) for key in self._properties if getattr(self, key) is not None} def import_dict(self, properties): - self.__dict__.update(properties) + for name, value in properties.items(): + setattr(self, name, value) @classmethod def from_dict(cls, properties): @@ -75,13 +76,13 @@ class Snippet: class Basesnippet(Snippet): - def __init__(self): - props = dict( + def __init__(self, snippetType="basesnippet"): + super().__init__(snippetType=snippetType) + self.set_properties( id=str, parentId=str, ownerGroup=str, accessGroups=list, - snippetType=str, isPrivate=bool, createdAt=str, createdBy=str, @@ -97,18 +98,17 @@ class Basesnippet(Snippet): versionable=bool, deleted=bool ) - super().__init__(snippetType="basesnippet", **props) class Paragraph(Basesnippet): - def __init__(self): - props = dict( + def __init__(self, snippetType="paragraph"): + super().__init__(snippetType=snippetType) + self.set_properties( textcontent=str, isMessage=str ) - super().__init__(snippetType="paragraph", **props) From df708a579913bc46d4bed3bb8e361c4984af24f7 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Tue, 1 Jun 2021 12:57:20 +0200 Subject: [PATCH 3/3] made url selectable --- example_scilog.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/example_scilog.py b/example_scilog.py index daf0b58..d50708a 100755 --- a/example_scilog.py +++ b/example_scilog.py @@ -2,11 +2,13 @@ import argparse -parser = argparse.ArgumentParser() +parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument("pgroup", help="Expected form: p12345") +parser.add_argument("-u", "--url", default="https://lnode2.psi.ch/api/v1", help="Server address") clargs = parser.parse_args() pgroup = clargs.pgroup +url = clargs.url import urllib3 @@ -20,9 +22,6 @@ from scilog import Basesnippet, Paragraph tmp = Basesnippet() tmp.id = "2" -#TODO make this selectable -url = "https://lnode2.psi.ch/api/v1" -#url = "http://[::1]:3000/" log = SciLog(url) #print(log.token) logbooks = log.get_logbooks(ownerGroup=pgroup)