Пример #1
0
 def init(self):
     try:
         process = subprocess.Popen(
             [self.execpath, "init",
              str(self.filepath)],
             cwd=self.filepath,
             stdout=subprocess.PIPE,
             stderr=subprocess.PIPE)
         stdout, stderr = process.communicate()
         if process.returncode > 0:
             raise GitExecutionException(
                 __("error", "controller.code.driver.git.init",
                    str(stderr)))
     except subprocess.CalledProcessError as e:
         raise GitExecutionException(
             __("error", "controller.code.driver.git.init", str(e)))
     try:
         code_refs_success = self.ensure_code_refs_dir()
     except Exception as e:
         raise FileIOException(
             __("error", "controller.code.driver.git.init.file", str(e)))
     try:
         datmo_files_ignored_success = self.ensure_datmo_files_ignored()
     except Exception as e:
         raise FileIOException(
             __("error", "controller.code.driver.git.init.file", str(e)))
     return code_refs_success and datmo_files_ignored_success
Пример #2
0
    def _stats_setup(self, incoming_dictionary, create_dict):
        """Fills in snapshot stats by having one of the following:
            1. stats = JSON object
            2. stats_filepath = some location where a json file exists
            3. stats_filename = just the file name

        Parameters
        ----------
        incoming_dictionary : dict
            dictionary for the create function defined above
        create_dict : dict
            dictionary for creating the Snapshot entity

        Raises
        ------
        FileIOException
        """

        if "stats" in incoming_dictionary:
            create_dict['stats'] = incoming_dictionary['stats']
        elif "stats_filepath" in incoming_dictionary:
            if not os.path.isfile(incoming_dictionary['stats_filepath']):
                raise FileIOException(
                    __("error", "controller.snapshot.create.file_stat"))
            # If path exists transform file to config dict
            stats_json_driver = JSONStore(
                incoming_dictionary['stats_filepath'])
            create_dict['stats'] = stats_json_driver.to_dict()
        elif "stats_filename" in incoming_dictionary:
            stats_filename = incoming_dictionary['stats_filename'] \
                if "stats_filename" in incoming_dictionary else "stats.json"
            create_dict['stats'] = self._find_in_filecollection(
                stats_filename, create_dict['file_collection_id'])
        else:
            create_dict['stats'] = {}
Пример #3
0
 def init(self):
     try:
         # Ensure the Datmo file structure exists
         self.ensure_datmo_file_structure()
     except Exception as e:
         raise FileIOException(
             __("error", "controller.file.driver.local.init", str(e)))
     return True
Пример #4
0
 def delete_ref(self, commit_id):
     self.ensure_code_refs_dir()
     code_ref_path = os.path.join(self.filepath, ".git/refs/datmo/",
                                  commit_id)
     if not self.exists_ref(commit_id):
         raise FileIOException(
             __("error", "controller.code.driver.git.delete_ref"))
     os.remove(code_ref_path)
     return True
Пример #5
0
 def ensure_code_refs_dir(self):
     dir = ".git/refs/datmo"
     try:
         if not os.path.isdir(os.path.join(self.filepath, dir)):
             os.makedirs(os.path.join(self.filepath, dir))
     except Exception as e:
         raise FileIOException(
             __("error", "controller.code.driver.git.ensure_code_refs_dir",
                str(e)))
     return True
Пример #6
0
 def init(self):
     try:
         subprocess.check_output(
             [self.execpath, "init",
              str(self.filepath)], cwd=self.filepath).strip()
     except Exception as e:
         raise GitExecutionException(
             __("error", "controller.code.driver.git.init", str(e)))
     try:
         code_refs_success = self.ensure_code_refs_dir()
     except Exception as e:
         raise FileIOException(
             __("error", "controller.code.driver.git.init.file", str(e)))
     try:
         datmo_files_ignored_success = self.ensure_datmo_files_ignored()
     except Exception as e:
         raise FileIOException(
             __("error", "controller.code.driver.git.init.file", str(e)))
     return code_refs_success and datmo_files_ignored_success
Пример #7
0
 def delete_code_refs_dir(self):
     dir = ".git/refs/datmo"
     dir_path = os.path.join(self.filepath, dir)
     try:
         if os.path.isdir(dir_path):
             shutil.rmtree(dir_path)
     except Exception as e:
         raise FileIOException(
             __("error", "controller.code.driver.git.delete_code_refs_dir",
                str(e)))
     return True
Пример #8
0
 def ensure_datmo_files_ignored(self):
     exclude_file = os.path.join(self.filepath, ".git/info/exclude")
     try:
         if not self.exists_datmo_files_ignored():
             with open(exclude_file, "a") as f:
                 f.write(to_unicode("\n.datmo/*\n"))
     except Exception as e:
         raise FileIOException(
             __("error", "controller.code.driver.git.ensure_code_refs_dir",
                str(e)))
     return True
Пример #9
0
 def exists_datmo_files_ignored(self):
     exclude_file = os.path.join(self.filepath, ".git/info/exclude")
     try:
         if ".datmo" not in open(exclude_file, "r").read():
             return False
         else:
             return True
     except Exception as e:
         raise FileIOException(
             __("error", "controller.code.driver.git.ensure_code_refs_dir",
                str(e)))
Пример #10
0
 def to_dict(self):
     output_dict = dict()
     # reading json file to stats
     if os.path.exists(self.filepath):
         with open(self.filepath) as data_file:
             meta_data_string = data_file.read()
         try:
             output_dict = json.loads(meta_data_string)
             output_dict = yaml.safe_load(json.dumps(output_dict))
         except Exception as err:
             raise FileIOException(err)
     return output_dict
Пример #11
0
 def init(self):
     try:
         # Ensure the Datmo file structure exists
         self.ensure_datmo_file_structure()
         # Ensure the collections directory exists
         self.ensure_collections_dir()
         # Ensure the empty collection exists
         if not os.path.isdir(
                 os.path.join(self.filepath, ".datmo", "collections",
                              "d41d8cd98f00b204e9800998ecf8427e")):
             self.create(os.path.join(".datmo", "collections",
                                      "d41d8cd98f00b204e9800998ecf8427e"),
                         directory=True)
     except Exception as e:
         raise FileIOException(
             __("error", "controller.file.driver.local.init", str(e)))
     return True