Exemplo n.º 1
0
    def check_password(self, password):
        """
        Check if hashed password matches with actual password
        """

        LOGGER.info("Check if the password is correct")
        return check_password_hash(self.password_hash, password)
Exemplo n.º 2
0
 def clean_raw(self, overwrite=False):
     """Basic cleaning and reducing of data"""
     LOGGER.info(f"Cleaning NAIS file for month {self.month}...")
     if not exists(self.csv_cleaned) or overwrite:
         self.df_raw.clean_raw()
     else:
         LOGGER.info(f"NAIS file for month {self.month} has been cleaned.")
Exemplo n.º 3
0
def fire_rules(execution: Execution):
    if has_unstaged_files():
        raise UnstagedFilesException()

    if is_ahead():
        raise BranchAheadException()

    actions = []

    for action_execution in execution.action.get("execution"):
        do = action_execution.get("do")
        action_from_template = do.get("action")

        LOGGER.info(f"Validando método {action_from_template}...")

        action_class = eval(capitalize_first_letter(action_from_template))

        action = action_class(
            ActionExecution(execution.variables, do.get("parameters"),
                            execution.arguments))

        if not action.is_implemented:
            LOGGER.warn("Método não implementado, favor revisar seu template!")
        else:
            actions.append(action)

    # TODO implementar informativo quando a ação não puder ser executada por
    #  determinado motivo

    for action in actions:
        action.execute()
Exemplo n.º 4
0
 def __init__(self, first_name, last_name, email, district, city):
     LOGGER.info("Create a volunteer instance")
     self.first_name = first_name
     self.last_name = last_name
     self.email = email
     self.district = district
     self.city = city
Exemplo n.º 5
0
    def _parse_action_parameters(self):
        LOGGER.info("Realizando parse da ação no template...")

        self.action_execution.parameters = {
            k: self._change_value(v)
            for k, v in self.action_execution.parameters.items()
        }
Exemplo n.º 6
0
 def process(self, overwrite=False):
     """Basic cleaning and reducing of data"""
     LOGGER.info(f"Processing NAIS file for month {self.month}...")
     if not exists(self.csv_processed) or overwrite:
         self.df_clean.preprocess()
     else:
         LOGGER.info(
             f"NAIS file for month {self.month} has been preprocessed.")
Exemplo n.º 7
0
def pull(branch):
    global GIT_REPO

    LOGGER.info(f"Atualizando source {branch}...")

    try:
        GIT_REPO.git.pull()
    except GitCommandError as e:
        raise GitException(e.stdout)
def get_smtp_no_tls(config):
    no_tls = False
    config_path = ["app", "smtp", "no_tls"]
    if not traverse_config_path(config=config, config_path=config_path):
        LOGGER.warning(
            f"Warning: no_tls is not found in {config_path_to_string(config_path)}"
        )
    else:
        no_tls = get_config_value(config=config, config_path=config_path)
    return no_tls
def get_smtp_port(config):
    port = None
    config_path = ["app", "smtp", "port"]
    if not traverse_config_path(config=config, config_path=config_path):
        LOGGER.warning(
            f"Warning: port is not found in {config_path_to_string(config_path)}"
        )
    else:
        port = get_config_value(config=config, config_path=config_path)
    return port
Exemplo n.º 10
0
 def __init__(self, reference_id, action_name, organizing_institution,
              address, district, city, description):
     LOGGER.info("Create an action instance")
     self.reference_id = reference_id
     self.action_name = action_name
     self.organizing_institution = organizing_institution
     self.address = address
     self.district = district
     self.city = city
     self.description = description
Exemplo n.º 11
0
def wanted_file(filters, file_path):
    if not file_path:
        return False
    if not filters or len(filters) == 0:
        return True
    for file_extension in filters:
        if re.search(f"{file_extension}$", file_path, re.IGNORECASE):
            return True
    LOGGER.debug(f"Skipping the unwanted file {file_path}")
    return False
Exemplo n.º 12
0
def process_folder(item, destination_path, filters, root):
    if not (item and destination_path and root):
        return None
    new_directory = os.path.join(destination_path, item.name)
    if not wanted_folder(filters=filters, folder_path=new_directory,
                         root=root):
        LOGGER.debug(f"Skipping the unwanted folder {new_directory} ...")
        return None
    os.makedirs(new_directory, exist_ok=True)
    return new_directory
Exemplo n.º 13
0
def delete(pattern):
    LOGGER.info(f"Excluindo source(es) {pattern}...")

    branches = [
        branch.replace(" ", "") for branch in git.branch().splitlines()
    ]

    branches = list(filter(lambda x: x.startswith(pattern), branches))

    [git.execute(["git", "source", "-D", branch]) for branch in branches]
Exemplo n.º 14
0
    def _process_str(self, value: str, execute: bool = True) -> str:
        LOGGER.debug(f"Processando parse de string {value}...")

        if _ismultiplechoice(value):
            return self._process_multiple_choice(value)
        elif _ismethod(value):
            return self._process_method(value, execute)
        elif _isvariable(value):
            return self._process_variable(value)

        return value
Exemplo n.º 15
0
def is_ahead():
    branch = retrieve_current_branch()

    try:
        commits_ahead = GIT_REPO.iter_commits(branch + ".." + branch)
        number_of_commits = sum(1 for _ in commits_ahead)

        return number_of_commits > 0
    except GitCommandError:
        LOGGER.info(f"Your current source ({branch}) doesn't exists on remote "
                    f"repo. Please use git push source {branch}.")
Exemplo n.º 16
0
def get_photos_sync_interval(config):
    sync_interval = DEFAULT_SYNC_INTERVAL_SEC
    config_path = ["photos", "sync_interval"]
    if not traverse_config_path(config=config, config_path=config_path):
        LOGGER.warning(
            f"sync_interval is not found in {config_path_to_string(config_path=config_path)}."
            + f" Using default sync_interval: {sync_interval} seconds ...")
    else:
        sync_interval = get_config_value(config=config,
                                         config_path=config_path)
        LOGGER.info(f"Syncing photos every {sync_interval} seconds.")
    return sync_interval
Exemplo n.º 17
0
def file_exists(item, local_file):
    if item and local_file and os.path.isfile(local_file):
        local_file_modified_time = int(os.path.getmtime(local_file))
        remote_file_modified_time = int(item.date_modified.timestamp())
        local_file_size = os.path.getsize(local_file)
        remote_file_size = item.size
        if (local_file_modified_time == remote_file_modified_time
                and local_file_size == remote_file_size):
            LOGGER.debug(
                f"No changes detected. Skipping the file {local_file} ...")
            return True
    return False
Exemplo n.º 18
0
def get_retry_login_interval(config):
    retry_login_interval = DEFAULT_RETRY_LOGIN_INTERVAL_SEC
    config_path = ["app", "credentials", "retry_login_interval"]
    if not traverse_config_path(config=config, config_path=config_path):
        LOGGER.warning(
            f"retry_login_interval not found in {config_path_to_string(config_path=config_path)}."
            + f" Using default {retry_login_interval} seconds ...")
    else:
        retry_login_interval = get_config_value(config=config,
                                                config_path=config_path)
        LOGGER.info(f"Retrying login every {retry_login_interval} seconds.")
    return retry_login_interval
Exemplo n.º 19
0
def get_drive_remove_obsolete(config):
    drive_remove_obsolete = False
    config_path = ["drive", "remove_obsolete"]
    if not traverse_config_path(config=config, config_path=config_path):
        LOGGER.warning(
            f"Warning: remove_obsolete is not found in {config_path_to_string(config_path)}."
            + " Not removing the obsolete files and folders.")
    else:
        drive_remove_obsolete = get_config_value(config=config,
                                                 config_path=config_path)
        LOGGER.debug(
            f"{'R' if drive_remove_obsolete else 'Not R'}emoving obsolete files and folders ..."
        )
    return drive_remove_obsolete
Exemplo n.º 20
0
 def __init__(self,
              first_name,
              last_name,
              email,
              username,
              password,
              is_admin=False):
     LOGGER.info("Create an user instance")
     self.first_name = first_name
     self.last_name = last_name
     self.email = email
     self.username = username
     self.password_hash = generate_password_hash(password)
     self.is_admin = is_admin
Exemplo n.º 21
0
def get_photos_remove_obsolete(config):
    photos_remove_obsolete = False
    config_path = ["photos", "remove_obsolete"]
    if not traverse_config_path(config=config, config_path=config_path):
        LOGGER.warning(
            f"Warning: remove_obsolete is not found in {config_path_to_string(config_path)}."
            + " Not removing the obsolete photos.")
    else:
        photos_remove_obsolete = get_config_value(config=config,
                                                  config_path=config_path)
        LOGGER.debug(
            f"{'R' if photos_remove_obsolete else 'Not R'}emoving obsolete photos ..."
        )
    return photos_remove_obsolete
Exemplo n.º 22
0
def prepare_root_destination(config):
    LOGGER.debug("Checking root destination ...")
    root_destination = DEFAULT_ROOT_DESTINATION
    config_path = ["app", "root"]
    if not traverse_config_path(config=config, config_path=config_path):
        LOGGER.warning(
            f"Warning: root destination is missing in {config_path_to_string(config_path)}."
            + f" Using default root destination: {root_destination}", )
    else:
        root_destination = get_config_value(config=config,
                                            config_path=config_path)
    root_destination_path = os.path.abspath(root_destination)
    os.makedirs(root_destination_path, exist_ok=True)
    return root_destination_path
Exemplo n.º 23
0
def checkout_new_branch(source: str, branch: str):
    global GIT_REPO

    checkout(source)
    pull(source)

    LOGGER.info(f"Criando source {branch} com base na source {source}...")

    try:
        _validate_existence(branch)

        GIT_REPO.git.checkout(source, b=branch)
    except GitCommandError as e:
        raise GitException(e.stdout)
Exemplo n.º 24
0
def get_username(config):
    username = None
    config_path = ["app", "credentials", "username"]
    if not traverse_config_path(config=config, config_path=config_path):
        LOGGER.error(
            f"username is missing in {config_path_to_string(config_path)}. Please set the username."
        )
    else:
        username = get_config_value(config=config, config_path=config_path)
        username = username.strip()
        if len(username) == 0:
            username = None
            LOGGER.error(
                f"username is empty in {config_path_to_string(config_path)}.")
    return username
Exemplo n.º 25
0
def remove_obsolete(destination_path, files):
    removed_paths = set()
    if not (destination_path and files is not None):
        return removed_paths
    for path in Path(destination_path).rglob("*"):
        local_file = str(path.absolute())
        if local_file not in files:
            LOGGER.info(f"Removing {local_file} ...")
            if path.is_file():
                path.unlink(missing_ok=True)
                removed_paths.add(local_file)
            elif path.is_dir():
                rmtree(local_file)
                removed_paths.add(local_file)
    return removed_paths
Exemplo n.º 26
0
def download_file(item, local_file):
    if not (item and local_file):
        return False
    LOGGER.info(f"Downloading {local_file} ...")
    try:
        with item.open(stream=True) as response:
            with open(local_file, "wb") as file_out:
                copyfileobj(response.raw, file_out)
        item_modified_time = time.mktime(item.date_modified.timetuple())
        os.utime(local_file, (item_modified_time, item_modified_time))
    except (exceptions.ICloudPyAPIResponseException, FileNotFoundError,
            Exception) as e:
        LOGGER.error(f"Failed to download {local_file}: {str(e)}")
        return False
    return True
Exemplo n.º 27
0
def prepare_drive_destination(config):
    LOGGER.debug("Checking drive destination ...")
    config_path = ["drive", "destination"]
    drive_destination = DEFAULT_DRIVE_DESTINATION
    if not traverse_config_path(config=config, config_path=config_path):
        LOGGER.warning(
            f"Warning: destination is missing in {config_path_to_string(config_path)}."
            + f" Using default drive destination: {drive_destination}.")
    else:
        drive_destination = get_config_value(config=config,
                                             config_path=config_path)
    drive_destination_path = os.path.abspath(
        os.path.join(prepare_root_destination(config=config),
                     drive_destination))
    os.makedirs(drive_destination_path, exist_ok=True)
    return drive_destination_path
Exemplo n.º 28
0
def prepare_photos_destination(config):
    LOGGER.debug("Checking photos destination ...")
    config_path = ["photos", "destination"]
    photos_destination = DEFAULT_PHOTOS_DESTINATION
    if not traverse_config_path(config=config, config_path=config_path):
        LOGGER.warning(
            f"Warning: destination is missing in {photos_destination}." +
            f" Using default photos destination: {config_path_to_string(config_path)}"
        )
    else:
        photos_destination = get_config_value(config=config,
                                              config_path=config_path)
    photos_destination_path = os.path.abspath(
        os.path.join(prepare_root_destination(config=config),
                     photos_destination))
    os.makedirs(photos_destination_path, exist_ok=True)
    return photos_destination_path
Exemplo n.º 29
0
def merge(source: str, target: str, allow_merge_again: bool):
    global GIT_REPO

    if allow_merge_again or not _already_merged(target, source):
        checkout(target)
        pull(target)

        LOGGER.info(
            f"Realizando merge da source {source} com a source {target}...")
        try:
            GIT_REPO.git.merge(source, "--no-ff")
        except GitCommandError:
            raise GitException("O merge gerou conflitos, você precisa "
                               "resolvê-los antes de commitar!")
    else:
        LOGGER.warn(f"O merge da source {source} com a source {target} já "
                    f"foi realizado!")
Exemplo n.º 30
0
class SolveQuizForm(FlaskForm):
    """
    Form that show a question form to solve by the user
    """

    LOGGER.info("Generate the question form for the quiz")
    question = RadioField(choices=[], validators=[InputRequired()])
    times_up = HiddenField("times_up")
    submit = SubmitField("Next")