Skip to content

Commit bd8a768

Browse files
authored
refactor!: Remove tools.syncfs() (bit-team#1698)
Was used in shutdown() only. Shutodwn cause an unmount which itself cause synfs on OS level. No need for BIT to do it explicit. Behavior of BIT do not change. Additionally minor PEP8 improvements. Close bit-team#1685
1 parent 1905cd5 commit bd8a768

File tree

2 files changed

+44
-22
lines changed

2 files changed

+44
-22
lines changed

common/test/test_tools.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,6 @@ def test_filesystemMountInfo(self):
430430
self.assertIn('/', mounts)
431431
self.assertIn('original_uuid', mounts.get('/'))
432432

433-
def test_syncfs(self):
434-
self.assertTrue(tools.syncfs())
435-
436433
def test_isRoot(self):
437434
self.assertIsInstance(tools.isRoot(), bool)
438435

common/tools.py

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
# | Handling paths |
9090
# |-----------------|
9191

92+
9293
def sharePath():
9394
"""Get path where Back In Time is installed.
9495
@@ -111,6 +112,7 @@ def sharePath():
111112

112113
return '/usr/share'
113114

115+
114116
def backintimePath(*path):
115117
"""
116118
Get path inside 'backintime' install folder.
@@ -349,9 +351,11 @@ def registerBackintimePath(*path):
349351
would need this to actually import :py:mod:`tools`.
350352
"""
351353
path = backintimePath(*path)
352-
if not path in sys.path:
354+
355+
if path not in sys.path:
353356
sys.path.insert(0, path)
354357

358+
355359
def runningFromSource():
356360
"""
357361
Check if BackInTime is running from source (without installing).
@@ -361,14 +365,16 @@ def runningFromSource():
361365
"""
362366
return os.path.isfile(backintimePath('common', 'backintime'))
363367

368+
364369
def addSourceToPathEnviron():
365370
"""
366371
Add 'backintime/common' path to 'PATH' environ variable.
367372
"""
368373
source = backintimePath('common')
369374
path = os.getenv('PATH')
370375
if path and source not in path.split(':'):
371-
os.environ['PATH'] = '%s:%s' %(source, path)
376+
os.environ['PATH'] = '%s:%s' % (source, path)
377+
372378

373379
def get_git_repository_info(path=None, hash_length=None):
374380
"""Return the current branch and last commit hash.
@@ -456,6 +462,7 @@ def readFile(path, default=None):
456462

457463
return ret_val
458464

465+
459466
def readFileLines(path, default = None):
460467
"""
461468
Read the file in ``path`` or its '.gz' compressed variant and return its
@@ -484,6 +491,7 @@ def readFileLines(path, default = None):
484491

485492
return ret_val
486493

494+
487495
def checkCommand(cmd):
488496
"""
489497
Check if command ``cmd`` is a file in 'PATH' environ.
@@ -501,8 +509,10 @@ def checkCommand(cmd):
501509

502510
if os.path.isfile(cmd):
503511
return True
512+
504513
return not which(cmd) is None
505514

515+
506516
def which(cmd):
507517
"""
508518
Get the fullpath of executable command ``cmd``. Works like
@@ -518,14 +528,19 @@ def which(cmd):
518528
pathenv = os.getenv('PATH', '')
519529
path = pathenv.split(":")
520530
common = backintimePath('common')
531+
521532
if runningFromSource() and common not in path:
522533
path.insert(0, common)
534+
523535
for directory in path:
524536
fullpath = os.path.join(directory, cmd)
537+
525538
if os.path.isfile(fullpath) and os.access(fullpath, os.X_OK):
526539
return fullpath
540+
527541
return None
528542

543+
529544
def makeDirs(path):
530545
"""
531546
Create directories ``path`` recursive and return success.
@@ -542,15 +557,19 @@ def makeDirs(path):
542557

543558
if os.path.isdir(path):
544559
return True
560+
545561
else:
562+
546563
try:
547564
os.makedirs(path)
548565
except Exception as e:
549566
logger.error("Failed to make dirs '%s': %s"
550-
%(path, str(e)), traceDepth = 1)
567+
% (path, str(e)), traceDepth=1)
568+
551569
return os.path.isdir(path)
552570

553-
def mkdir(path, mode = 0o755, enforce_permissions = True):
571+
572+
def mkdir(path, mode=0o755, enforce_permissions=True):
554573
"""
555574
Create directory ``path``.
556575
@@ -567,14 +586,18 @@ def mkdir(path, mode = 0o755, enforce_permissions = True):
567586
os.chmod(path, mode)
568587
except:
569588
return False
589+
570590
return True
591+
571592
else:
572593
os.mkdir(path, mode)
594+
573595
if mode & 0o002 == 0o002:
574-
#make file world (other) writable was requested
575-
#debian and ubuntu won't set o+w with os.mkdir
576-
#this will fix it
596+
# make file world (other) writable was requested
597+
# debian and ubuntu won't set o+w with os.mkdir
598+
# this will fix it
577599
os.chmod(path, mode)
600+
578601
return os.path.isdir(path)
579602

580603

@@ -1105,6 +1128,7 @@ def checkCronPattern(s):
11051128
except ValueError:
11061129
return False
11071130

1131+
11081132
#TODO: check if this is still necessary
11091133
def checkHomeEncrypt():
11101134
"""
@@ -1131,6 +1155,7 @@ def checkHomeEncrypt():
11311155
return True
11321156
return False
11331157

1158+
11341159
def envLoad(f):
11351160
"""
11361161
Load environ variables from file ``f`` into current environ.
@@ -1150,6 +1175,7 @@ def envLoad(f):
11501175
os.environ[key] = value
11511176
del(env_file)
11521177

1178+
11531179
def envSave(f):
11541180
"""
11551181
Save environ variables to file that are needed by cron
@@ -1169,6 +1195,7 @@ def envSave(f):
11691195

11701196
env_file.save(f)
11711197

1198+
11721199
def keyringSupported():
11731200
"""
11741201
Checks if a keyring (supported by BiT) is available
@@ -1275,12 +1302,14 @@ def password(*args):
12751302
return keyring.get_password(*args)
12761303
return None
12771304

1305+
12781306
def setPassword(*args):
12791307

12801308
if is_keyring_available:
12811309
return keyring.set_password(*args)
12821310
return False
12831311

1312+
12841313
def mountpoint(path):
12851314
"""
12861315
Get the mountpoint of ``path``. If your HOME is on a separate partition
@@ -1318,6 +1347,7 @@ def repl(m):
13181347
return chr(int(m.group(1), 8))
13191348
return re.sub(r'\\(\d{3})', repl, s)
13201349

1350+
13211351
def mountArgs(path):
13221352
"""
13231353
Get all /etc/mtab args for the filesystem of ``path`` as a list.
@@ -1544,16 +1574,6 @@ def filesystemMountInfo():
15441574
if uuidFromDev(items[0]) != None}
15451575

15461576

1547-
def syncfs():
1548-
"""
1549-
Sync any data buffered in memory to disk.
1550-
1551-
Returns:
1552-
bool: ``True`` if successful
1553-
"""
1554-
if checkCommand('sync'):
1555-
return(Execute(['sync']).run() == 0)
1556-
15571577
def isRoot():
15581578
"""
15591579
Check if we are root.
@@ -1887,6 +1907,7 @@ def fdDup(old, new_fd, mode = 'w'):
18871907
except OSError as e:
18881908
logger.debug('Failed to redirect {}: {}'.format(old, str(e)))
18891909

1910+
18901911
class UniquenessSet:
18911912
"""
18921913
Check for uniqueness or equality of files.
@@ -2003,6 +2024,7 @@ def checkEqual(self, path):
20032024
else:
20042025
return self.reference == (st.st_size, int(st.st_mtime))
20052026

2027+
20062028
class Alarm(object):
20072029
"""
20082030
Establish a callback function that is called after a timeout.
@@ -2078,6 +2100,7 @@ def handler(self, signum, frame):
20782100
else:
20792101
self.callback()
20802102

2103+
20812104
class ShutDown(object):
20822105
"""
20832106
Shutdown the system after the current snapshot has finished.
@@ -2237,7 +2260,6 @@ def shutdown(self):
22372260
return(False)
22382261

22392262
if self.is_root:
2240-
syncfs()
22412263
self.started = True
22422264
proc = subprocess.Popen(['shutdown', '-h', 'now'])
22432265
proc.communicate()
@@ -2247,7 +2269,6 @@ def shutdown(self):
22472269
return(False)
22482270

22492271
else:
2250-
syncfs()
22512272
self.started = True
22522273

22532274
return(self.proxy(*self.args))
@@ -2343,6 +2364,7 @@ def clean(self):
23432364
return
23442365
self.iface.clean()
23452366

2367+
23462368
class PathHistory(object):
23472369
def __init__(self, path):
23482370
self.history = [path,]
@@ -2377,6 +2399,7 @@ def reset(self, path):
23772399
self.history = [path,]
23782400
self.index = 0
23792401

2402+
23802403
class OrderedSet(MutableSet):
23812404
"""
23822405
OrderedSet from Python recipe
@@ -2438,6 +2461,7 @@ def __eq__(self, other):
24382461
return len(self) == len(other) and list(self) == list(other)
24392462
return set(self) == set(other)
24402463

2464+
24412465
class Execute(object):
24422466
"""
24432467
Execute external commands and handle its output.
@@ -2643,6 +2667,7 @@ def kill(self, signum, frame):
26432667
logger.info('Kill process "%s"' %self.printable_cmd, self.parent, 2)
26442668
return self.currentProc.kill()
26452669

2670+
26462671
class Daemon:
26472672
"""
26482673
A generic daemon class.

0 commit comments

Comments
 (0)