O2-DQ User Interface 1.0.0
Loading...
Searching...
No Matches
pycacheRemover.py
Go to the documentation of this file.
1#!/usr/bin/env python
2# PYTHON_ARGCOMPLETE_OK
3# -*- coding: utf-8 -*-
4
5# Copyright 2019-2020 CERN and copyright holders of ALICE O2.
6# See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
7# All rights not expressly granted are reserved.
8#
9# This software is distributed under the terms of the GNU General Public
10# License v3 (GPL Version 3), copied verbatim in the file "COPYING".
11#
12# In applying this license CERN does not waive the privileges and immunities
13# granted to it by virtue of its status as an Intergovernmental Organization
14# or submit itself to any jurisdiction.
15
16# This scripts provides remove pycache files recursively
17
18import os
19import logging
20import sys
21
22
23class PycacheRemover(object):
24
25 """This class creates two python commands in order to remove pycache files recursively
26
27 Args:
28 object (str): Creates two python command for deleting pycache files
29 """
30
31 def __init__(self):
32
33 super(PycacheRemover, self).__init__()
34
35 commandOne = ("python3 -Bc " + '"' + "import pathlib;" + "[p.unlink() for p in pathlib.Path('.').rglob('*.py[co]')]" + '"')
36 commandTwo = ("python3 -Bc" + '"' + "import pathlib;" + "[p.rmdir() for p in pathlib.Path('.').rglob('__pycache__')]" + '"')
37
38 os.system(commandOne)
39 os.system(commandTwo)
40
41
43 """This function run two python command and it provides recursively deletes pycache files
44
45 Raises:
46 BaseException: If not path exists in OS
47 """
48
49 pycacheRemover = PycacheRemover()
50
51 try:
52 parentPath = os.getcwd()
53 if os.path.exists(parentPath):
54 logging.info("Inserting inside for pycache remove: %s", os.getcwd())
55 pycacheRemover.__init__()
56 logging.info("pycaches removed succesfully")
57
58 elif not os.path.exists(parentPath):
59 raise BaseException
60
61 # Caching the exception
62 except BaseException:
63 logging.exception("Something wrong with specified\
64 directory. Exception- %s", sys.exc_info(),)
65 sys.exit()
def runPycacheRemover()