@@ -28,7 +28,7 @@ def is_url(str):
2828 return False
2929
3030def displayId (rowobj ):
31- # used to set the object display id in converter function
31+ # used to check the object display id in the converter function
3232 username = os .getenv ("SBOL_USERNAME" )
3333 password = os .getenv ("SBOL_PASSWORD" )
3434
@@ -38,11 +38,21 @@ def displayId(rowobj):
3838 if url .endswith ('/' ):
3939 url = url [:- 1 ]
4040 collection = data ["Library Name" ]
41+ master_collection = False
42+ private_collection = False
4143 if is_url (collection ) == False :
42- if data ["Master Collection" ] is not None :
43- collection = data ["Master Collection" ]
44+ private_collection = False
45+
46+ if data ["Master Collection" ].strip () == "" :
47+
48+ master_collection = False
4449 else :
45- return
50+ collection = data ["Master Collection" ]
51+ master_collection = True
52+ else :
53+ private_collection = True
54+
55+
4656
4757 for col in rowobj .col_cell_dict .keys ():
4858 val = rowobj .col_cell_dict [col ]
@@ -53,40 +63,78 @@ def displayId(rowobj):
5363 display_id = rowobj .col_cell_dict ['Part Id' ]
5464 previous_id = rowobj .col_cell_dict ['Previous Version (URI)' ]
5565 rowobj .obj .wasDerivedFrom = previous_id
56-
5766 return
5867
59- sbol2 . Config . setOption ( 'sbol_typed_uris' , True )
60- doc = sbol2 . Document ( )
68+ val = hf . check_name ( val )
69+ # print("Display ID: ", val )
6170
62- sbol2 .setHomespace (url )
63-
64- part_shop = sbol2 .PartShop (url )
71+ if private_collection == True :
72+
73+ if username is None or password is None or url is None :
74+ print ("No login credentials provided. Proceeding without login." )
75+ print ("Unable to search in a private collection without login credentials." )
76+ print ("Terminating" )
77+ sys .exit (1 )
78+ else :
79+ part_shop = sbol2 .PartShop (collection )
80+ try :
81+ part_shop .login (username , password )
82+ except Exception as e :
83+ print (f"Login failed: { e } " )
84+ exit (1 )
85+
86+ search_results = part_shop .search_exact (val , property_uri = 'http://sbols.org/v2#displayId' )
87+ if len (search_results ) > 0 :
88+ for part in search_results :
89+ print (f"Part with display ID: { part .displayId } already exists in the collection at URL { part .identity } ." )
90+ print ("XML file will NOT be generated." )
91+ os .environ ["COUNTER" ] = "Error found"
6592
66- if username is None or password is None or url is None :
67- # do not login
68- print ("No login credentials provided. Proceeding without login." )
6993 else :
70- try :
71- part_shop .login (username , password )
72- # print("Successfully logged in.")
73- except Exception as e :
74- print (f"Login failed: { e } " )
75- exit (1 )
76- collection_parts = collection .split ('/' )[:- 2 ]
77- link = '/' .join (collection_parts )
78- val = hf .check_name (val )
79- link2 = f"{ link } /{ val } /1"
80- # print(link2)
81- part_shop .pull (link2 , doc )
94+
95+ if master_collection == True :
96+
97+ # part_shop = sbol2.PartShop(collection)
98+ if username is None or password is None or url is None :
99+
100+ part_shop = sbol2 .PartShop (collection )
101+ else :
102+ part_shop = sbol2 .PartShop (collection )
103+ try :
104+ part_shop .login (username , password )
105+ except Exception as e :
106+ print (f"Login failed: { e } " )
107+ exit (1 )
108+
109+ search_results = part_shop .search_exact (val , property_uri = 'http://sbols.org/v2#displayId' )
110+ if len (search_results ) > 0 :
111+ for part in search_results :
112+ print (f"Part with display ID: { part .displayId } already exists in the collection at URL { part .identity } ." )
113+ print ("XML file will NOT be generated." )
114+ os .environ ["COUNTER" ] = "Error found"
115+ elif master_collection == False :
116+
117+ # part_shop = sbol2.PartShop(url)
118+ if username is None or password is None or url is None :
119+
120+ part_shop = sbol2 .PartShop (url )
121+ else :
122+ part_shop = sbol2 .PartShop (collection )
123+ try :
124+ part_shop .login (username , password )
125+ except Exception as e :
126+ print (f"Login failed: { e } " )
127+ exit (1 )
128+ search_results = part_shop .search_exact (val , property_uri = 'http://sbols.org/v2#displayId' )
129+ if len (search_results ) > 0 :
130+ for part in search_results :
131+ print (f"Part with display ID: { part .displayId } already exists in the collection at URL { part .identity } ." )
132+ print ("Just a warning. XML file will be generated." )
133+
82134
83- component = doc .get (link2 )
84- if component :
85- print (f"Component with displayId { component .displayId } already exists at URL { component .identity } " )
86- # print("Terminating")
87- os .environ ["COUNTER" ] = "Error found"
88- # sys.exit(1)
89- pass
135+
136+
137+
90138
91139
92140
0 commit comments