def create(self, title="tessera title goes here"): """ create a new tessera with title {title}. @returns Tessera object of the new Tessera """ uuid = uuid1() tessera_path = os.path.join(Tessera._tesserae, str(uuid)) tessera_file = "%s/tessera" % tessera_path os.mkdir(tessera_path) fin = open(os.path.join(Tessera._tesserae, "template"), "r") fout = open(tessera_file, "w") for line in fin.readlines(): if line == "@title@\n": line = "# %s\n" % title fout.write(line) fin.close() fout.close() tessera_info = "%s/info" % tessera_path fout = open(tessera_info, "w") c = StackedConfig(StackedConfig.default_backends()) fout.write("author: %s\n" % c.get("user", "name")) fout.write("email: %s\n" % c.get("user", "email")) fout.write("updated: %d\n" % int(time())) fout.close() return Tessera(tessera_path, self._config)
def _configure(self): """ Parse configuration from git config """ sc = StackedConfig(StackedConfig.default_backends()) self.config = {} # Get top level directory of project proc = subprocess.Popen(['git', 'rev-parse', '--show-toplevel'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) self.config['top_dir'] = proc.communicate()[0] if proc.returncode != 0: exit_code = 20 log.error("{0}::{1}".format(__name__, exit_codes[exit_code])) sys.exit(exit_code) self.config['deploy_file'] = self.config['top_dir'] + '/.git' try: self.config['hook_dir'] = sc.get('deploy', 'hook-dir') except KeyError: exit_code = 21 log.error("{0}::{1}".format(__name__, exit_codes[exit_code])) sys.exit(exit_code) try: self.config['repo_name'] = sc.get('deploy', 'tag-prefix') except KeyError: exit_code = 22 log.error("{0}::{1}".format(__name__, exit_codes[exit_code])) sys.exit(exit_code) self.config['sync_dir'] = '{0}/sync'.format(self.config['hook_dir'])
def create(self, title="tessera title goes here"): """ create a new tessera with title {title}. @returns Tessera object of the new Tessera """ uuid = uuid1() tessera_path = os.path.join(Tessera._tesserae, str(uuid)) tessera_file = "%s/tessera" % tessera_path os.mkdir(tessera_path) fin = open(os.path.join(Tessera._tesserae, "template"), "r") fout = open(tessera_file, "w") for line in fin.readlines(): if line == "@title@\n": line = "# %s\n" % title fout.write(line) fin.close() fout.close() tessera_info = "%s/info" % tessera_path fout = open(tessera_info, "w") c = StackedConfig(StackedConfig.default_backends()) fout.write("author: %s\n"%c.get("user", "name")) fout.write("email: %s\n"%c.get("user", "email")) fout.write("updated: %d\n"%int(time())) fout.close() return Tessera(tessera_path, self._config)
def sync(self, no_deps=False, force=False): """ * add a sync tag * write a .deploy file with the tag information * call a sync hook with the prefix (repo) and tag info """ # TODO: do git calls in dulwich, rather than shelling out # TODO: get all configuration via a function, and get it during main if "lock" not in os.listdir(".git/deploy"): exit_code = 20 log.error("{0}::{1}".format(__name__, exit_codes[exit_code])) return exit_code sc = StackedConfig(StackedConfig.default_backends()) try: hook_dir = sc.get("deploy", "hook-dir") except KeyError: exit_code = 21 log.error("{0}::{1}".format(__name__, exit_codes[exit_code])) return exit_code try: repo_name = sc.get("deploy", "tag-prefix") except KeyError: exit_code = 22 log.error("{0}::{1}".format(__name__, exit_codes[exit_code])) return exit_code sync_dir = "{0}/sync".format(hook_dir) sync_script = "{0}/{1}.sync".format(sync_dir, repo_name) _tag = "{0}-sync-{1}".format(repo_name, datetime.now().strftime(DATE_TIME_TAG_FORMAT)) proc = subprocess.Popen(["/usr/bin/git tag", "-a", _tag]) if proc.returncode != 0: exit_code = 23 log.error("{0}::{1}".format(__name__, exit_codes[exit_code])) return exit_code # TODO: use a pluggable sync system rather than shelling out if os.path.exists(sync_script): proc = subprocess.Popen( [ sync_script, '--repo="{0}"'.format(repo_name), '--tag="{0}"'.format(_tag), '--force="{0}"'.format(force), ] ) log.info(proc.stdout.read()) if proc.returncode != 0: exit_code = 24 log.error("{0}::{1}".format(__name__, exit_codes[exit_code])) return exit_code
def configure(**kwargs): """ Parse configuration from git config """ sc = StackedConfig(StackedConfig.default_backends()) config = {} # Get top level directory of project proc = subprocess.Popen(['git', 'rev-parse', '--show-toplevel'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) config['top_dir'] = proc.communicate()[0].strip() if proc.returncode != 0: exit_code = 20 log.error("{0} :: {1}".format(__name__, exit_codes[exit_code])) sys.exit(exit_code) config['deploy_file'] = config['top_dir'] + '/.git/.deploy' # Define the key names, git config names, and error codes config_elements = { 'hook_dir': ('deploy', 'hook-dir', 21), 'path': ('deploy', 'path', 23), 'user': ('deploy', 'user', 24), 'target': ('deploy', 'target', 25), 'repo_name': ('deploy', 'tag-prefix', 22), 'remote': ('deploy', 'remote', 26), 'branch': ('deploy', 'branch', 27), 'client_path': ('deploy', 'client-path', 19), 'user.name': ('user', 'name', 28), 'user.email': ('user', 'email', 29), 'deploy.key_path': ('deploy', 'key-path', 37), 'deploy.test_repo': ('deploy', 'test-repo-path', 38), } # Assign the values of each git config element for key, value in config_elements.iteritems(): try: # Override with kwargs if the attribute exists if key in kwargs: config[key] = kwargs[key] else: config[key] = sc.get(value[0], value[1]) except KeyError: exit_code = value[2] log.error("{0} :: {1}".format(__name__, exit_codes[exit_code])) sys.exit(exit_code) config['sync_dir'] = '{0}/sync'.format(config['hook_dir']) return config
def create(cls, basepath, title): t_id = str(generate_uniq_id()) t_path = os.path.join(basepath, t_id) t_file = os.path.join(t_path, Tessera.TESSERA_FILENAME) t_info = os.path.join(t_path, Tessera.INFO_FILENAME) os.makedirs(t_path) with open(Tessera.NEW_TESSERA_TEMPLATE, "r") as fin: with open(t_file, "w+") as fout: for l in fin.readlines(): if l == "@title@\n": l = "# %s\n" % title fout.write(l) with open(t_info, "w+") as f: c = StackedConfig(StackedConfig.default_backends()) f.write("author: %s\n" % c.get("user", "name")) f.write("email: %s\n" % c.get("user", "email")) f.write("updated: %s\n" % datetime.now().strftime("%Y-%m-%dT%H:%M:%S")) t = Tessera(t_id, t_path) return t