MCPcopy
hub / github.com/PokemonGoF/PokemonGo-Bot / GithubPlugin

Class GithubPlugin

pokemongo_bot/plugin_loader.py:48–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46 return getattr(my_module, class_name)
47
48class GithubPlugin(object):
49 PLUGINS_FOLDER = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'plugins')
50
51 def __init__(self, plugin_name):
52 self.plugin_name = plugin_name
53 self.plugin_parts = self.get_github_parts()
54
55 def is_valid_plugin(self):
56 return self.plugin_parts is not None
57
58 def get_github_parts(self):
59 groups = re.match('(.*)\/(.*)#(.*)', self.plugin_name)
60
61 if groups is None:
62 return None
63
64 parts = {}
65 parts['user'] = groups.group(1)
66 parts['repo'] = groups.group(2)
67 parts['sha'] = groups.group(3)
68
69 return parts
70
71 def get_installed_version(self):
72 if not self.is_already_installed():
73 return None
74
75 filename = os.path.join(self.get_plugin_folder(), '.sha')
76 print(filename)
77 with open(filename) as file:
78 return file.read().strip()
79
80 def get_local_destination(self):
81 parts = self.plugin_parts
82 if parts is None:
83 raise Exception('Not a valid github plugin')
84
85 file_name = '{}_{}_{}.zip'.format(parts['user'], parts['repo'], parts['sha'])
86 full_path = os.path.join(self.PLUGINS_FOLDER, file_name)
87 return full_path
88
89 def is_already_installed(self):
90 file_path = self.get_plugin_folder()
91 if not os.path.isdir(file_path):
92 return False
93
94 sha_file = os.path.join(file_path, '.sha')
95
96 if not os.path.isfile(sha_file):
97 return False
98
99 with open(sha_file) as file:
100 content = file.read().strip()
101
102 if content != self.plugin_parts['sha']:
103 return False
104
105 return True

Calls

no outgoing calls