Skip to content

Commit

Permalink
Add .old dir support for source services
Browse files Browse the repository at this point in the history
Some services expect "old" service files (that is, files from a
previous service run) to be present in an ".old" dir. Hence, osc
should support that.
Instead of removing all files from a previous service run, move them
to the ".old" dir, run the services, and, finally, remove the ".old"
dir.
Unfortunately, the location of the ".old" dir is hardcoded in the
specific services. That is, we have to be careful if an ".old" dir
exists (in this case, we error out).

Based on [1].

[1] #846
  • Loading branch information
marcus-h committed Oct 1, 2020
1 parent 7b5d105 commit 89bb15d
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions osc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,16 +410,27 @@ def addRecompressTar(self, serviceinfo_node):
return r

def execute(self, dir, callmode = None, singleservice = None, verbose = None):
old_dir = os.path.join(dir, '.old')
if os.path.exists(old_dir) or os.path.islink(old_dir):
msg = '"%s" exists, please remove it' % old_dir
raise oscerr.OscIOError(None, msg)
try:
os.mkdir(old_dir)
return self._execute(dir, old_dir, callmode, singleservice,
verbose)
finally:
if os.path.exists(old_dir):
shutil.rmtree(old_dir)

def _execute(self, dir, old_dir, callmode=None, singleservice=None,
verbose=None):
import tempfile

# cleanup existing generated files
for filename in os.listdir(dir):
if filename.startswith('_service:') or filename.startswith('_service_'):
ent = os.path.join(dir, filename)
if os.path.isdir(ent):
shutil.rmtree(ent)
else:
os.unlink(ent)
os.rename(os.path.join(dir, filename),
os.path.join(old_dir, filename))

allservices = self.services or []
service_names = [s['name'] for s in allservices]
Expand Down

0 comments on commit 89bb15d

Please sign in to comment.