def add_machine(self, machine): """ Ajoute une machine au reseau. 1. Si c'est bien une machine. gere par super 2. Si elle n'est pas deja presente gere par super 3. Si au moins une de ses adresses IP entre dans le range IP Si ses adresses IP ne entre en collision les adresses IP deja presente, on remonte un warnings :param machine: Machine, la machine a ajouter :return: None """ if not super(ReseauL3, self).check_machine(machine): return if not [True for ip in machine.ls_online_ip() if ip in self.netaddr]: tools.debug( "RZO_L3 add_machine : Aucune adresse n'entre dans le reseau") return if [ True for ip in machine.ls_online_ip() if ip in self.ls_online_ip() ]: tools.debug( "RZO_L3 add_machine : Collision detectee") # Inutile peut etre self.machines.append(machine)
def get_public_ip(ip): """ Recupere l'adresse IP public de l'hote en utilisant la requete du moteur de recherche duckduckgo On recherche dans la page web le texte : Your IP address is ([0-9]{1,3}\.){3}[0-9]{1,3} in <a href=.*>.*</a> :param ip: str, adresse IP :return str, str, Public IP et localisation """ query = "https://duckduckgo.com/?q=whats++my+ip&t=canonical&ia=answer" try: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: sock.bind((ip, 65432)) context = ssl.create_default_context() context.wrap_socket(sock, server_hostname="duckduckgo.com") r = urllib.request.urlopen(query, context=context) page = r.read().decode() regex = re.compile( r"Your IP address is (?P<myip>(\d{1,3}\.){3}\d{1,3}) in <a (.)*>(?P<geoloc>(.)+)</a>" ) match = re.search(regex, page) if match: return match.group('myip'), match.group('geoloc') except OSError: tools.debug("Get public ip: OS erreur") except ssl.CertificateError: tools.error("Get public ip: Erreur de certificat") return None, None
def add_nic(self, new_nic): """ Ajoute une interface reseau. Controle si l'interface n'est pas deja dans la liste des interface de cette machine. Controle de la collision d'adresse IP. Deux interfaces reseau ne doivent pas avoir la meme adresse :param new_nic: Nic, la nouvelle interface :return: Bool, True si l'interface a ete ajoutee. (utilise par PCAdmin) """ if not isinstance(new_nic, Nic): tools.error( "add_nic: Impossible d'ajouter {} aux interfaces de {}".format( new_nic, self.label)) return False if new_nic in self.nics: tools.debug("add_nic: '{}' deja presente sur '{}'".format( new_nic, self.label)) return False for new_ip in new_nic.ls_online_ip(): if new_ip in self.ls_online_ip(): tools.debug( "add_nic: {} deja utilise par une autre interface".format( new_ip)) return False self.nics.append(new_nic) return True
def nom(self, value): if not value: self._nom = "Reseau indefini" elif isinstance(value, str): self._nom = value else: self._nom = "Reseau indefini" tools.debug("setter nom : {} invalide pour nom de reseau".format( self.nom))
def nom(self, value): """ Setter du nom de l'interface. Si la value n'est pas un str, on definit _nom a "" :param value: str, le nom de l'interface :return: None """ if isinstance(value, str): self._nom = value else: self._nom = "" tools.debug("Setter nom : {} Invalide".format(value))
def get_iface_info(interface): """ Recupere les informations a partir de l'interface donnee en argument :param interface: String, designant une interface de connexion (wifi, ethernet) :return Tuple de String, adresse mac, IP4/CIDR, IP6/CIDR """ try: addr = netifaces.ifaddresses(interface) except ValueError: tools.debug("Fonction 'get_iface_info' : Valeur '{}' incorrect".format( interface)) return None, None, None mac = addr[netifaces.AF_LINK][0][ 'addr'] # Problème avec VPN pas de AF_LINK if netifaces.AF_INET in addr: ip4 = addr[netifaces.AF_INET][0]['addr'] nm4 = addr[netifaces.AF_INET][0]['netmask'] else: ip4 = nm4 = None if netifaces.AF_INET in addr: ip6 = addr[netifaces.AF_INET6][0]['addr'].split('%')[0] nm6 = addr[netifaces.AF_INET6][0]['netmask'] else: ip6 = nm6 = None if ip4 and nm4: ip4_cidr = ip4 + '/' + tools.nm4_to_cidr(nm4) else: ip4_cidr = None if ip6 and nm6: ip6_cidr = ip6 + '/' + tools.nm6_to_cidr(nm6) else: ip6_cidr = None return mac, ip4_cidr, ip6_cidr
action='store_true', help='outputs the output from selenium in the same window', dest='seleniumverbose') parser.add_argument('name', metavar='name', default=None, nargs='?', help='name of the instance') args = parser.parse_args() Wp = workplace.Workplace(C.get('dirs.storage')) # Loading instance M = Wp.resolve(args.name) if not M: debug('This is not a Moodle instance') sys.exit(1) # Check if installed if not M.get('installed'): debug('This instance needs to be installed first') sys.exit(1) # No Javascript nojavascript = args.nojavascript if not nojavascript and not C.get('java') or not os.path.isfile( os.path.abspath(C.get('java'))): nojavascript = True debug( 'Disabling Javascript because Java is required to run Selenium and could not be found.' )
action='store_true', help= 'checkout a testing branch before proceeding to the pull (Testing mode).') parser.add_argument( 'issue', metavar='issue', default=None, nargs='?', help= 'tracker issue to pull from (MDL-12345, 12345). If not specified, read from current branch.' ) args = parser.parse_args() M = Wp.resolve() if not M: debug('This is not a Moodle instance') sys.exit(1) if args.testing and args.integration: debug('You cannot combine --integration and --testing') sys.exit(1) # Tracker issue number. issuenb = args.issue if not issuenb: parsedbranch = tools.parseBranch(M.currentBranch(), C.get('wording.branchRegex')) if not parsedbranch: debug('Could not extract issue number from %s' % M.currentBranch()) sys.exit(1) issuenb = parsedbranch['issue']
versionNice = version if version == 'master': versionNice = C.get('wording.master') # Generating names if args.integration: fullname = C.get('wording.integration') + ' ' + versionNice + ' ' + C.get('wording.%s' % engine) else: fullname = C.get('wording.stable') + ' ' + versionNice + ' ' + C.get('wording.%s' % engine) # Append the suffix if args.suffix: fullname += ' ' + args.suffix.replace('-', ' ').replace('_', ' ').title() # Create the instance debug('Creating instance %s...' % name) kwargs = { 'name': name, 'version': version, 'integration': args.integration, 'useCacheAsRemote': C.get('useCacheAsRemote') } try: M = Wp.create(**kwargs) except Exception as e: debug(e) sys.exit(1) # Run the install script if args.install:
dest='includestable') parser.add_argument('-k', '--force-stable', action='store_true', help='force the push on the stable branch', dest='forcestable') parser.add_argument('name', metavar='name', default=None, nargs='?', help='name of the instance to work on') args = parser.parse_args() M = Wp.resolve(args.name) if not M: debug('This is not a Moodle instance') sys.exit(1) # Setting remote if args.remote == None: remote = C.get('myRemote') else: remote = args.remote # Setting branch if args.branch == None: branch = M.currentBranch() if branch == 'HEAD': debug('Cannot push HEAD branch') sys.exit(1) else:
parser.add_argument('arguments', type=str, metavar='arguments', default=None, nargs=argparse.REMAINDER, help='arguments for the command') args = parser.parse_args() if args.command == 'list': aliases = C.get('aliases') for alias, command in aliases.items(): print '{0:<20}: {1}'.format(alias, command) elif args.command == 'show': if len(args.arguments) != 1: debug( 'Too few/many arguments. One needed: moodle alias show aliasName') sys.exit(1) alias = C.get('aliases.%s' % args.arguments[0]) if alias != None: debug(alias) elif args.command == 'add': if len(args.arguments) < 2: debug( 'Too few/many arguments. Two needed: moodle alias add aliasName Command To Perform' ) sys.exit(1) alias = args.arguments[0] command = ' '.join(args.arguments[1:]) C.add('aliases.%s' % alias, command)
elif args.command == 'flatlist': def show_list(settings, parent=''): for name, setting in settings.items(): if type(setting) != dict: print u'%s: %s' % (parent + name, setting) else: show_list(setting, parent + name + u'.') show_list(C.get()) elif args.command == 'show': if len(args.arguments) != 1: debug( 'Too few/many arguments. One needed: moodle config show settingName' ) sys.exit(1) setting = C.get(args.arguments[0]) if setting != None: debug(setting) elif args.command == 'set': if len(args.arguments) < 2: debug( 'Too few arguments. Two needed: moodle config set settingName value' ) sys.exit(1) setting = args.arguments[0] val = u' '.join(args.arguments[1:]) if val.startswith('b:'):
show_list(C.get(), 0) elif args.command == "flatlist": def show_list(settings, parent=""): for name, setting in settings.items(): if type(setting) != dict: print u"%s: %s" % (parent + name, setting) else: show_list(setting, parent + name + u".") show_list(C.get()) elif args.command == "show": if len(args.arguments) != 1: debug("Too few/many arguments. One needed: moodle config show settingName") sys.exit(1) setting = C.get(args.arguments[0]) if setting != None: debug(setting) elif args.command == "set": if len(args.arguments) < 2: debug("Too few arguments. Two needed: moodle config set settingName value") sys.exit(1) setting = args.arguments[0] val = u" ".join(args.arguments[1:]) if val.startswith("b:"): val = True if val[2:].lower() in ["1", "true"] else False elif val.startswith("i:"): try:
from lib.tools import debug from lib.config import Conf C = Conf() # Arguments parser = argparse.ArgumentParser(description='Completely remove an instance') parser.add_argument('name', help='name of the instance') parser.add_argument('-y', action='store_true', help='do not ask for confirmation', dest='do') args = parser.parse_args() Wp = workplace.Workplace() try: M = Wp.get(args.name) except: debug('This is not a Moodle instance') sys.exit(1) if not args.do: confirm = raw_input('Are you sure? (Y/n) ') if confirm != 'Y': debug('Exiting...') sys.exit(0) debug('Removing %s...' % args.name) try: Wp.delete(args.name) except OSError: debug('Error while deleting the instance.') debug('This is probably a permission issue.') debug('Run: sudo chmod -R 0777 %s' % Wp.getPath(args.name))
from lib.tools import debug from lib.config import Conf Wp = workplace.Workplace() C = Conf() # Arguments parser = argparse.ArgumentParser(description='Perform several checks on your current installation') # parser.add_argument('-f', '--fix', dest='fix', action='store_true', help='Fix the problems where possible') parser.add_argument('-i', '--integration', action='store_true', help='runs the script on the integration instances', dest='integration') parser.add_argument('-s', '--stable', action='store_true', help='runs the script on the stable instances', dest='stable') parser.add_argument('names', metavar='names', default=None, nargs='*', help='name of the instances') args = parser.parse_args() # Check configuration file debug('[Config file]') distSettings = Conf(os.path.dirname(__file__), 'config-dist.json').get() allSettings = C.get() errors = [] def dictCompare(orig, mine, path = ''): for k in orig: currentpath = path + '.' + k currentpath = currentpath.strip('.') if k not in mine: errors.append(currentpath) elif type(orig[k]) in (dict, list): dictCompare(orig[k], mine[k], currentpath) dictCompare(distSettings, allSettings) if len(errors) > 0:
parser.add_argument('-i', '--issues', metavar='issues', required=True, nargs='+', help='issues to be rebased') parser.add_argument('-s', '--suffix', metavar='suffix', help='the suffix of the branch of those issues') parser.add_argument('-v', '--versions', metavar='version', nargs='+', choices=[ str(x) for x in range(13, int(C.get('masterBranch'))) ] + ['master'], help='versions to rebase the issues on. Ignored if names is set.') parser.add_argument('-p', '--push', action='store_true', help='push the branch after successful rebase') parser.add_argument('-r', '--remote', metavar='remote', help='the remote to push the branch to. Default is %s.' % C.get('myRemote')) parser.add_argument('-f', '--force-push', action='store_true', help='Force the push', dest='forcepush') parser.add_argument('names', metavar='names', default=None, nargs='*', help='name of the instances to rebase') args = parser.parse_args() names = args.names issues = args.issues versions = args.versions # If we don't have a version, we need an instance if not names and not versions: debug('This is not a Moodle instance') sys.exit(1) # We don't have any names but some versions are set if not names: names = [] for v in versions: names.append(Wp.generateInstanceName(v)) # Getting instances Mlist = Wp.resolveMultiple(names) # Loops over instances to rebase for M in Mlist: debug('Working on %s' % (M.get('identifier'))) M.git().fetch(C.get('upstreamRemote'))
default=None, nargs='*', help='name of the instances') args = parser.parse_args() # Resolving instances names = args.names if args.all: names = Wp.list() elif args.integration or args.stable: names = Wp.list(integration=args.integration, stable=args.stable) # Doing stuff Mlist = Wp.resolveMultiple(names) if len(Mlist) < 1: debug('No instances to work on. Exiting...') sys.exit(1) for M in Mlist: debug('Purging cache on %s' % (M.get('identifier'))) try: M.purge() except Exception as e: debug(e) else: debug('Cache purged!') debug('') debug('Done.')
# List the backups if args.list: backups = BackupManager.list() for key in sorted(backups.keys()): B = backups[key] backuptime = time.ctime(B.get('backup_time')) print '{0:<25}: {1:<30} {2}'.format(key, B.get('release'), backuptime) # Displays backup information elif args.info: name = args.info # Resolve the backup if not name or not BackupManager.exists(name): debug('This is not a valid backup') sys.exit(1) # Restore process B = BackupManager.get(name) infos = B.infos debug('Displaying information about %s' % name) for key in sorted(infos.keys()): debug('{0:<20}: {1}'.format(key, infos[key])) # Restore elif args.restore: name = args.restore # Resolve the backup if not name or not BackupManager.exists(name):
for x in range(13, int(C.get('masterBranch')))] + ['master'], help='versions to backport to') args = parser.parse_args() M = None branch = args.branch versions = args.versions remote = args.remote integration = args.integration if remote == None: remote = C.get('myRemote') # If we don't have a branch, we need an instance M = Wp.resolve(args.name) if not M and not branch: debug('This is not a Moodle instance') sys.exit(1) # Getting issue number if M and not branch: branch = M.currentBranch() # Parsing the branch parsedbranch = tools.parseBranch(branch, C.get('wording.branchRegex')) if not parsedbranch: debug('Could not extract issue number from %s' % branch) sys.exit(1) issue = parsedbranch['issue'] suffix = parsedbranch['suffix'] version = parsedbranch['version']
) parser.add_argument( "--selenium-verbose", action="store_true", help="outputs the output from selenium in the same window", dest="seleniumverbose", ) parser.add_argument("name", metavar="name", default=None, nargs="?", help="name of the instance") args = parser.parse_args() Wp = workplace.Workplace(C.get("dirs.storage")) # Loading instance M = Wp.resolve(args.name) if not M: debug("This is not a Moodle instance") sys.exit(1) # Check if installed if not M.get("installed"): debug("This instance needs to be installed first") sys.exit(1) # No Javascript nojavascript = args.nojavascript if not nojavascript and not C.get("java") or not os.path.isfile(os.path.abspath(C.get("java"))): nojavascript = True debug("Disabling Javascript because Java is required to run Selenium and could not be found.") # If not composer.phar, install Composer if not os.path.isfile(os.path.join(M.get("path"), "composer.phar")):
C = Conf() # Arguments parser = argparse.ArgumentParser(description='Creates a branch associated to an MDL issue') parser.add_argument('issue', help='issue number') parser.add_argument('suffix', nargs='?', default='', help='suffix of the branch') parser.add_argument('-n', '--name', metavar='name', default=None, help='name of the instance') args = parser.parse_args() Wp = workplace.Workplace() # Loading instance M = Wp.resolve(args.name) if not M: debug('This is not a Moodle instance') sys.exit(1) # Branch name branch = M.generateBranchName(args.issue, suffix=args.suffix) # Track track = '%s/%s' % (C.get('upstreamRemote'), M.get('stablebranch')) # Git repo repo = M.git() # Creating and checking out the new branch if not repo.hasBranch(branch): if not repo.createBranch(branch, track): debug('Could not create branch %s' % branch)
C = Conf() # Arguments parser = argparse.ArgumentParser(description='Initialize PHPUnit') parser.add_argument('-f', '--force', action='store_true', help='force the initialisation') parser.add_argument('-r', '--run', action='store_true', help='also run the tests') parser.add_argument('name', metavar='name', default=None, nargs='?', help='name of the instance') args = parser.parse_args() Wp = workplace.Workplace(C.get('dirs.storage')) # Loading instance M = Wp.resolve(args.name) if not M: debug('This is not a Moodle instance') sys.exit(1) # Check if installed if not M.get('installed'): debug('This instance needs to be installed first') sys.exit(1) # Run cli try: M.initPHPUnit(force=args.force) debug('PHPUnit ready!') if args.run: debug('Running PHPUnit') process('phpunit', M.path, None, None) except Exception as e:
versionNice = C.get('wording.master') # Generating names if args.integration: fullname = C.get('wording.integration') + ' ' + versionNice + ' ' + C.get( 'wording.%s' % engine) else: fullname = C.get('wording.stable') + ' ' + versionNice + ' ' + C.get( 'wording.%s' % engine) # Append the suffix if args.suffix: fullname += ' ' + args.suffix.replace('-', ' ').replace('_', ' ').title() # Create the instance debug('Creating instance %s...' % name) kwargs = { 'name': name, 'version': version, 'integration': args.integration, 'useCacheAsRemote': C.get('useCacheAsRemote') } try: M = Wp.create(**kwargs) except Exception as e: debug(e) sys.exit(1) # Run the install script if args.install:
C = Conf() # Arguments parser = argparse.ArgumentParser(description="Push a branch to a remote.") parser.add_argument('-b', '--branch', metavar='branch', help='the branch to push. Default is current branch.') parser.add_argument('-r', '--remote', metavar='remote', help='remote to push to. Default is your remote.') parser.add_argument('-f', '--force', action='store_true', help='force the push (does not apply on the stable branch).') parser.add_argument('-t', '--update-tracker', action='store_true', help='also add the diff information to the tracker issue.', dest='updatetracker') parser.add_argument('-s', '--include-stable', action='store_true', help='also push the stable branch (MOODLE_xx_STABLE, master)', dest='includestable') parser.add_argument('-k', '--force-stable', action='store_true', help='force the push on the stable branch', dest='forcestable') parser.add_argument('name', metavar='name', default=None, nargs='?', help='name of the instance to work on') args = parser.parse_args() M = Wp.resolve(args.name) if not M: debug('This is not a Moodle instance') sys.exit(1) # Setting remote if args.remote == None: remote = C.get('myRemote') else: remote = args.remote # Setting branch if args.branch == None: branch = M.currentBranch() if branch == 'HEAD': debug('Cannot push HEAD branch') sys.exit(1) else:
dest='updatecache') parser.add_argument('-p', '--proceed', action='store_true', help='do not exit the process after updating the cache', dest='process') parser.add_argument('names', metavar='names', default=None, nargs='*', help='name of the instances') args = parser.parse_args() # Updating cache only if args.updatecache: debug('Updating cached remote') Wp.updateCachedClones() debug('Done.') if not args.process: sys.exit(0) debug('') # Updating instances names = args.names if args.all: names = Wp.list() elif args.integration or args.stable: names = Wp.list(integration=args.integration, stable=args.stable) Mlist = Wp.resolveMultiple(names) if len(Mlist) < 1:
parser.add_argument('-i', '--integration', action='store_true', help='runs the script on the integration instances', dest='integration') parser.add_argument('-s', '--stable', action='store_true', help='runs the script on the stable instances', dest='stable') parser.add_argument('script', metavar='script', help='the name of the script to run') parser.add_argument('names', metavar='names', default=None, nargs='*', help='name of the instances') args = parser.parse_args() # Resolving instances names = args.names if args.all: names = Wp.list() elif args.integration or args.stable: names = Wp.list(integration=args.integration, stable=args.stable) # Doing stuff Mlist = Wp.resolveMultiple(names) if len(Mlist) < 1: debug('No instances to work on. Exiting...') sys.exit(1) for M in Mlist: debug('Running \'%s\' on \'%s\'' % (args.script, M.get('identifier'))) try: M.runScript(args.script, stderr=None, stdout=None) except Exception as e: debug('Error while running the script on %s' % M.get('identifier')) debug(e) else: debug('') debug('Done.')
# Arguments parser = argparse.ArgumentParser(description='Install a Moodle instance') parser.add_argument('-e', '--engine', action='store', choices=['mysqli', 'pgsql'], default=C.get('defaultEngine'), help='database engine to use', metavar='engine') parser.add_argument('-f', '--fullname', action='store', help='full name of the instance', metavar='fullname') parser.add_argument('-r', '--run', action='store', nargs='*', help='scripts to run after installation', metavar='run') parser.add_argument('name', metavar='name', default=None, nargs='?', help='name of the instance') args = parser.parse_args() name = args.name engine = args.engine fullname = args.fullname M = Wp.resolve(name) if not M: debug('This is not a Moodle instance') sys.exit(1) name = M.get('identifier') dataDir = Wp.getPath(name, 'data') if not os.path.isdir(dataDir): os.mkdir(dataDir, 0777) kwargs = { 'engine': engine, 'fullname': fullname, 'dataDir': dataDir } M.install(**kwargs) # Running scripts
help='Force the push', dest='forcepush') parser.add_argument('names', metavar='names', default=None, nargs='*', help='name of the instances to rebase') args = parser.parse_args() names = args.names issues = args.issues versions = args.versions # If we don't have a version, we need an instance if not names and not versions: debug('This is not a Moodle instance') sys.exit(1) # We don't have any names but some versions are set if not names: names = [] for v in versions: names.append(Wp.generateInstanceName(v)) # Getting instances Mlist = Wp.resolveMultiple(names) # Loops over instances to rebase for M in Mlist: debug('Working on %s' % (M.get('identifier'))) M.git().fetch(C.get('upstreamRemote'))
C = Conf() # Arguments parser = argparse.ArgumentParser(description='Completely remove an instance') parser.add_argument('name', help='name of the instance') parser.add_argument('-y', action='store_true', help='do not ask for confirmation', dest='do') args = parser.parse_args() Wp = workplace.Workplace() try: M = Wp.get(args.name) except: debug('This is not a Moodle instance') sys.exit(1) if not args.do: confirm = raw_input('Are you sure? (Y/n) ') if confirm != 'Y': debug('Exiting...') sys.exit(0) debug('Removing %s...' % args.name) try: Wp.delete(args.name) except OSError: debug('Error while deleting the instance.') debug('This is probably a permission issue.') debug('Run: sudo chmod -R 0777 %s' % Wp.getPath(args.name))
help='runs the script on the integration instances', dest='integration') parser.add_argument('-s', '--stable', action='store_true', help='runs the script on the stable instances', dest='stable') parser.add_argument('names', metavar='names', default=None, nargs='*', help='name of the instances') args = parser.parse_args() # Check configuration file debug('[Config file]') distSettings = Conf(os.path.dirname(__file__), 'config-dist.json').get() allSettings = C.get() errors = [] def dictCompare(orig, mine, path=''): for k in orig: currentpath = path + '.' + k currentpath = currentpath.strip('.') if k not in mine: errors.append(currentpath) elif type(orig[k]) in (dict, list): dictCompare(orig[k], mine[k], currentpath)
path = os.path.abspath(os.path.realpath(os.path.expanduser(path))) return path # Arguments parser = argparse.ArgumentParser( description='Initialise MDK for the current user.') parser.add_argument('-f', '--force', action='store_true', help='Force the initialisation') args = parser.parse_args() # Check root. if os.getuid() != 0: debug('You must execute this as root.') debug(' sudo mdk init') sys.exit(1) # Check what user we want to initialise for. while True: username = question('What user are you initialising MDK for?', get_current_user()) try: user = pwd.getpwnam(username) except: debug('Error while getting information for user %s' % (username)) continue try: usergroup = grp.getgrgid(user.pw_gid)
parser.add_argument('-i', '--integration', action='store_true', help='runs the script on the integration instances', dest='integration') parser.add_argument('-s', '--stable', action='store_true', help='runs the script on the stable instances', dest='stable') parser.add_argument('names', metavar='names', default=None, nargs='*', help='name of the instances') args = parser.parse_args() # Resolving instances names = args.names if args.all: names = Wp.list() elif args.integration or args.stable: names = Wp.list(integration = args.integration, stable = args.stable) # Doing stuff Mlist = Wp.resolveMultiple(names) if len(Mlist) < 1: debug('No instances to work on. Exiting...') sys.exit(1) for M in Mlist: debug('Purging cache on %s' % (M.get('identifier'))) try: M.purge() except Exception as e: debug(e) else: debug('Cache purged!') debug('') debug('Done.')
l = Wp.list(integration=args.integration, stable=args.stable) else: l = Wp.list() l.sort() for i in l: if not args.nameonly: M = Wp.get(i) print '{0:<25}'.format(i), M.get('release') else: print i # Loading instance else: M = Wp.resolve(args.name) if not M: debug('This is not a Moodle instance') sys.exit(1) # Printing/Editing variable. if args.var != None: # Edit a value. if args.edit != None: val = args.edit if val.startswith('b:'): val = True if val[2:].lower() in ['1', 'true'] else False elif val.startswith('i:'): try: val = int(val[2:]) except ValueError: # Not a valid int, let's consider it a string. pass
metavar='names', default=None, nargs='*', help='name of the instances') args = parser.parse_args() # Resolving instances names = args.names if args.all: names = Wp.list() elif args.integration or args.stable: names = Wp.list(integration=args.integration, stable=args.stable) # Doing stuff Mlist = Wp.resolveMultiple(names) if len(Mlist) < 1: debug('No instances to work on. Exiting...') sys.exit(1) for M in Mlist: debug('Running \'%s\' on \'%s\'' % (args.script, M.get('identifier'))) try: M.runScript(args.script, stderr=None, stdout=None) except Exception as e: debug('Error while running the script on %s' % M.get('identifier')) debug(e) else: debug('') debug('Done.')
parser.add_argument('-i', '--integration', action='store_true', help='runs the script on the integration instances', dest='integration') parser.add_argument('-n', '--no-checkout', action='store_true', help='do not checkout the stable branch before upgrading', dest='nocheckout') parser.add_argument('-s', '--stable', action='store_true', help='runs the script on the stable instances', dest='stable') parser.add_argument('-u', '--update', action='store_true', help='update the instance before running the upgrade script', dest='update') parser.add_argument('names', metavar='names', default=None, nargs='*', help='name of the instances') args = parser.parse_args() names = args.names if args.all: names = Wp.list() elif args.integration or args.stable: names = Wp.list(integration = args.integration, stable = args.stable) Mlist = Wp.resolveMultiple(names) if len(Mlist) < 1: debug('No instances to work on. Exiting...') sys.exit(1) errors = [] for M in Mlist: if args.update: debug('Updating %s...' % M.get('identifier')) try: M.update() except Exception as e: errors.append(M) debug('Error during update. Skipping...') debug(e) continue debug('Upgrading %s...' % M.get('identifier'))
'--run', action='store_true', help='also run the tests') parser.add_argument('name', metavar='name', default=None, nargs='?', help='name of the instance') args = parser.parse_args() Wp = workplace.Workplace(C.get('dirs.storage')) # Loading instance M = Wp.resolve(args.name) if not M: debug('This is not a Moodle instance') sys.exit(1) # Check if installed if not M.get('installed'): debug('This instance needs to be installed first') sys.exit(1) # Run cli try: M.initPHPUnit(force=args.force) debug('PHPUnit ready!') if args.run: debug('Running PHPUnit') process('phpunit', M.path, None, None) except Exception as e:
sys.exit() # Arguments parser = argparse.ArgumentParser(description='Manage your aliases') parser.add_argument('command', metavar='command', choices=['list', 'show', 'add', 'remove'], help='the action to perform') parser.add_argument('arguments', type=str, metavar='arguments', default=None, nargs=argparse.REMAINDER, help='arguments for the command') args = parser.parse_args() if args.command == 'list': aliases = C.get('aliases') for alias, command in aliases.items(): print '{0:<20}: {1}'.format(alias, command) elif args.command == 'show': if len(args.arguments) != 1: debug('Too few/many arguments. One needed: moodle alias show aliasName') sys.exit(1) alias = C.get('aliases.%s' % args.arguments[0]) if alias != None: debug(alias) elif args.command == 'add': if len(args.arguments) < 2: debug('Too few/many arguments. Two needed: moodle alias add aliasName Command To Perform') sys.exit(1) alias = args.arguments[0] command = ' '.join(args.arguments[1:]) C.add('aliases.%s' % alias, command) elif args.command == 'remove': if len(args.arguments) != 1:
parser.add_argument('name', metavar='name', default=None, nargs='?', help='name of the instance to backport from. Can be omitted if branch is specified.') parser.add_argument('-v', '--versions', metavar='version', required=True, nargs='+', choices=[str(x) for x in range(13, int(C.get('masterBranch')))] + ['master'], help='versions to backport to') args = parser.parse_args() M = None branch = args.branch versions = args.versions remote = args.remote integration = args.integration if remote == None: remote = C.get('myRemote') # If we don't have a branch, we need an instance M = Wp.resolve(args.name) if not M and not branch: debug('This is not a Moodle instance') sys.exit(1) # Getting issue number if M and not branch: branch = M.currentBranch() # Parsing the branch parsedbranch = tools.parseBranch(branch, C.get('wording.branchRegex')) if not parsedbranch: debug('Could not extract issue number from %s' % branch) sys.exit(1) issue = parsedbranch['issue'] suffix = parsedbranch['suffix'] version = parsedbranch['version']
from lib.tools import debug from lib.config import Conf Wp = workplace.Workplace() C = Conf() # Arguments parser = argparse.ArgumentParser(description="Pull a branch from a tracker issue.") parser.add_argument('-i', '--integration', action='store_true', help='checkout the stable branch before proceeding to the pull (Integration mode).') parser.add_argument('-t', '--testing', action='store_true', help='checkout a testing branch before proceeding to the pull (Testing mode).') parser.add_argument('issue', metavar='issue', default=None, nargs='?', help='tracker issue to pull from (MDL-12345, 12345). If not specified, read from current branch.') args = parser.parse_args() M = Wp.resolve() if not M: debug('This is not a Moodle instance') sys.exit(1) if args.testing and args.integration: debug('You cannot combine --integration and --testing') sys.exit(1) # Tracker issue number. issuenb = args.issue if not issuenb: parsedbranch = tools.parseBranch(M.currentBranch(), C.get('wording.branchRegex')) if not parsedbranch: debug('Could not extract issue number from %s' % M.currentBranch()) sys.exit(1) issuenb = parsedbranch['issue']
help='scripts to run after installation', metavar='run') parser.add_argument('name', metavar='name', default=None, nargs='?', help='name of the instance') args = parser.parse_args() name = args.name engine = args.engine fullname = args.fullname M = Wp.resolve(name) if not M: debug('This is not a Moodle instance') sys.exit(1) name = M.get('identifier') dataDir = Wp.getPath(name, 'data') if not os.path.isdir(dataDir): os.mkdir(dataDir, 0777) kwargs = {'engine': engine, 'fullname': fullname, 'dataDir': dataDir} M.install(**kwargs) # Running scripts if M.isInstalled() and type(args.run) == list: for script in args.run: debug('Running script \'%s\'' % (script)) try:
def resolve_directory(path, user): if path.startswith('~'): path = re.sub(r'^~', '~%s' % user, path) path = os.path.abspath(os.path.realpath(os.path.expanduser(path))) return path # Arguments parser = argparse.ArgumentParser(description='Initialise MDK for the current user.') parser.add_argument('-f', '--force', action='store_true', help='Force the initialisation') args = parser.parse_args() # Check root. if os.getuid() != 0: debug('You must execute this as root.') debug(' sudo mdk init') sys.exit(1) # Check what user we want to initialise for. while True: username = question('What user are you initialising MDK for?', get_current_user()) try: user = pwd.getpwnam(username) except: debug('Error while getting information for user %s' % (username)) continue try: usergroup = grp.getgrgid(user.pw_gid) except: