def myLocalLogTestFunc(): """ example of logging from a function """ logger = Logging.getLogger() logger.info("Test of Message") logger2 = Logging.getLogger("TestLogger") logger2.info("Test2 of Message") logger3 = Logging.getLogger(__name__) logger3.info("Test3 of Message")
def mainMethod(args): """ @brief The "main" method. @details This method is the entry point to the program. In this sense, it is similar to a main (and it is why it is called mainMethod()). """ logger = log.getLogger('sextractor') logger.info('#') logger.info('# Entering sextractor mainMethod()') logger.info('#') if args.zeropoint == "PER_S": zeropoints = image.get_zeropoints(args.image,apply_exptime=True,zerokey=args.zerokey) elif args.zeropoint == "INTEGRATED": zeropoints = image.get_zeropoints(args.image,apply_exptime=False,zerokey=args.zerokey) if args.outputcat == None : args.outputcat=utils.rm_extension(args.image)+".cat" image.sex(args.image,outputcat=args.outputcat) catalog.apply_zeropoints(args.outputcat,zeropoints) # !! Getting the option from the example option in defineSpecificProgramOption # !! e.g string_option = args.string_value logger.info('#') logger.info('# Exiting sextractor mainMethod()') logger.info('#')
class ClassExample(object): """ This is an example of the most basic Python class """ logger = log.getLogger('ClassExample') def __init__(self, my_list): """ Constructor """ self._m_i = 5 self._m_list = my_list def sumListValues(self): """ Method summing the elements of the list """ my_sum = 0 for element in self._m_list: my_sum += element return my_sum @staticmethod def product(first, second): """ This is an example static method :param first: The first number :param second: The second number :return: The product of the two numbers """ return first * second
def mainMethod(args): """ @brief The "main" method. @details This method is the entry point to the program. In this sense, it is similar to a main (and it is why it is called mainMethod()). The code below contains the calls to the different classes created for the first developer's workshop See the ElementsProgram documentation for more details. """ logger = log.getLogger('SomeOtherScript') logger.info('Entering SomeOtherScript mainMethod()') # # Log some of the arguments # int_from_configuration = args.int_option if not int_from_configuration: int_from_configuration = 9 logger.info('Example int : %d', int_from_configuration) ThatFunction() logger.info('Exiting SomeOtherScript mainMethod()') return 0
def mainMethod(args): """ @brief The "main" method. @details This method is the entry point to the program. In this sense, it is similar to a main (and it is why it is called mainMethod()). """ logger = log.getLogger('makeregionfile') logger.info('#') logger.info('# Entering makeregionfile mainMethod()') logger.info('#') # !! Getting the option from the example option in defineSpecificProgramOption # !! e.g string_option = args.string_value # cat = catalog.read(args.catalog,format=args.format) regionfile = utils.rm_extension(args.catalog)+'.reg' if args.subtag is None : args.subtag = '' catalog.toRegionFile(cat, regionfile, symbol = args.symbol, subtag=args.subtag, wcs=args.wcs) # logger.info('#') logger.info('# Exiting makeregionfile mainMethod()') logger.info('#')
def _destruct(self): """Internal function to remove the resource""" if self._name: if self._keep_var in os.environ: log = Logging.getLogger(None) log.info("%s set: I do not remove the '%s' temporary path", self._keep_var, self._name) else: self._delResource() self._name = None
def mainMethod(args): """ Main """ exit_code = Exit.Code["OK"] logger = log.getLogger('CreateElementsProject') logger.info('#') logger.info( '# Logging from the mainMethod() of the CreateElementsProject script') logger.info('#') proj_name = args.project_name proj_version = args.project_version dependant_projects = args.dependency destination_path = Project.setPath() dependency = args.dependency no_version_directory = args.no_version_directory standalone = args.standalone force_erase = args.erase answer_yes = args.yes logger.info('# Installation directory : %s', destination_path) try: # Set the project directory project_dir = Project.getProjectDirectory(no_version_directory, destination_path, proj_name, proj_version) Project.makeChecks(proj_name, proj_version, dependency, dependant_projects) Project.checkProjectExist(project_dir, no_version_directory, force_erase, answer_yes) # Create the project Project.createProject(project_dir, proj_name, proj_version, dependant_projects, standalone) # Print all files created ProjectCommonRoutines.printCreationList() logger.info('# <%s> project successfully created.', project_dir) except Exception as msg: if str(msg): logger.error(msg) logger.error('# Script aborted.') exit_code = Exit.Code["NOT_OK"] else: logger.info('# Script over.') return exit_code
def __delitem__(self, key): """ Unset an environment variable. Needed to provide the same interface as os.environ. """ key = self._fix_key(key) if key not in self.env: raise KeyError(key) self.old_values[key] = self.env[key] del self.env[key] log = Logging.getLogger(None) log.info("removed %s from environment", key)
def mainMethod(args): #pylint: disable=unused-argument """ The "main" method. This method is the entry point to the program. In this sense, it is similar to a main (and it is why it is called mainMethod()). The code below contains the calls to the different classes created for the first developer's workshop. See the ElementsProgram documentation for more details. """ logger = Logging.getLogger('TestProgramExample') logger.info('Entering TestProgramExample mainMethod()') logger.info('Exiting TestProgramExample mainMethod()') return Exit.Code["OK"]
def __init__(self, app_module, parent_project_version=None, parent_project_name=None, parent_project_vcs_version=None, elements_module_name=None, elements_module_version=None, search_dirs=None, original_path="", elements_loglevel=logging.DEBUG): self._app_module = importlib.import_module(app_module) self._logger = log.getLogger('ElementsProgram') self._elements_loglevel = elements_loglevel self._parent_project_version = parent_project_version self._parent_project_name = parent_project_name self._parent_project_vcs_version = parent_project_vcs_version self._elements_module_name = elements_module_name self._elements_module_version = elements_module_version self._search_dirs = search_dirs self._program_path = os.path.dirname(original_path) self._program_name = os.path.basename(original_path) self._env = Environment()
def mainMethod(args): """ The "main" method. This method is the entry point to the program. In this sense, it is similar to a main (and it is why it is called mainMethod()). The code below contains the calls to the different classes created for the first developer's workshop See the ElementsProgram documentation for more details. """ logger = Logging.getLogger('ProgramExample') logger.info('Entering ProgramExample mainMethod()') # # function with log messages # myLocalLogTestFunc() # # Log some of the arguments # string_from_configuration = args.string_option logger.info('Example string : %s', string_from_configuration) second_element = args.int_list_option[1] logger.info('Second elements from the list : %s', str(second_element)) logger.info("the int_option value %d", args.int_option) logger.info("the threshold value %.1f", args.threshold) # # Calling a static method # result = ClassExample.product(3, 4) logger.info('Static method result : %s', str(result)) # # Calling the constructor and a method member # example_object = ClassExample(args.int_list_option) logger.info('Sum of the list elements : %s', str(example_object.sumListValues())) logger.info('Exiting ProgramExample mainMethod()') return Exit.Code["OK"]
def mainMethod(args): """ @brief The "main" method. @details This method is the entry point to the program. In this sense, it is similar to a main (and it is why it is called mainMethod()). """ logger = log.getLogger('mergecatalogs') logger.info('#') logger.info('# Entering mergecatalogs mainMethod()') logger.info('#') # !! Getting the option from the example option in defineSpecificProgramOption # !! e.g string_option = args.string_value catalogs = [] for i,cat in enumerate(args.catalogs) : if len(args.format) > 1: ft = args.format[i] catalogs.append(catalog.read(cat,format=ft)) if len(args.catalogs) == 2: mcats=[utils.rm_extension(c)+'_matchtag.cat' for c in args.catalogs] mergedcat = catalog.mergecats(catalogs,delta=args.tol,filters=args.filters,mcats=mcats) #with open(args.outputcat, 'w') as f : # fits.write(mergedcat, f) catalog.writefits(mergedcat,args.outputcat) logger.info('# Percentage of cat 1 matched : {} %'.format(100*(len(mergedcat)/len(catalogs[0])))) logger.info('# Percentage of cat 2 matched : {} %'.format(100*(len(mergedcat)/len(catalogs[1])))) logger.info('# Size ratio cat 2 / cat 1 : {} %'.format(100*(len(catalogs[1])/len(catalogs[0])))) logger.info('#') logger.info('# Exiting mergecatalogs mainMethod()') logger.info('#')
def mainMethod(args): """ @brief The "main" method. @details This method is the entry point to the program. In this sense, it is similar to a main (and it is why it is called mainMethod()). """ logger = log.getLogger('truewcs') logger.info('#') logger.info('# Entering truewcs mainMethod()') logger.info('#') instrument = image.read_instrument(args.instrument) for imfile in args.images : im=fits.open(imfile) image.updatewcs(im,instrument) im.writeto('truewcs_'+imfile) logger.info('#') logger.info('# Exiting truewcs mainMethod()') logger.info('#')
def mainMethod(args): """ @brief The "main" method. @details This method is the entry point to the program. In this sense, it is similar to a main (and it is why it is called mainMethod()). """ logger = log.getLogger('generate_weight_map') logger.info('#') logger.info('# Entering generate_weight_map mainMethod()') logger.info('#') # !! Getting the option from the example option in defineSpecificProgramOption # !! e.g string_option = args.string_value instrument=image.read_instrument(args.instrument) wmap=image.generate_weight_map(instrument) wmap.writeto(args.outfile,overwrite=True) logger.info('#') logger.info('# Exiting generate_weight_map mainMethod()') logger.info('#')
def mainMethod(args): """ @brief The "main" method. @details This method is the entry point to the program. In this sense, it is similar to a main (and it is why it is called mainMethod()). """ logger = log.getLogger('GetElementsFiles') exit_code = Exit.Code["OK"] stem = args.file_stem file_type = args.type if stem.find(os.path.sep) != -1 and (not Path.HAS_SUBLEVELS[file_type]): logger.error("The search stem cannot contain \"%s\" for the %s type", os.path.sep, file_type) exit_code = Exit.Code["NOT_OK"] locations = Path.getLocations(file_type, exist_only=True, with_defaults=args.with_defaults) if stem: found_list = Path.getAllPathFromLocations(stem, locations) else: logger.info("No stem provided. Listing all files") found_list = [] for l in locations: for root, _, files in os.walk(l): for f in files: found_list.append(os.path.join(root, f)) found_list = selfFilter(found_list, args.self) for f in found_list: print(f) return exit_code
def mainMethod(args): """ The "main" method. This method is the entry point to the program. In this sense, it is similar to a main (and it is why it is called mainMethod()). The code below contains the calls to the different classes created for the first developer's workshop. See the ElementsProgram documentation for more details. """ logger = log.getLogger('SwigProgramExample') logger.info('Entering SwigProgramExample mainMethod()') # # Log some of the arguments # int_from_configuration = args.int_option if not int_from_configuration: int_from_configuration = 9 logger.info('Example int : %d', int_from_configuration) func_result = functionExample(int_from_configuration) logger.info('functionExample(%d) : %d', int_from_configuration, func_result) logger.info('Exiting SwigProgramExample mainMethod()') return Exit.Code["OK"]
import argparse import os from ElementsKernel import ProjectCommonRoutines from ElementsKernel import ParseCmakeLists from ElementsKernel import Logging from ElementsKernel import Exit try: from builtins import input except ImportError: from __builtin__ import input CMAKE_LISTS_FILE = 'CMakeLists.txt' logger = Logging.getLogger('RemoveCppClass') ################################################################################ def getAllFiles(class_name, module_directory, module_name): """ Get all files related to a class """ delete_file_list = [] file_name_h = os.path.join(module_directory, module_name, class_name) + '.h' if os.path.exists(file_name_h): delete_file_list.append(file_name_h) file_name_cpp = os.path.join(module_directory, 'src', 'lib', class_name) + '.cpp'
from argparse import RawTextHelpFormatter try: from builtins import input except ImportError: from __builtin__ import input from ElementsKernel import ProjectCommonRoutines from ElementsKernel import ParseCmakeLists from ElementsKernel import Logging from ElementsKernel import Exit CMAKE_LISTS_FILE = 'CMakeLists.txt' logger = Logging.getLogger('RemovePythonProgram') ################################################################################ def getAllFiles(program_name, module_directory, module_name): """ Get all files related to a python program """ delete_file_list = [] file_name_conf = os.path.join(module_directory, 'conf', module_name, program_name) + '.conf' if os.path.exists(file_name_conf): delete_file_list.append(file_name_conf) file_name_cpp = os.path.join(module_directory, 'python', module_name, program_name) + '.py'
import os import argparse import json import ElementsKernel.Logging as log from ElementsKernel import Exit # pyling: disable=bare-except try: from urllib2 import urlopen # @UnusedImport @UnresolvedImport from urllib2 import URLError # @UnusedImport @UnresolvedImport except: # pylint: disable=bare-except from urllib.request import urlopen # @ImportRedefinition from urllib.error import URLError logger = log.getLogger('NameCheck') TYPES = ["cmake", "library", "executable"] DEFAULT_TYPE = "cmake" _localUrlOpen = urlopen def getInfo(name, db_url, entity_type=DEFAULT_TYPE): """ Get the informations about a given entity of a specific type """ full_url = db_url + "/NameCheck/exists?name=%s&type=%s" % (name, entity_type) logger.debug("The url for the name request: %s", full_url) info = json.loads(_localUrlOpen(full_url).read().decode("utf-8")) for u in ["url", "private_url"]: if u in info and info[u]:
:date: 01/07/15 """ import argparse import os import time from ElementsKernel import Auxiliary from ElementsKernel import ProjectCommonRoutines from ElementsKernel import ParseCmakeListsMacros from ElementsKernel import Logging from ElementsKernel import Exit logger = Logging.getLogger('AddCppProgram') # Define constants CMAKE_LISTS_FILE = 'CMakeLists.txt' PROGRAM_TEMPLATE_FILE = 'Program_template.cpp' PROGRAM_TEMPLATE_FILE_IN = 'Program_template.cpp.in' def createDirectories(module_dir): """ Create directories needed for a program """ standalone_directories = [os.path.join('src', 'program'), 'conf'] for d in standalone_directories: target_dir = os.path.join(module_dir, d)
:date: 03/08/17 """ import argparse import os import time import stat from ElementsKernel import Auxiliary from ElementsKernel import ProjectCommonRoutines from ElementsKernel import ParseCmakeLists from ElementsKernel import Logging from ElementsKernel import Exit logger = Logging.getLogger('AddScript') # Define constants CMAKE_LISTS_FILE = 'CMakeLists.txt' PROGRAM_TEMPLATE_FILE = 'Script_template' PROGRAM_TEMPLATE_FILE_IN = 'Script_template.in' ################################################################################ def createDirectories(module_dir): """ Create directories needed for a python program """ # Create the scripts directory scripts_path = os.path.join(module_dir, 'scripts')
""" import argparse import os import time from ElementsKernel import Auxiliary from ElementsKernel import ProjectCommonRoutines from ElementsKernel import ParseCmakeLists from ElementsKernel import ParseCmakeListsMacros from ElementsKernel import Logging from ElementsKernel import Exit logger = Logging.getLogger('AddPythonProgram') # Define constants CMAKE_LISTS_FILE = 'CMakeLists.txt' PROGRAM_TEMPLATE_FILE = 'PythonProgram_template.py' PROGRAM_TEMPLATE_FILE_IN = 'PythonProgram_template.py.in' ################################################################################ def createDirectories(module_dir, module_name): """ Create directories needed for a python program """ standalone_directories = [ os.path.join('python', module_name),
def mainMethod(args): """ @brief The "main" method. @details This method is the entry point to the program. In this sense, it is similar to a main (and it is why it is called mainMethod()). """ logger = log.getLogger('runwcsfit') logger.info('#') logger.info('# Entering runwcsfit mainMethod()') logger.info('#') wcsfit.IMCORE = args.imcore_path #if args.debug: # logger.setLevel(logging.DEBUG) image_name = args.image if wcsfit.check_wcslib() == ERROR: sys.exit(1) if wcsfit.check_exe_in_path() == ERROR: sys.exit(1) # Check number of extensions and merge quadrants into ccd image if necessary n_extensions = wcsfit.get_number_of_extensions(image_name) if n_extensions in (4, 144): # Quadrants wcsfit.merge_quadrants(image_name) image_name = image_name.replace('.fit', '_ccd.fit') elif n_extensions in (1, 36): # CCD pass else: logger.error( 'fits file does not contain correct number of extensions ({})'. format(n_extensions)) sys.exit(1) # Deal with the weight map if needed if args.weight.find('noconf') == -1: weight_name = args.weight n_extensions = wcsfit.get_number_of_extensions(image_name) if n_extensions in (4, 144): # Quadrants wcsfit.merge_quadrants(weight_name) weight_name = weight_name.replace('.fit', '_ccd.fit') wcsfit.weight_to_conf(image_name, weight_name) # Fit astrometry with wcsfit.CCDImage(image_name, mode=args.mode, save_backup=args.copy) as img: img.fit_astrometry(refcat=args.refcat, makecat=args.nocat, wcsconf=args.wcsconf, fitpv=args.fitpv) # Primt summary print_summary(image_name) logger.info('#') logger.info('# Exiting runwcsfit mainMethod()') logger.info('#')
import argparse import os from ElementsKernel import Exit from ElementsKernel import Auxiliary from ElementsKernel import ProjectCommonRoutines from ElementsKernel import ParseCmakeLists from ElementsKernel import ParseCmakeListsMacros from ElementsKernel import Logging try: from builtins import input except ImportError: from __builtin__ import input logger = Logging.getLogger('AddElementsModule') # Define constants CMAKE_LISTS_FILE = 'CMakeLists.txt' CMAKE_LISTS_FILE_IN = 'CMakeLists.txt.mod.in' AUX_MOD_RST_IN = 'doc_module.rst.in' target_locations = { CMAKE_LISTS_FILE_IN: "CMakeLists.txt", AUX_MOD_RST_IN: "doc/doc_module.rst" } ################################################################################ def checkCmakelistFileExist(project_directory):
:date: 01/07/15 """ import os import argparse import time from ElementsKernel import Auxiliary from ElementsKernel import ProjectCommonRoutines from ElementsKernel import ParseCmakeLists from ElementsKernel import Logging from ElementsKernel import Exit logger = Logging.getLogger('AddPythonModule') # Define constants CMAKE_LISTS_FILE = 'CMakeLists.txt' PYTEST_TEMPLATE_FILE_IN = 'PythonTest_template.py.in' PYMODULE_TEMPLATE_FILE_IN = 'PythonModule_template.py.in' ################################################################################ def createDirectories(module_dir, module_name): """ Create directories needed for a python module """ standalone_directories = [ os.path.join('python', module_name),
import os import re import ELEMENTS_VERSION # @UnresolvedImport import ElementsKernel.Logging as log from ElementsKernel import Auxiliary from ElementsKernel import ProjectCommonRoutines try: from builtins import input except ImportError: from __builtin__ import input logger = log.getLogger('CreateElementsProject') AUX_CMAKE_LIST_IN = "CMakeLists.txt.in" AUX_MAKE_FILE_IN = "Makefile.in" AUX_PROJ_RST_IN = "doc_project.rst.in" AUX_PROJ_MAINPAGE_IN = "mainpage.dox.in" AUX_GITIGNORE_IN = "gitignore_template.in" AUX_GITATTRIBUTES_IN = "gitattributes_template.in" AUX_EDITOR_CONFIG = "editorconfig" AUX_CLANG_FORMAT = "clang-format" target_locations = { AUX_CMAKE_LIST_IN: "CMakeLists.txt", AUX_MAKE_FILE_IN: "Makefile", AUX_PROJ_RST_IN: "doc/doc_project.rst", AUX_PROJ_MAINPAGE_IN: "doc/mainpage.dox", AUX_GITIGNORE_IN: ".gitignore",
import ElementsKernel.Auxiliary as aux try: from builtins import input except ImportError: from __builtin__ import input # Define a global list containing files created or modified # by the python scripts for the creation of a Elements project _filelist = [] # Define regex for name & version checking NAME_REGEX = r"^[A-Za-z0-9][A-Za-z0-9_-]*$" VERSION_REGEX = r"^(\d+\.\d+(\.\d+)?|HEAD)$" logger = log.getLogger('ProjectCommonRoutines') CMAKE_LISTS_FILE = 'CMakeLists.txt' ################################################################################ def addItemToCreationList(element): """ Add an element to the global list. """ _filelist.append(element) ################################################################################ def printCreationList(): """
""" @file python/Phot/photometry.py @date 03/16/16 @author user """ from __future__ import division import ElementsKernel.Logging as log logger = log.getLogger('image') import subprocess, os, sys from . import utils from astropy.io import fits from astropy.modeling import models, fitting from astropy.wcs import WCS from matplotlib.colors import LogNorm import numpy as np import numpy.ma as ma from string import Template from matplotlib import pylab as P import json from scipy.ndimage.measurements import center_of_mass def parse_section_list(sectionlist): section = [sys.maxint, 0, sys.maxint, None] for sectionstring in sectionlist : s = parse_section_string(sectionstring) section = [min(s[0], section[0]), max(s[1],section[1]), min(s[2],section[2]), max(s[3],section[3])] return section def parse_section_string(section): section=section[1:-1].replace(':',',').split(',')
# along with this library; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # import argparse import os from datetime import timedelta import ElementsKernel.Logging as logging import matplotlib.pyplot as plt import numpy as np from dateutil.parser import parse, parser as dateutil_parser from matplotlib.ticker import FuncFormatter from time import mktime logger = logging.getLogger(__name__) def _parse_sourcex_logs(path): """ Low level parsing of the logs :param path: SourceX logs :return: A dictionary with the log entries, with their timestamp, logger, level and message """ timestamp_parser = dateutil_parser() log = dict(timestamp=[], logger=[], level=[], message=[]) with open(path) as fd: for line in fd:
@file tests/python/smoke_test.py @date 12/16/15 @author user """ import py.test import os.path import glob import extSim.utils import extSim.extsim from astropy.io import fits import shutil from string import uppercase as amptags from fixtures.PyDataSyncFixture import * import ElementsKernel.Logging as logging log = logging.getLogger('image') data_dir = os.path.join(os.environ["PHOTROOT"],"tests", "data") def symlinks(datafiles,workspace): for dst,src in datafiles.items(): os.symlink(os.path.join(data_dir,src), os.path.join(workspace,dst)) def simulate(): datafiles={"catalog.txt":"myEXTrandomcat-sersics.txt", "target.json":"des_target.json", "instrument.json":"des_test_instrument.json", "flat.fits":"des_testflat.fits", "bias.fits":"des_testbias.fits"} with extSim.utils.mock_workspace('test_smoke_sersics_ws_',del_tmp=False) as workspace: symlinks(datafiles,workspace) args = extSim.extsim.parseOptions(['--workspace',workspace],defaultconfig='smoke_test.conf') extSim.extsim.mainMethod(args) return args
import argparse import os from ElementsKernel import ProjectCommonRoutines from ElementsKernel import ParseCmakeLists from ElementsKernel import Logging from ElementsKernel import Exit try: from builtins import input except ImportError: from __builtin__ import input CMAKE_LISTS_FILE = 'CMakeLists.txt' logger = Logging.getLogger('RemovePythonModule') ################################################################################ def getAllFiles(pymodule_name, module_directory, module_name): """ Get all files related to a python module """ delete_file_list = [] file_name_test = os.path.join(module_directory, 'tests', 'python', \ pymodule_name) + '_test.py' if os.path.exists(file_name_test): delete_file_list.append(file_name_test) file_name_py = os.path.join(module_directory, 'python', module_name, \ pymodule_name) + '.py'
import argparse import os from ElementsKernel import ProjectCommonRoutines from ElementsKernel import ParseCmakeLists from ElementsKernel import Logging from ElementsKernel import Exit try: from builtins import input except ImportError: from __builtin__ import input CMAKE_LISTS_FILE = 'CMakeLists.txt' logger = Logging.getLogger('RemoveCppProgram') ################################################################################ def getAllFiles(program_name, module_directory, module_name): """ Get all files related to a Cpp program """ delete_file_list = [] file_name_conf = os.path.join(module_directory, 'conf', module_name, program_name) + '.conf' if os.path.exists(file_name_conf): delete_file_list.append(file_name_conf) file_name_cpp = os.path.join(module_directory, 'src', 'program', program_name) + '.cpp'