sdk_project.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # coding=utf-8
  2. """ 广告管理工程 """
  3. import os
  4. import ConfigParser
  5. from sdk.tool.ad_ecpm_config_txt import AdEcpmConfigTxt
  6. class SdkProject(object):
  7. """ 广告工程管理
  8. 成员变量:
  9. config_parser: ConfigParser
  10. project_name: string 工程名
  11. ios_bundle_id: string iOS的字符串包名
  12. root_dir: string 工程所在目录
  13. game_platform: string 游戏所在平台(android或ios)
  14. package: string 包名, iOS平台的话为appId(数字)
  15. """
  16. def __init__(self):
  17. self.config_parser = ConfigParser.ConfigParser()
  18. self.project_name = ""
  19. self.game_platform = ""
  20. self.package = ""
  21. self.ios_bundle_id = ""
  22. self.root_dir = ""
  23. def read(self, ini_path):
  24. self.config_parser.read(ini_path)
  25. section_project = "project"
  26. self.project_name = self.config_parser.get(section_project, "name")
  27. self.game_platform = self.config_parser.get(section_project, "game_platform")
  28. self.package = self.config_parser.get(section_project, "package")
  29. self.ios_bundle_id = self.config_parser.get(section_project, "ios_bundle_id")
  30. section_path = "path"
  31. self.root_dir = self.config_parser.get(section_path, "root")
  32. def __find_ecmp_confid_txt(self, file_name_mark):
  33. txt_dir = os.path.join(self.root_dir, "ecpm_config_txts")
  34. files = os.listdir(txt_dir)
  35. for file_name in files:
  36. if file_name.find(file_name_mark) != -1:
  37. txt = AdEcpmConfigTxt()
  38. txt.read(os.path.join(txt_dir, file_name))
  39. return txt
  40. def banner_ecpm_config_txt(self):
  41. """ 读取Banner配置文件
  42. :return: AdEcpmConfigTxt
  43. """
  44. return self.__find_ecmp_confid_txt("banner")
  45. def inter_ecpm_config_txt(self):
  46. """ 读取Inter配置文件
  47. :return: AdEcpmConfigTxt
  48. """
  49. return self.__find_ecmp_confid_txt("inter")
  50. def print_desc(self):
  51. print "工程名: \t\t\t {}".format(self.project_name)
  52. print "游戏平台: \t\t {}".format(self.game_platform)
  53. print "包名: \t\t\t {}".format(self.package)
  54. if not self.ios_bundle_id:
  55. print "iOS bundle id: \t {}".format(self.ios_bundle_id)
  56. print "工程目录: \t\t {}".format(self.root_dir)
  57. if __name__ == '__main__':
  58. proj = SdkProject()
  59. proj.read("/Users/zhuge/datas/AdProjects/ShootingZombie-2D射击-Android/project.ini")
  60. proj.print_desc()
  61. print "banner 国家数: {}".format(proj.banner_ecpm_config_txt().country_count)
  62. print "inter 国家数: {}".format(proj.inter_ecpm_config_txt().country_count)