def test_removes_pyc_files(self): call_command('compile_pyc') pyc_glob = self._find_pyc(get_project_root()) self.assertTrue(len(pyc_glob) > 0) call_command('clean_pyc') pyc_glob = self._find_pyc(get_project_root()) self.assertEqual(len(pyc_glob), 0)
def test_removes_pyc_files(self): with self.settings(BASE_DIR=get_project_root()): call_command('compile_pyc') pyc_glob = self._find_pyc(get_project_root()) self.assertTrue(len(pyc_glob) > 0) with self.settings(BASE_DIR=get_project_root()): call_command('clean_pyc') pyc_glob = self._find_pyc(get_project_root()) self.assertEqual(len(pyc_glob), 0)
def test_compiles_pyc_files(self): with self.settings(BASE_DIR=get_project_root()): call_command('clean_pyc') pyc_glob = self._find_pyc(get_project_root()) self.assertEqual(len(pyc_glob), 0) with self.settings(BASE_DIR=get_project_root()): call_command('compile_pyc') pyc_glob = self._find_pyc(get_project_root()) self.assertTrue(len(pyc_glob) > 0) with self.settings(BASE_DIR=get_project_root()): call_command('clean_pyc')
def test_takes_path(self): out = six.StringIO() project_root = os.path.join(get_project_root(), 'tests', 'testapp') with self.settings(BASE_DIR=get_project_root()): call_command('clean_pyc', path=project_root) pyc_glob = self._find_pyc(project_root) self.assertEqual(len(pyc_glob), 0) with self.settings(BASE_DIR=get_project_root()): call_command('compile_pyc', verbosity=2, path=project_root, stdout=out) expected = ['Compiling %s...' % fn for fn in sorted(self._find_pyc(project_root, mask='*.py'))] output = out.getvalue().splitlines() self.assertEqual(expected, sorted(output)) with self.settings(BASE_DIR=get_project_root()): call_command('clean_pyc')
def handle_noargs(self, **options): project_root = options.get("path", None) if not project_root: project_root = getattr(settings, 'BASE_DIR', None) verbosity = int(options.get("verbosity")) if not project_root: warnings.warn("settings.BASE_DIR or specifying --path will become mandatory in 1.4.0", DeprecationWarning) project_root = get_project_root() if verbosity > 0: self.stdout.write("""No path specified and settings.py does not contain BASE_DIR. Assuming '%s' is the project root. Please add BASE_DIR to your settings.py future versions 1.4.0 and higher of Django-Extensions will require either BASE_DIR or specifying the --path option. Waiting for 30 seconds. Press ctrl-c to abort. """ % project_root) if getattr(settings, 'COMPILE_PYC_DEPRECATION_WAIT', True): try: time.sleep(30) except KeyboardInterrupt: self.stdout.write("Aborted\n") return for root, dirs, filenames in os.walk(project_root): for filename in fnmatch.filter(filenames, '*.py'): full_path = _j(root, filename) if verbosity > 1: self.stdout.write("Compiling %s...\n" % full_path) py_compile.compile(full_path)
def handle_noargs(self, **options): project_root = options.get("path", getattr(settings, 'BASE_DIR', None)) if not project_root: project_root = getattr(settings, 'BASE_DIR', None) verbosity = int(options.get("verbosity")) if not project_root: warnings.warn( "settings.BASE_DIR or specifying --path will become mandatory in 1.4.0", DeprecationWarning) project_root = get_project_root() if verbosity > 0: self.stdout.write( """No path specified and settings.py does not contain BASE_DIR. Assuming '%s' is the project root. Please add BASE_DIR to your settings.py future versions 1.4.0 and higher of Django-Extensions will require either BASE_DIR or specifying the --path option. Waiting for 30 seconds. Press ctrl-c to abort. """ % project_root) if getattr(settings, 'CLEAN_PYC_DEPRECATION_WAIT', True): try: time.sleep(30) except KeyboardInterrupt: self.stdout.write("Aborted\n") return exts = options.get("optimize", False) and "*.py[co]" or "*.pyc" for root, dirs, filenames in os.walk(project_root): for filename in fnmatch.filter(filenames, exts): full_path = _j(root, filename) if verbosity > 1: self.stdout.write("%s\n" % full_path) os.remove(full_path)
def test_assumes_project_root(self): out = six.StringIO() call_command('compile_pyc', stdout=out) expected = "Assuming '%s' is the project root." % get_project_root() output = out.getvalue() self.assertIn(expected, output) call_command('clean_pyc', stdout=out)
def test_assumes_project_root(self): out = six.StringIO() call_command('clean_pyc', stdout=out) expected = ('No path specified, assuming %s is the project root.' % get_project_root()) output = out.getvalue().splitlines()[0] self.assertEqual(expected, output)
def test_takes_path(self): out = six.StringIO() project_root = os.path.join(get_project_root(), 'tests', 'testapp') call_command('compile_pyc', path=project_root) pyc_glob = self._find_pyc(project_root) self.assertTrue(len(pyc_glob) > 0) call_command('clean_pyc', verbosity=2, path=project_root, stdout=out) output = out.getvalue().splitlines() self.assertEqual(sorted(pyc_glob), sorted(output))
def save_version(self): """Creates a version string and saves it to a text file""" from datetime import datetime self.VERSION = '%s-%s.%s-%s' % (settings.BUILD_APPNAME, settings.BUILD_VERSION[0], settings.BUILD_VERSION[1], datetime.now().strftime('%Y%m%d%H%M%S')) ver_file = open(os.path.join(get_project_root(), 'templates', 'VERSION.txt'), 'w') ver_file.write(self.VERSION) ver_file.close()
def handle_noargs(self, **options): project_root = get_project_root() verbose = options.get("verbose", False) for root, dirs, files in os.walk(project_root): for file in files: ext = os.path.splitext(file)[1] if ext==".py": full_path = _j(root, file) if verbose: print "%sc" % full_path py_compile.compile(full_path)
def handle_noargs(self, **options): project_root = get_project_root() exts = options.get("optimize", False) and [".pyc", ".pyo"] or [".pyc"] verbose = options.get("verbose", False) for root, dirs, files in os.walk(project_root): for file in files: ext = os.path.splitext(file)[1] if ext in exts: full_path = _j(root, file) if verbose: print full_path os.remove(full_path)
def handle_noargs(self, **options): project_root = options.get("path", None) if not project_root: project_root = get_project_root() verbose = int(options.get("verbosity", 1)) > 1 for root, dirs, files in os.walk(project_root): for file in files: ext = os.path.splitext(file)[1] if ext == ".py": full_path = _j(root, file) if verbose: print("%sc" % full_path) py_compile.compile(full_path)
def handle_noargs(self, **options): project_root = options.get('path', None) if not project_root: project_root = get_project_root() verbose = int(options.get('verbosity', 1)) > 1 for (root, dirs, files) in os.walk(project_root): for file in files: ext = os.path.splitext(file)[1] if ext == '.py': full_path = _j(root, file) if verbose: print '%sc' % full_path py_compile.compile(full_path)
def handle_noargs(self, **options): project_root = options.get("path", None) if not project_root: project_root = get_project_root() exts = options.get("optimize", False) and [".pyc", ".pyo"] or [".pyc"] verbose = int(options.get("verbosity", 1))>1 for root, dirs, files in os.walk(project_root): for file in files: ext = os.path.splitext(file)[1] if ext in exts: full_path = _j(root, file) if verbose: print full_path os.remove(full_path)
def handle_noargs(self, **options): project_root = options.get("path", None) verbosity = int(options.get("verbosity")) if not project_root: project_root = get_project_root() if verbosity > 0: self.stdout.write( "No path specified, assuming %s is the project root.\n" % project_root) for root, dirs, filenames in os.walk(project_root): for filename in fnmatch.filter(filenames, '*.py'): full_path = _j(root, filename) if verbosity > 1: self.stdout.write("Compiling %s...\n" % full_path) py_compile.compile(full_path)
def test_removes_pyo_files(self): out = six.StringIO() project_root = os.path.join(get_project_root(), 'tests', 'testapp') call_command('compile_pyc', path=project_root) pyc_glob = self._find_pyc(project_root) self.assertTrue(len(pyc_glob) > 0) # Create some fake .pyo files since we can't force them to be created. pyo_glob = [] for fn in pyc_glob: pyo = '%s.pyo' % os.path.splitext(fn)[0] shutil.copyfile(fn, pyo) pyo_glob.append(pyo) call_command('clean_pyc', verbosity=2, path=project_root, optimize=True, stdout=out) output = out.getvalue().splitlines() self.assertEqual(sorted(pyc_glob + pyo_glob), sorted(output))
def handle_noargs(self, **options): project_root = options.get('path', None) if not project_root: project_root = get_project_root() exts = options.get('optimize', False) and ['.pyc', '.pyo'] \ or ['.pyc'] verbose = int(options.get('verbosity', 1)) > 1 for (root, dirs, files) in os.walk(project_root): for file in files: ext = os.path.splitext(file)[1] if ext in exts: full_path = _j(root, file) if verbose: print full_path os.remove(full_path)
def handle_noargs(self, **options): project_root = options.get("path", None) verbosity = int(options.get("verbosity")) if not project_root: project_root = get_project_root() if verbosity > 0: self.stdout.write( "No path specified, assuming %s is the project root.\n" % project_root) exts = options.get("optimize", False) and "*.py[co]" or "*.pyc" for root, dirs, filenames in os.walk(project_root): for filename in fnmatch.filter(filenames, exts): full_path = _j(root, filename) if verbosity > 1: self.stdout.write("%s\n" % full_path) os.remove(full_path)
def handle_noargs(self, **options): project_root = options.get("path", None) if not project_root: project_root = get_project_root() exts = options.get("optimize", False) and [".pyc", ".pyo"] or [".pyc"] verbose = int(options.get("verbosity", 1)) if verbose > 1: print "Project Root: %s" % project_root for root, dirs, files in os.walk(project_root): for file in files: ext = os.path.splitext(file)[1] if ext in exts: full_path = _j(root, file) if verbose > 1: print full_path os.remove(full_path)
def handle_noargs(self, **options): from django.conf import settings if settings.BUILT: settings.LOG.info("Installation built by build process; skipping clean_pyc") return project_root = options.get("path", None) if not project_root: project_root = get_project_root() exts = options.get("optimize", False) and [".pyc", ".pyo"] or [".pyc"] verbose = int(options.get("verbosity", 1)) if verbose > 1: print "Project Root: %s" % project_root for root, dirs, files in os.walk(project_root): for file in files: ext = os.path.splitext(file)[1] if ext in exts: full_path = _j(root, file) if verbose > 1: print full_path os.remove(full_path)
def handle_noargs(self, **options): from django.conf import settings if settings.BUILT: settings.LOG.info( "Installation built by build process; skipping clean_pyc") return project_root = options.get("path", None) if not project_root: project_root = get_project_root() exts = options.get("optimize", False) and [".pyc", ".pyo"] or [".pyc"] verbose = int(options.get("verbosity", 1)) if verbose > 1: print "Project Root: %s" % project_root for root, dirs, files in os.walk(project_root): for file in files: ext = os.path.splitext(file)[1] if ext in exts: full_path = _j(root, file) if verbose > 1: print full_path os.remove(full_path)
def get_base_dir(): return get_project_root()