You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

74 lines
2.9 KiB

  1. # -*- coding: UTF-8 -*-
  2. #!/usr/bin/env python.3.7
  3. import json
  4. try:
  5. import portage
  6. portage.root
  7. portge = portage.db[portage.root]["porttree"].dbapi
  8. except Exception as e:
  9. print("Not Found Portage")
  10. from utils.utils import sort_inatll_pkg
  11. #ПЛАН:
  12. #
  13. # API PORTAGE IN SEARCH
  14. class Package():
  15. def __init__(self):
  16. self.Cat =[]
  17. self.pkg = {}
  18. self.Category =""
  19. self.Name = ""
  20. self.version =""
  21. self.USE =""
  22. self.Description = ""
  23. self.Home_page =""
  24. self.repository = ""
  25. def search(self, r_p):
  26. try:
  27. pametrs = ["HOMEPAGE", "IUSE","DESCRIPTION", "repository", "LICENSE"]
  28. #print(r_p)
  29. p_list = portge.xmatch('match-all', r_p)
  30. m_list = portge.xmatch('match-visible', r_p)
  31. #print(m_list)
  32. #print(len(p_list))
  33. if len(p_list) != 0:
  34. for l in p_list:
  35. params = portge.aux_get(l, pametrs)
  36. if str(self.Cat) in self.Category and str(l).split('/')[1].split('-')[0] in self.Name:
  37. self.version = self.version + " " + str(l.replace(l.split("/")[0] + "/"+ r_p, ""))
  38. if not l in m_list:
  39. self.version = str(self.version) +"[M]"
  40. else:
  41. self.version = str(self.version) +"[U]"
  42. #version + " " + str(l).split('/')[1].split('-')[:-1]
  43. else:
  44. self.Category= str(self.Cat)
  45. #Name =str(l).split('/')[1].split('-')[0]
  46. self.Name = l.split("/")[0] +"/" + r_p
  47. self.version = str(l.replace(l.split("/")[0] + "/"+r_p, ""))
  48. if not l in m_list:
  49. self.version = str(self.version) + "[M]"
  50. else:
  51. self.version = str(self.version) +"[U]"
  52. self.USE = params[1]
  53. self.Description = params[2]
  54. self.Home_page = params[0]
  55. self.repository = params[3]
  56. else:
  57. self.Name = "Package is not Found"
  58. #print(Category + "\n" + Name + "\n" + version +"\n" + USE + "\n" + Description + "\n" + Home_page +"\n")
  59. #p_list = str(Category + "\n" + Name + "\n" + version +"\n" + USE + "\n" + Description + "\n" + Home_page +"\n")
  60. except Exception as e:
  61. print(str(e))
  62. p_list = " ERROR IN Package "
  63. self.pkg = {"Category": self.Category, "Name": self.Name,"version": self.version.split(" "), "USE":self.USE.split(" "), "Description": self.Description, "Home_page":self.Home_page, 'repo': str(self.repository) }
  64. print(self.pkg)
  65. return self.pkg