def main(): global interface global quit global runInBackground if (len(argv) > 1): if (argv[1] == "-b"): runInBackground = True messages.clear() # Start the interface interface = networkingInterface.Interface() # Get configuration if it is not running in background if (not runInBackground): newhost = getHostFromUser() newport = getPortFromUser() terminal.clear() log("Host is set to be " + newhost + " using port " + str(newport), terminal.Foreground.LIME) interface.configure(newhost, newport) # Bind to a local endpoint if (interface.becomeHost()): log("Ready to internet!", terminal.Foreground.LIME) else: if (not runInBackground): terminal.error("Unable to internet :(") return # Set the timeout for a minute to perform other tasks when there are no responses interface.setTimeout(60) # Display the logo if (not runInBackground): terminal.logo() # Add the server as a participant addUser(interface.getHost(), "Sudo the Server") # main loop while (not quit): try: # Check activity then process recieved messages checkUserTimeouts() data = interface.recieve() processMessage(data) except KeyboardInterrupt: # Handle ctrl+c quit = True log("Manual shutdown", terminal.Foreground.RED) except: # Log any errors log(format_exc(), terminal.Foreground.YELLOW) # Broadcast shutdown shutDown()
def pull(self, repo): if not util.checkRemote(repo): error = "{0} has a different remote on disk than in config".format(repo['local']) terminal.error("\n" + error) dolly.Dolly.warnings.append(error) if util.isGitRepo(repo): self.pullGit(repo) else: self.pullSvn(repo)
def add_to_topic(self, topic, entry): if len(topic) > 0: if topic[0] not in self.subtopics: terminal.error(u"In entry {0}: unknown (sub)topic {1}".format( entry, topic), abort=True) else: self.subtopics[topic[0]].add_to_topic(topic[1:], entry) else: self.entries.append(entry)
def parse(filename): parser = configparser.RawConfigParser(dict_type=OrderedDict) try: parser.readfp(codecs.open(filename, encoding='UTF-8', errors='strict')) return OrderedDict((sec, validate(sec, dict(parser.items(sec)))) for sec in parser.sections()) except UnicodeDecodeError as ex: error(u"In file {0}: invalid UTF-8 character".format(filename), exception=ex, abort=True)
def statusSvn(self, repo): if not util.isSvnCheckout(repo): error = "{0} is a Svn repo in config file but not a Svn checkout on disk".format(repo['local']) terminal.error("\n" + error) dolly.Dolly.warnings.append(error) return result = util.executeCommand('svn status', cwd=repo['local']) for line in result['stdout'].splitlines(): change = os.path.join(repo['local'], ' '.join(line.split()[1:])) dolly.Dolly.changes.append({'repo': repo, 'change': change})
def statusSvn(self, repo): if not util.isSvnCheckout(repo): error = "{0} is a Svn repo in config file but not a Svn checkout on disk".format( repo['local']) terminal.error("\n" + error) dolly.Dolly.warnings.append(error) return result = util.executeCommand('svn status', cwd=repo['local']) for line in result['stdout'].splitlines(): change = os.path.join(repo['local'], ' '.join(line.split()[1:])) dolly.Dolly.changes.append({'repo': repo, 'change': change})
def status(self, repo): if not os.path.exists(repo['local']): dolly.Dolly.not_cloned.append(repo) return if not util.checkRemote(repo): error = "{0} has a different remote on disk than in config".format(repo['local']) terminal.error("\n" + error) dolly.Dolly.warnings.append(error) if util.isGitRepo(repo): self.statusGit(repo) else: self.statusSvn(repo)
def status(self, repo): if not os.path.exists(repo['local']): dolly.Dolly.not_cloned.append(repo) return if not util.checkRemote(repo): error = "{0} has a different remote on disk than in config".format( repo['local']) terminal.error("\n" + error) dolly.Dolly.warnings.append(error) if util.isGitRepo(repo): self.statusGit(repo) else: self.statusSvn(repo)
def statusGit(self, repo): if not util.isGitCheckout(repo): error = "{0} is a Git repo in config file but not a Git checkout on disk".format(repo['local']) terminal.error("\n" + error) dolly.Dolly.warnings.append(error) return result = util.executeCommand('git status -s', cwd=repo['local']) for line in result['stdout'].splitlines(): change = os.path.join(repo['local'], ' '.join(line.split()[1:])) dolly.Dolly.changes.append({'repo': repo, 'change': change}) result = util.executeCommand('git status -s -b', cwd=repo['local']) if result['stdout']: if 'ahead' in result['stdout']: dolly.Dolly.unpushed.append(repo)
def statusGit(self, repo): if not util.isGitCheckout(repo): error = "{0} is a Git repo in config file but not a Git checkout on disk".format( repo['local']) terminal.error("\n" + error) dolly.Dolly.warnings.append(error) return result = util.executeCommand('git status -s', cwd=repo['local']) for line in result['stdout'].splitlines(): change = os.path.join(repo['local'], ' '.join(line.split()[1:])) dolly.Dolly.changes.append({'repo': repo, 'change': change}) result = util.executeCommand('git status -s -b', cwd=repo['local']) if result['stdout']: if 'ahead' in result['stdout']: dolly.Dolly.unpushed.append(repo)
def validate(entry, attributes): sane_attributes = {} missing_keys = [] processed_keys = set() for key, (split, processor, default) in metadata.attribute_schema.items(): if processor is None: processor = lambda str, **kwargs: str if key.endswith("*"): shortkey = key[:len(key) - 1] result = OrderedDict() process = partial(processor, entry=entry, shortkey=shortkey) for appkey, str in attributes.items(): if appkey.startswith(shortkey + "-"): processed_keys.add(appkey) app = appkey[len(shortkey) + 1:] if not split: result[app] = process(str.strip(), appendix=app) else: result[app] = [ process(s.strip(), appendix=app) for s in str.split(',') ] sane_attributes[shortkey] = result else: process = partial(processor, entry=entry, key=key) if default is None and key not in attributes: missing_keys.append(key) sane_attributes[key] = process("") if not split else [] else: value = attributes[key] if key in attributes else default processed_keys.add(key) if not split: sane_attributes[key] = process(value) else: sane_attributes[key] = [ process(s.strip()) for s in value.split(',') ] if missing_keys: error(u"In entry {0}: missing key(s) {1!s}".format( entry, missing_keys), abort=True) extraneous_keys = set(attributes.keys()) - processed_keys if extraneous_keys: warn(u"In entry {0}: unknown key(s) {1!s}. Have you misspelled them?". format(entry, list(extraneous_keys))) return sane_attributes
def run(self): if not self.args.command == 'list-dirs': self.banner() config_system = '/etc/dolly/dolly.yml' config_user = os.path.expanduser('~/.dolly.yml') if self.args.config: self.config=self.args.config elif os.path.exists(config_user): self.config = config_user elif os.path.exists(config_system): self.config = config_system else: terminal.error('No valid config file found') return parser = config.Config(self.config) self.startproject = parser.parse(self.args.project) self.countProjects() self.run_visitor()
def parse(self, name): if not (name in self.data): terminal.error("Project doesn't exist in config file") sys.exit(0) proj = self.data[name] tree = [] includes = [] description = '' post_update=None if 'tree' in proj: tree = self.__normalizeTree(proj['tree']) if 'includes' in proj: includes = proj['includes'] if 'description' in proj: description = proj['description'] if 'post_update' in proj: post_update = proj['post_update'] return project.Project(name, description, tree, includes, self, post_update)
def parse(self, name): if not (name in self.data): terminal.error("Project doesn't exist in config file") sys.exit(0) proj = self.data[name] tree = [] includes = [] description = '' post_update = None if 'tree' in proj: tree = self.__normalizeTree(proj['tree']) if 'includes' in proj: includes = proj['includes'] if 'description' in proj: description = proj['description'] if 'post_update' in proj: post_update = proj['post_update'] return project.Project(name, description, tree, includes, self, post_update)
def executeCommand(command, cwd=None): proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd, bufsize=0) output = '' if dolly.Dolly.verbose: print '' for line in iter(proc.stdout.readline, ''): sys.stdout.write(line) output += line stdout, stderr = proc.communicate() output += stdout returncode = proc.returncode if not returncode == 0: print '' terminal.error('Error while executing command "{0}"'.format(command)) terminal.error(output) terminal.error(stderr) dolly.Dolly.warnings.append( 'Error while executing command "{0}" in "{1}"'.format( command, cwd)) return {'returncode': returncode, 'stdout': output, 'stderr': stderr}
def executeCommand(command, cwd=None, tmux=False, name=None): if tmux and os.getenv('TMUX') != None: # We seem to be inside a tmux window, so try using a tmux split # instead. If this turns out to be wrong or doesn't work for some other # reason, fall back to the usual execution. try: return executeTmuxCommand(command, cwd, name) except subprocess.CalledProcessError: pass proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd, bufsize=0) output = '' if dolly.Dolly.verbose: print '' for line in iter(proc.stdout.readline, ''): sys.stdout.write(line) output += line stdout, stderr = proc.communicate() output += stdout returncode = proc.returncode if not returncode == 0: print '' terminal.error('Error while executing command "{0}"'.format(command)) terminal.error(output) terminal.error(stderr) dolly.Dolly.warnings.append('Error while executing command "{0}" in "{1}"'.format(command, cwd)) return {'returncode': returncode, 'stdout': output, 'stderr': stderr}
def read_versions(filename): versions = [] try: with open(filename) as input: for line in input: try: version, release_date = line.split(" = ") except ValueError as ex: error(u"In file {0}: Malformed association {1}".format( filename, line), exception=ex) error("Not processing releases") return [] else: versions.append((version, release_date.strip())) except Exception as ex: error(u"In file {0}: error".format(filename), exception=ex) error("Not processing releases") return [] else: versions.sort(key=itemgetter(1), reverse=True) return versions
def associate_releases(entries, versions, filename): for _, attributes in entries.items(): attributes['releases'] = OrderedDict() prog = re.compile(release_pattern) warnings = {} try: with open(filename) as input: lines = [] for line in input: line = line.strip() result = prog.match(line) try: entry, date = result.groups() except ValueError as ex: error(u"In file {0}: Malformed release {1}".format( filename, line.replace), exception=ex) else: if not entry in entries: if not entry in warnings: warnings[entry] = [line] else: warnings[entry].append(line) else: lines.append((entry, date)) for entry, releases in warnings.items(): warn(u"In file {0}: In release(s) {1!s}: Unknown entry {2}".format( filename, releases, entry)) lines.sort(reverse=True) for line in lines: found = False entry, date = line for version_number, version_date in versions: if version_date <= date: entry_releases = entries[entry]['releases'] if version_number not in entry_releases: entry_releases[version_number] = [] entry_releases[version_number].append(date) found = True break if not found: warn( u"In file {0}: In release {1}: Release date {2} has no matching version" .format(filename, line, date)) except Exception as ex: error(u"In file {0}: error".format(filename), exception=ex) error("Not processing releases")
def executeCommand(command, cwd=None): proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd, bufsize=0) output = '' if dolly.Dolly.verbose: print '' for line in iter(proc.stdout.readline, ''): sys.stdout.write(line) output += line stdout, stderr = proc.communicate() output += stdout returncode = proc.returncode if not returncode == 0: print '' terminal.error('Error while executing command "{0}"'.format(command)) terminal.error(output) terminal.error(stderr) dolly.Dolly.warnings.append('Error while executing command "{0}" in "{1}"'.format(command, cwd)) return {'returncode': returncode, 'stdout': output, 'stderr': stderr}
if 'idlelib.run' in sysModule.modules: print("You probably want to run this from the command line.") else: terminal.out(""" ██╗ ██╗ █████╗ ██████╗██╗ ██╗███████╗██╗ ██╗███████╗\n\ ██║ ██║██╔══██╗██╔════╝██║ ██╔╝██╔════╝╚██╗ ██╔╝██╔════╝\n\ ███████║███████║██║ █████╔╝ ███████╗ ╚████╔╝ ███████╗\n\ ██╔══██║██╔══██║██║ ██╔═██╗ ╚════██║ ╚██╔╝ ╚════██║\n\ ██║ ██║██║ ██║╚██████╗██║ ██╗███████║ ██║ ███████║\n\ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚══════╝\n\ version {} """.format(__version__)) time.sleep(2) utils.serverBootSequence(sysCont.userSystem, terminal) while True: if sysCont.userSystem.status == system.Statuses.UNBOOTABLE: terminal.error("ERROR: SYSTEM UNBOOTABLE") while True: continue userInput = terminal.get(sysCont.userSystem.IP + sysCont.userSystem.fileSystem.getPath()) ret = comCont.feed(userInput, sysCont, sysCont.userSystem, terminal) comCont.outputType = 0 terminal.out('') if ret == 99: sysModule.exit() else: save.save(sysCont) continue
def main(): usage = "sitegen.py [-h] [--templates TEMPLATES_DIR --dest DEST_DIR] [--status STATUS_FILE] [--deps DEPS_FILE] METADATA_DIR THYS_DIR" parser = argparse.ArgumentParser(usage=usage) parser.add_argument("metadata_dir", metavar="METADATA_DIR", action="store", help="metadata location") parser.add_argument("thys_dir", metavar="THYS_DIR", action="store", help="directory with afp entries") parser.add_argument("--templates", action="store", dest="templates_dir", help="directory with Jinja2 templates") parser.add_argument("--dest", action="store", dest="dest_dir", help="destination dir for generated html files") parser.add_argument("--status", action="store", dest="status_file", help="status file location (devel)") parser.add_argument("--deps", action="store", dest="deps_file", help="dependencies file location") parser.parse_args(namespace=options) options.is_devel = options.status_file is not None if options.dest_dir and not options.templates_dir: error("Please specify templates dir", abort=True) # parse metadata entries = parse(os.path.join(options.metadata_dir, "metadata")) versions = read_versions( os.path.join(options.metadata_dir, "release-dates")) associate_releases(entries, versions, os.path.join(options.metadata_dir, "releases")) if len(entries) == 0: warn("In metadata: No entries found") # generate depends-on, used-by entries, lines of code and number of lemmas # by using an afp_dict object # TODO: error instead of warn deps_dict = metadata.empty_deps(entries) if options.deps_file: with open(options.deps_file, 'r') as df: deps_dict = metadata.read_deps(df) else: warn("No dependencies file specified") afp_dict = afpstats.afp_dict(entries, options.thys_dir, deps_dict) afp_dict.build_stats() for e in entries: entries[e]['depends-on'] = list(map(str, afp_dict[e].imports)) entries[e]['used-by'] = list(map(str, afp_dict[e].used)) # perform check count = check_fs(entries, options.thys_dir) output = "Checked directory {0}. Found {1} warnings.".format( options.thys_dir, count) color = 'yellow' if count > 0 else 'green' print(colored(output, color, attrs=['bold'])) # perform generation if options.dest_dir: if options.status_file is not None: (build_data, status) = parse_status(options.status_file) for a in afp_dict: if a in status: afp_dict[a].status = status[a] else: afp_dict[a].status = "skipped" else: build_data = dict() builder = templates.Builder(options, entries, afp_dict) builder.generate_topics() builder.generate_index() builder.generate_entries() builder.generate_statistics() builder.generate_download() for s in [ "about", "citing", "updating", "search", "submitting", "using" ]: builder.generate_standard(s + ".html", s + ".tpl") builder.generate_rss(30) #TODO: look over it one more time if options.is_devel: builder.generate_status(build_data)
def printErrors(): for message in errors: terminal.error(message)