瀏覽代碼

Adding git0 patterns to remote parsing

Andrej 3 年之前
父節點
當前提交
00c944b912
共有 1 個文件被更改,包括 29 次插入7 次删除
  1. 29 7
      wrapper/nixWrapper.py

+ 29 - 7
wrapper/nixWrapper.py

@@ -22,9 +22,15 @@ def getSuitePath():
     return installDir
     return installDir
 
 
 def buildGITURL(server,project,path,branch='master'):
 def buildGITURL(server,project,path,branch='master'):
-    projectURL='%2f'.join(project)
-    pathURL='%2f'.join(path)
-    return server+'/api/v4/projects/'+projectURL+'/repository/files/'+pathURL+'?ref='+branch
+    if server.find('wiscigt')>-1:
+        projectURL='%2f'.join(project)
+        pathURL='%2f'.join(path)
+        return server+'/api/v4/projects/'+projectURL+'/repository/files/'+pathURL+'?ref='+branch
+    if server.find('fmf.uni-lj.si')>-1:
+        projectURL='/'.join(project)#studen/nixSuite
+        pathURL='/'.join(path)
+        return '/'.join([server,projectURL,'raw',branch,pathURL])
+
 
 
 
 
 def getResources():
 def getResources():
@@ -32,14 +38,25 @@ def getResources():
     project=['labkey','nixsuite']
     project=['labkey','nixsuite']
     path=['remoteResources','resources.json']
     path=['remoteResources','resources.json']
 
 
+    server='https://git0.fmf.uni-lj.si'
+    project=['studen','nixSuite']
+    
     remoteSourcesURL=buildGITURL(server,project,path)
     remoteSourcesURL=buildGITURL(server,project,path)
+    print('remoteSourcesURL {}'.format(remoteSourcesURL))
     http = urllib3.PoolManager()
     http = urllib3.PoolManager()
     r = http.request('GET', remoteSourcesURL)
     r = http.request('GET', remoteSourcesURL)
     #returns a JSON
     #returns a JSON
     encoding=chardet.detect(r.data)['encoding']
     encoding=chardet.detect(r.data)['encoding']
-    jsonData=json.loads(r.data.decode(encoding))
+    dataDecoded=r.data.decode(encoding)
+    jsonData=json.loads(dataDecoded)
+    print(jsonData)
 
 
-    #we are interested in content, do looped way of decoding it
+    #since gogs drops raw data, we already did the hard part 
+    if server.find('fmf.uni-lj.si')>-1:
+        return jsonData
+
+    #on gitlab a further decoding step is required
+    #we are interested in content, do looped way of decoding it 
     b64_bytes=jsonData['content'].encode('ascii')
     b64_bytes=jsonData['content'].encode('ascii')
     m_bytes=base64.b64decode(b64_bytes)
     m_bytes=base64.b64decode(b64_bytes)
     m=m_bytes.decode('ascii')
     m=m_bytes.decode('ascii')
@@ -104,8 +121,13 @@ def loadLibrary(name):
         zipName=name.lower()+'-'+rsource['branch']
         zipName=name.lower()+'-'+rsource['branch']
         os.rename(os.path.join(installDir,zipName),finalName)
         os.rename(os.path.join(installDir,zipName),finalName)
     except FileNotFoundError:
     except FileNotFoundError:
-        zipName=name+'-'+rsource['branch']
-        os.rename(os.path.join(installDir,zipName),finalName)
+        try:
+            zipName=name+'-'+rsource['branch']
+            os.rename(os.path.join(installDir,zipName),finalName)
+        except FileNotFoundError:
+            #git0/gogs
+            zipName=name.lower()
+            os.rename(os.path.join(installDir,zipName),finalName)
 
 
     
     
     sys.path.append(finalName)
     sys.path.append(finalName)