MCPcopy
hub / github.com/deadc0de6/dotdrop / _update

Method _update

dotdrop/updater.py:94–156  ·  view source on GitHub ↗

update dotfile from file pointed by path

(self, path, dotfile)

Source from the content-addressed store, hash-verified

92 return self._update(path, dotfile)
93
94 def _update(self, path, dotfile):
95 """update dotfile from file pointed by path"""
96 ret = False
97 new_path = None
98 ignores = list(set(self.ignore + dotfile.upignore))
99 prefixes = [dotfile.dst, dotfile.src]
100 ignores = ignores_to_absolute(ignores, prefixes,
101 debug=self.debug)
102 self.log.dbg(f'ignore pattern(s) for {path}: {ignores}')
103
104 deployed_path = os.path.expanduser(path)
105 local_path = os.path.join(self.dotpath, dotfile.src)
106 local_path = os.path.expanduser(local_path)
107
108 if not os.path.exists(deployed_path):
109 msg = f'\"{deployed_path}\" does not exist'
110 self.log.err(msg)
111 return False
112
113 if not os.path.exists(local_path):
114 msg = f'\"{local_path}\" does not exist, import it first'
115 self.log.err(msg)
116 return False
117
118 ignore_missing_in_dotdrop = self.ignore_missing_in_dotdrop or \
119 dotfile.ignore_missing_in_dotdrop
120
121 if ignore_missing_in_dotdrop and not os.path.exists(local_path):
122 self.log.sub(f'\"{dotfile.key}\" ignored')
123 return True
124
125 # apply write transformation if any
126 new_path = self._apply_trans_update(deployed_path, dotfile)
127 if not new_path:
128 return False
129
130 # save current rights
131 deployed_mode = get_file_perm(deployed_path)
132 local_mode = get_file_perm(local_path)
133
134 # handle the pointed file
135 if os.path.isdir(new_path):
136 ret = self._handle_dir(new_path, local_path,
137 dotfile, ignores)
138 else:
139 ret = self._handle_file(new_path, local_path,
140 ignores)
141 if not ret:
142 return False
143
144 # mirror rights
145 if deployed_mode != local_mode:
146 msg = f'adopt mode {deployed_mode:o} for {dotfile.key}'
147 self.log.dbg(msg)
148 if self.conf.update_dotfile(dotfile.key, deployed_mode):
149 ret = True
150 self._mirror_file_perms(deployed_path, local_path)
151

Callers 2

update_pathMethod · 0.95
update_keyMethod · 0.95

Calls 11

_apply_trans_updateMethod · 0.95
_handle_dirMethod · 0.95
_handle_fileMethod · 0.95
_mirror_file_permsMethod · 0.95
ignores_to_absoluteFunction · 0.90
get_file_permFunction · 0.90
removepathFunction · 0.90
dbgMethod · 0.80
errMethod · 0.80
subMethod · 0.80
update_dotfileMethod · 0.45

Tested by

no test coverage detected