def copy(self, src, dst, new_extension=None): """Copy the resource Args: src (str): resource location dst (str): destination """ try: self.exists(src, True) if self.is_dir(src): mkdir(dst, recursive=True) real_src = src walk_files = self.walk(real_src) for walk_file in walk_files: real_src = src.rstrip('/') + '/' + walk_file.strip('/') real_dst = dst.rstrip('/') + '/' + walk_file.strip('/') if self.is_dir(real_src): mkdir(real_dst, recursive=True) else: content = self.read(real_src) if new_extension is not None and f_exists(real_dst): real_dst += "." + new_extension.strip('.') print("Copy file %s:%s to %s" % ( self._module, real_src, real_dst, )) with open(real_dst, 'wb') as new_file: new_file.write(content) else: content = self.read(src) src_file = src.strip('/').split('/')[-1] if is_dir(dst): dst = dst.rstrip('/') + '/' + src_file if new_extension is not None and f_exists(dst): dst += "." + new_extension.strip('.') print("Copy file %s:/%s to %s" % ( self._module, src, dst, )) with open(dst, 'wb') as new_file: new_file.write(content) except ImportError: raise ImportError(self._module) from None
def setup(req, resp): module = Module('calabiyau') mkdir("/var/tachyonic") mkdir("/etc/tachyonic") mkdir("/etc/tachyonic/freeradius") mkdir("/etc/tachyonic/freeradius/proxy") for i in range(6): module.copy('config/freeradius/acct%s.conf' % str(i + 1), '/etc/tachyonic/freeradius/acct%s.conf' % str(i + 1)) module.copy('config/freeradius/auth%s.conf' % str(i + 1), '/etc/tachyonic/freeradius/auth%s.conf' % str(i + 1)) module.copy('config/freeradius/clients', '/etc/tachyonic/freeradius/clients', 'default') module.copy('config/freeradius/log.conf', '/etc/tachyonic/freeradius/log.conf', 'default') module.copy('config/freeradius/dictionary', '/etc/tachyonic/freeradius/dictionary') module.copy('config/freeradius/mods-config', '/etc/tachyonic/freeradius/mods-config') module.copy('config/freeradius/modules', '/etc/tachyonic/freeradius/modules') module.copy('config/freeradius/policy', '/etc/tachyonic/freeradius/policy') module.copy('config/freeradius/proxy/proxy.conf', '/etc/tachyonic/freeradius/proxy/proxy.conf') module.copy('config/freeradius/proxy/radius.conf', '/etc/tachyonic/freeradius/proxy/radius.conf', 'default') module.copy('config/freeradius/proxy.conf', '/etc/tachyonic/freeradius/proxy.conf') module.copy('config/freeradius/python', '/etc/tachyonic/freeradius/python') module.copy('config/freeradius/servers.conf', '/etc/tachyonic/freeradius/servers.conf') module.copy('config/freeradius/sites', '/etc/tachyonic/freeradius/sites')
def setup(args): """Setup Tachyonic Package with Luxon Creates relevant directories and copies relevant files Called when **-i** is used Args: args (parse_args object): arguments gathered from terminal """ path = args.path.rstrip('/') module = Module(args.pkg) no_install = ['luxon', 'psychokinetic'] if args.pkg in no_install: print("Your suppose to install luxon applications not '%s'" % args.pkg) exit() def copy(name, new_extension=None): if module.exists(name): module.copy(name, path + '/' + name, new_extension=new_extension) mkdir(path) if (module.exists('etc')): mkdir("/etc/tachyonic") module.copy('etc', '/etc/tachyonic', 'default') mkdir(joinpath(path, 'tmp')) copy('policy.json', 'default') copy('settings.ini', 'default') try: if exists(path + '/settings.ini'): chmod(path + '/settings.ini', 640) except PermissionError: pass copy('wsgi.py', 'default') copy('static') mkdir('%s/templates/%s' % (path, args.pkg), recursive=True)
def github(req, resp): root_path = g.app.path mkdir(joinpath(root_path, 'github')) mkdir(joinpath(root_path, 'docs')) try: projects = load(root_path + '/projects.pickle') except FileNotFoundError: projects = {} username = g.app.config.get('github', 'username') password = g.app.config.get('github', 'password') tachyonic = GitHub(auth=(username, password)) while True: try: teams = {} github_teams = tachyonic.teams('TachyonicProject') for github_team in github_teams: team = github_team['name'] if team == "Author": continue teams[team] = {} github_members = tachyonic.team_members(github_team['id']) for github_member in github_members: login = github_member['login'] teams[team][login] = {} teams[team][login]['github'] = github_member['html_url'] teams[team][login]['avatar'] = github_member['avatar_url'] save(teams, root_path + '/team.pickle', perms=664) save(tachyonic.projects('TachyonicProject'), root_path + '/planning.pickle', perms=664) found = [] log.info("Getting Repos") repos = tachyonic.repos('TachyonicProject') for repo in repos: name = repo['name'] found.append(name) description = repo['description'] if name not in projects: projects[name] = {} log.info("Scanning Repo " + name) updated_at = utc(repo['updated_at']) created_at = utc(repo['created_at']) pushed_at = utc(repo['pushed_at']) if (('updated_at' not in projects[name]) or ('updated_at' in projects[name] and updated_at != projects[name]['updated_at']) or ('pushed_at' not in projects[name]) or ('pushed_at' in projects[name] and pushed_at != projects[name]['pushed_at'])): projects[name]['created_at'] = created_at projects[name]['description'] = description projects[name]['clone_url'] = repo['clone_url'] log.info("Getting Branches for %s" % name) branches = tachyonic.branches('TachyonicProject', name) branches = [branch['name'] for branch in branches] projects[name]['branches'] = branches log.info("Getting Tags for %s" % name) tags = tachyonic.tags('TachyonicProject', name) tags = [tag['name'] for tag in tags] projects[name]['tags'] = tags projects[name]['refs'] = version_order(branches + tags) projects[name]['doc_refs'] = {} else: log.info("Project %s Already up-to-date (%s)" % ( name, updated_at, )) projects[name]['updated_at'] = updated_at projects[name]['pushed_at'] = pushed_at if 'updated_doc' not in projects[name]: projects[name]['updated_doc'] = {} for ref in projects[name]['refs']: current_datetime = now() if ref in projects[name]['updated_doc']: commits = tachyonic.commits( 'TachyonicProject', name, sha=ref, since=format_iso8601( projects[name]['updated_doc'][ref])) if len(commits) == 0: log.info("Documentation" + " '%s/%s'" % ( name, ref, ) + " Already up-to-date (%s)" % updated_at) continue venv_dir = "%s/github/%s_%s" % ( root_path, name, ref, ) doc_dir = "%s/docs/%s_%s" % ( root_path, name, ref, ) src_path = venv_dir + '/' + name log.info("Creating Virtual Environment '%s'" % venv_dir) create_env(str(venv_dir), wipe=True, site_packages=False) clone(projects[name]['clone_url'], src_path) if (exists(src_path + '/docs/source/conf.py') and exists(src_path + '/docs/Makefile')): log.info("Bulding '%s/%s'" % ( name, ref, )) projects[name]['doc_refs'][ref] = True info = build_doc(root_path, venv_dir, src_path, ref, doc_dir, name) updated(name, ref, info) else: projects[name]['doc_refs'][ref] = False log.warning("No Sphinx docs found '%s/%s'" % ( name, ref, )) projects[name]['updated_doc'][ref] = current_datetime save(projects, root_path + '/projects.pickle', perms=664) events = [] events_ordered = [] git_events = tachyonic.events('TachyonicProject') for pj in projects.copy(): if pj not in found: del projects[pj] else: for event in git_events: type = event['type'] payload = event['payload'] if type == 'PullRequestEvent': pr = payload['pull_request'] merged = pr['merged'] base = pr['base'] ref = base['ref'] if merged is True: merged_at = utc(pr['merged_at']) events.append((merged_at, "Code Updated", "Repo " + pj + "/" + ref + "")) for item in sorted(events, key=operator.itemgetter(0)): events_ordered.append(item) events_ordered = list(reversed(events_ordered)) save(events_ordered[0:10], root_path + '/events.pickle', perms=664) save(projects, root_path + '/projects.pickle', perms=664) log.info('Infinite loop sleeping 5 Minutes') sleep(300) except KeyboardInterrupt: print("Control-C closed / Killed") break except ExecuteError as e: handle_error(e.title, e.description) except Exception as e: trace = str(traceback.format_exc()) error = '%s: %s' % (object_name(e), e) handle_error(error, trace)