-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestgit.py
45 lines (40 loc) · 1.26 KB
/
testgit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
import yaml
import git
from git import Repo
import logging
def main():
logging.basicConfig(filename='gittest.log',level=logging.DEBUG)
if os.path.isdir("flux-demo"):
g = git.cmd.Git("flux-demo")
g.pull()
logging.info('repo is pulled times')
else:
git.Git("").clone("[email protected]:itsmesinghavneet/flux-demo.git")
logging.info('repo is cloned')
if __name__ == "__main__":main()
def set_state(state):
with open('flux-demo/hello-deploy.yaml') as f:
doc = yaml.load(f)
logging.debug('yaml file is loaded')
doc['metadata']['annotations']['flux.weave.works/locked'] = state
logging.debug('Selected the part to edit')
with open('flux-demo/hello-deploy.yaml', 'w') as f:
yaml.safe_dump(doc, f, default_flow_style=False)
logging.debug('File is opened in write mode')
set_state("true")
logging.debug('The value is changed ')
repo_dir = 'flux-demo/'
repo = Repo(repo_dir)
logging.debug('choosed the repo')
file_list = [
'hello-deploy.yaml'
]
commit_message = 'deautomate'
logging.debug('The commit initialed')
repo.index.add(file_list)
logging.debug('File added')
repo.index.commit(commit_message)
origin = repo.remote('origin')
repo.git.push('[email protected]:itsmesinghavneet/flux-demo.git')
logging.debug('File is being pushed')