Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding sync to remote repo #37

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions munkiwebadmin/settings_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
if USE_LDAP:
import ldap
from django_auth_ldap.config import LDAPSearch, PosixGroupType

# LDAP settings
AUTH_LDAP_SERVER_URI = "ldap://foo.example.com"
AUTH_LDAP_BIND_DN = ""
Expand All @@ -183,7 +183,7 @@
ldap.SCOPE_SUBTREE, "(objectClass=posixGroup)")
AUTH_LDAP_GROUP_TYPE = PosixGroupType()
AUTH_LDAP_FIND_GROUP_PERMS = True
AUTH_LDAP_USER_ATTR_MAP = {"first_name": "givenName",
AUTH_LDAP_USER_ATTR_MAP = {"first_name": "givenName",
"last_name": "sn",
"email": "mail"}
# Cache group memberships for an hour to minimize LDAP traffic
Expand Down Expand Up @@ -228,16 +228,21 @@
# be sure to include trailing slash

# for development work (Set DEBUG=True), you can set the ICONS_URL to MEDIA_URL.
# This is not recommended for production.
# This is not recommended for production.
MEDIA_ROOT = os.path.join(MUNKI_REPO_DIR, 'icons')
ICONS_URL = MEDIA_URL

# For production, you can point to your Munki server
# For production, you can point to your Munki server
# if retrieving icons requires no special authentication
# -- otherwise, you'll need some other static file server
#ICONS_URL = "http://localhost/munki_repo/icons/"
#ICONS_URL = "http://munki/repo/icons/"

# For suncing changesfrom the repositoty mwa2 uses to the remote server
# For this to work munki_repo/.git/config should have branch and remote configured.
# You should be able to manually run, 'git pull' and git 'git push' from the repo mwa2 is using
SYNC_REMOTE_REPO = False

# path to the makecatalogs binary
MAKECATALOGS_PATH = '/usr/local/munki/makecatalogs'

Expand Down
29 changes: 28 additions & 1 deletion munkiwebadmin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

APPNAME = settings.APPNAME
REPO_DIR = settings.MUNKI_REPO_DIR

SYNC_REMOTE_REPO = settings.SYNC_REMOTE_REPO
LOGGER = logging.getLogger('munkiwebadmin')

try:
Expand Down Expand Up @@ -56,6 +56,27 @@ def path_is_in_git_repo(self, a_path):
self.run_git(['status', a_path])
return self.results['returncode'] == 0

def sync_changes_to_repo(self):
LOGGER.info("Syncing changes...................")
os.chdir(REPO_DIR)
#get_branch_name = self.run_git(['symbolic-ref', '--short', 'HEAD'])
#branch_name = get_branch_name['output'].strip()
if self.results['returncode'] == 0:
# Pull changes
self.run_git(['pull'])
if self.results['returncode'] != 0:
LOGGER.info("Failed to pull changes")
LOGGER.info(self.results['error'])
return -1

# Push changes
self.run_git(['push'])
if self.results['returncode'] != 0:
LOGGER.info("Failed to push changes")
LOGGER.info(self.results['error'])
return -1
return 0

def commit_file_at_path(self, a_path, committer):
"""Commits the file at 'a_path'. This method will also automatically
generate the commit log appropriate for the status of a_path where
Expand Down Expand Up @@ -96,8 +117,14 @@ def commit_file_at_path(self, a_path, committer):
LOGGER.info("Failed to commit changes to %s", a_path)
LOGGER.info(self.results['error'])
return -1

# if syncing has been set then sync with remote repo
if SYNC_REMOTE_REPO:
#sync changes
self.sync_changes_to_repo()
return 0


def add_file_at_path(self, a_path, committer):
"""Commits a file to the Git repo."""
if self.path_is_in_git_repo(a_path):
Expand Down