def markpress_update(filename): doc = markpress_load(filename) if not doc: return -1 uuid = doc._uuid post = {} post['id'] = uuid post['title'] = doc._title post['content'] = markpress_render(doc) status = doc._status if status not in ('', 'draft', 'private', 'publish'): config.perror(filename, 1, 'invalid status %s' % status) return -3 post['status'] = status and status or 'draft' if doc._cats: post['category'] = doc._cats if doc._tags: post['tag'] = doc._tags if doc._slug: post['slug'] = doc._slug if doc._date: post['date'] = utils.utc_datetime(doc._date) wp = config.wp_client() wp.post_edit(post) pp = wp.post_get(uuid) print('post uuid=%s updated: %s' % (uuid, filename)) print('%s' % pp.link) return 0
def openConfig(self): try: with open(self.config["config_file"], "r") as config: return self.parse(config) except IOError: perror("Config File not found") return 0
def cloneThatRepo(self): pinfo("Cloning the repository...") os.chdir(self.config["repo_dir"]) proc = Popen(["git", "clone", self.url], stdout=PIPE, stderr=PIPE) stdout, stderr = proc.communicate() if stderr != "" and "already exists" in stderr: perror("Repository already exists")
def markpress_load(filename): if not os.path.exists(filename): config.fatal('file not find: ' + filename) doc = utils.MarkdownDoc(filename) if not doc._uuid: config.perror(filename, 1, 'uuid not find in the markdown meta-header') return None uuid = doc._uuid.strip() if not uuid.isdigit(): config.perror(filename, 1, 'invalid uuid %s' % uuid) return None return doc
def refresh(self, reponame=""): pinfo("Getting newest Version...") if reponame == "": reponame = self.config["github"].split("/")[1] fullPath = self.config["repo_dir"] + "/" + reponame os.chdir(fullPath) proc = Popen(["git", "pull"], stdout=PIPE, stderr=PIPE) stdout, stderr = proc.communicate() if stderr != "": perror(stderr)
def updateRepo(self, reponame=""): pinfo("Updating repository...") if reponame == "": reponame = self.config["github"].split("/")[1] fullPath = self.config["repo_dir"] + "/" + reponame os.chdir(fullPath) procAdd = Popen(["git", "add", "."], stdout=PIPE, stderr=PIPE) stdout, stderr = procAdd.communicate() # Error checking if stderr != "": perror(stderr) procCommit = Popen(["git", "commit", "-m", "c0nfigure"], stdout=PIPE, stderr=PIPE) stdout, stderr = procCommit.communicate() if stderr != "": perror(stderr) procPush = Popen(["git", "push"], stdout=PIPE, stderr=PIPE, stdin=PIPE) procPush.wait() if stderr != "": perror(stderr)
def parse(self, config): try: obj = yaml.safe_load(config) # 1. parse global variables for glVar, _ in self.globals: self.getGlobal(obj, glVar) # 1.2 Check of the required variables are set for name, req in self.globals: if req == True and name not in self.config.keys(): perror("Required global variable %s not found" % name) raise Exception("Required global not found") # 2. parse programs folders = [ key for key in obj.keys() if key not in [x for x, _ in self.globals] ] # the adjustPath call, repaces ~ with the homepath # Dict with prorgams as keys, and list of replacement files as value self.replacement_rel = { key: self.adjustPath(obj[key]) for key in folders } return 1 except Exception as e: print e.message perror("Failed to parse config") return 0