roomservice: Blissify

Todo: get rid of hacky workaround that substitutes "q" for all
default branch variables

Change-Id: I62ecd248755d19589f5c52f908f3060be643edfd
diff --git a/build/tools/roomservice.py b/build/tools/roomservice.py
index bf502a5..24c0f3b 100755
--- a/build/tools/roomservice.py
+++ b/build/tools/roomservice.py
@@ -52,7 +52,7 @@
     device = product
 
 if not depsonly:
-    print("Device %s not found. Attempting to retrieve device repository from LineageOS Github (http://github.com/LineageOS)." % device)
+    print("Device %s not found. Attempting to retrieve device repository from BlissRoms-Devices GitHub (http://github.com/BlissRoms-Devices)." % device)
 
 repositories = []
 
@@ -72,7 +72,7 @@
         githubreq.add_header("Authorization","Basic %s" % githubauth)
 
 if not depsonly:
-    githubreq = urllib.request.Request("https://api.github.com/search/repositories?q=%s+user:LineageOS+in:name+fork:true" % device)
+    githubreq = urllib.request.Request("https://api.github.com/search/repositories?q=%s+user:BlissRoms-Devices+in:name+fork:true" % device)
     add_auth(githubreq)
     try:
         result = json.loads(urllib.request.urlopen(githubreq).read().decode())
@@ -124,10 +124,12 @@
         return ".repo/manifests/{}".format(m.find("include").get("name"))
 
 def get_default_revision():
-    m = ElementTree.parse(get_manifest_path())
-    d = m.findall('default')[0]
-    r = d.get('revision')
-    return r.replace('refs/heads/', '').replace('refs/tags/', '')
+    #m = ElementTree.parse(get_manifest_path())
+    #d = m.findall('default')[0]
+    #r = d.get('revision')
+    #return r.replace('refs/heads/', '').replace('refs/tags/', '')
+    # Return q branch for now (workaround)
+    return "q"
 
 def get_from_manifest(devicename):
     try:
@@ -164,9 +166,9 @@
         if localpath.get("path") == projectpath:
             return True
 
-    # ... and don't forget the lineage snippet
+    # ... and don't forget the bliss snippet
     try:
-        lm = ElementTree.parse(".repo/manifests/snippets/lineage.xml")
+        lm = ElementTree.parse(".repo/manifests/bliss.xml")
         lm = lm.getroot()
     except:
         lm = ElementTree.Element("manifest")
@@ -189,12 +191,18 @@
         repo_target = repository['target_path']
         print('Checking if %s is fetched from %s' % (repo_target, repo_name))
         if is_in_manifest(repo_target):
-            print('LineageOS/%s already fetched to %s' % (repo_name, repo_target))
+            print('BlissRoms/%s already fetched to %s' % (repo_name, repo_target))
             continue
 
-        print('Adding dependency: LineageOS/%s -> %s' % (repo_name, repo_target))
-        project = ElementTree.Element("project", attrib = { "path": repo_target,
-            "remote": "github", "name": "LineageOS/%s" % repo_name })
+        print('Adding dependency: %s -> %s' % (repo_name, repo_target))
+
+        # Check if repository name contains organization
+        if "/" in repo_name:
+            project = ElementTree.Element("project", attrib = { "path": repo_target,
+                "remote": "github", "name": "%s" % repo_name })
+        else:
+            project = ElementTree.Element("project", attrib = { "path": repo_target,
+                "remote": "github", "name": "BlissRoms-Devices/%s" % repo_name })
 
         if 'branch' in repository:
             project.set('revision',repository['branch'])
@@ -203,6 +211,7 @@
             project.set('revision', fallback_branch)
         else:
             print("Using default branch for %s" % repo_name)
+            project.set('revision', "q")
 
         lm.append(project)
 
@@ -216,7 +225,7 @@
 
 def fetch_dependencies(repo_path, fallback_branch = None):
     print('Looking for dependencies in %s' % repo_path)
-    dependencies_path = repo_path + '/lineage.dependencies'
+    dependencies_path = repo_path + '/bliss.dependencies'
     syncable_repos = []
     verify_repos = []
 
@@ -265,9 +274,9 @@
         repo_name = repository['name']
         if re.match(r"^android_device_[^_]*_" + device + "$", repo_name):
             print("Found repository: %s" % repository['name'])
-            
+
             manufacturer = repo_name.replace("android_device_", "").replace("_" + device, "")
-            
+
             default_revision = get_default_revision()
             print("Default revision: %s" % default_revision)
             print("Checking branch info")
@@ -275,15 +284,16 @@
             add_auth(githubreq)
             result = json.loads(urllib.request.urlopen(githubreq).read().decode())
 
+
             ## Try tags, too, since that's what releases use
             if not has_branch(result, default_revision):
                 githubreq = urllib.request.Request(repository['tags_url'].replace('{/tag}', ''))
                 add_auth(githubreq)
                 result.extend (json.loads(urllib.request.urlopen(githubreq).read().decode()))
-            
+
             repo_path = "device/%s/%s" % (manufacturer, device)
             adding = {'repository':repo_name,'target_path':repo_path}
-            
+
             fallback_branch = None
             if not has_branch(result, default_revision):
                 if os.getenv('ROOMSERVICE_BRANCHES'):
@@ -312,4 +322,4 @@
             print("Done")
             sys.exit()
 
-print("Repository for %s not found in the LineageOS Github repository list. If this is in error, you may need to manually add it to your local_manifests/roomservice.xml." % device)
+print("Repository for %s not found in the BlissRoms-Devices Github repository list. If this is in error, you may need to manually add it to your local_manifests/roomservice.xml." % device)