Пример #1
0
def count_testing(repository_endpoint):
    token = Token()
    token.repository_endpoint = repository_endpoint
    repo = token.get_repository()
    contents = repo.get_contents("")

    # Counter
    javascript = 0
    python = 0
    java = 0
    php = 0

    while contents:
        file_content = contents.pop(0)
        if file_content.type == 'dir':
            contents.extend(repo.get_contents(file_content.path))
        else:
            fileName = file_content.name
            file = File(fileName)
            if file.is_python() or file.is_java() or file.is_php() or file.is_javascript():
                decoded_content = file_content.decoded_content
                inside_content = decoded_content.decode('utf-8')

                if inside_content.find('org.junit.jupiter.api.Test') > -1 or inside_content.find(
                        'import unittest') > -1 or inside_content.find('assert') > -1:
                    if file.is_javascript():  # Javascript
                        javascript += 1
                    elif file.is_python():  # Python
                        python += 1
                    elif file.is_java():  # Java
                        java += 1
                    elif file.is_php():  # PHP
                        php += 1

    return generate_dates(javascript, java, python, php)
Пример #2
0
def count_comment(repository_endpoint):
    token = Token()
    token.repository_endpoint = repository_endpoint
    repo = token.get_repository()
    contents = repo.get_contents("")

    # Counter
    javascript = 0
    python = 0
    java = 0
    php = 0

    while contents:
        file_content = contents.pop(0)
        if file_content.type == 'dir':
            contents.extend(repo.get_contents(file_content.path))
        else:
            fileName = file_content.name
            file = File(fileName)
            if file.is_python() or file.is_java() or file.is_php() or file.is_javascript():
                decoded_content = file_content.decoded_content
                inside_content = decoded_content.decode('utf-8')
                length = len(re.findall(r'/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/', inside_content))

                if length > 0:
                    if file.is_javascript():  # Javascript
                        javascript += length
                    elif file.is_python():  # Python
                        python += length
                    elif file.is_java():  # Java
                        java += length
                    elif file.is_php():  # PHP
                        php += length

    return generate_dates(javascript, java, python, php)
Пример #3
0
    def generateTables(self, conn_destination):
        cur = self.getConnection().cursor()
        cur_dest = conn_destination.cursor()

        blnTableGenerate = False
        tables = self.getLinkedTables()
        for table in tables:

            strQuery = "SHOW TABLES LIKE '{}'".format(table)
            cur_dest.execute(strQuery)
            tableExist = cur_dest.fetchall()

            if not tableExist:
                blnTableGenerate = True
                cur.execute("SHOW CREATE TABLE {}".format(table))
                data = cur.fetchall()
                for table, script in data:
                    cur_dest.execute(script)
                    conn_destination.commit()
                file = File("logging.txt")
                file.log(
                    "[{}] SUCCESS! New table {} was created successfully! \n".
                    format(datetime.datetime.now(), table))
        if blnTableGenerate:
            print("Tables successfully generated!")
        else:
            print("No new tables to generate!")
        conn_destination.close()
Пример #4
0
 def send_file(self, file: File):
     filename = file.get_filename()
     LCFILE = file.get_file()
     RMFILE = f"{self.get_config().data['cloud']['root']}{self.get_config().data['cloud']['folder']}{filename}"
     #cSTR = f"curl -u {self.get_config()['cloud']['WDUSER']}:{self.get_config()['cloud']['WDPASS']} -T {LCFILE} {RMFILE}"
     #print(cSTR)
     return subprocess.call([
         "curl", "-u",
         f"{self.get_config().data['cloud']['user']}:{self.get_config().data['cloud']['pass']}",
         "-T", LCFILE, RMFILE
     ])
Пример #5
0
def new_file(pathname, script, course_id, tags, student_instance):
    """
    PRE:    - pathname est de type str
            - script est de type bool
            - course_id est soit de type int soit None
            - tags est soit de type list soit None
            - student_instance est une instance de la classe Student
    POST: cree une instance de File
    """
    persistent_data = cli.cli_misc.pickle_get(students_arg=True,
                                              files_arg=True,
                                              courses_arg=True,
                                              id_dict_arg=True)
    all_students = persistent_data[0]
    all_files = persistent_data[2]
    all_courses = persistent_data[3]
    id_dict = persistent_data[4]
    file_instance = File(student_instance.user_id, pathname, course_id,
                         id_dict["file"], script, tags)
    student_instance.add_file(id_dict["file"])
    id_dict["file"] += 1
    course_instance = None
    if course_id is not None:
        course_instance = all_courses["objects_dict"][course_id]
        course_instance.add_file(file_instance.file_id)
    all_files["name_id_dict"][pathname] = file_instance.file_id
    all_files["objects_dict"][file_instance.file_id] = file_instance
    all_students["objects_dict"][student_instance.user_id] = student_instance
    if course_instance is not None:
        all_courses["objects_dict"][
            course_instance.course_id] = course_instance
    cli.cli_misc.pickle_save(all_students=all_students,
                             all_files=all_files,
                             all_courses=all_courses,
                             id_dict=id_dict)
Пример #6
0
    def __init__(self,
                 config: str = 'config/config.xml',
                 output_dir='./report'):
        if not config:
            config = 'config/config.xml'

        if isinstance(config, str):
            config = Config(config)
        self.config = config

        if not output_dir:
            if 'output_dir' in config.data:
                output_dir = config.data['output_dir']
            else:
                output_dir = '../report'
        self.__output_dir = output_dir
        self.config_db = dict()
        self.__db = DB(typedb='postgres', **self.config_db)

        self.__file = File(f"{self.get_output_dir()}/file.csv", 'csv')
Пример #7
0
    def starting_count(self):
        for content in self.contents['files']:
            fileName = content.name
            file = File(fileName)
            if file.is_python() or file.is_java() or file.is_php(
            ) or file.is_javascript():
                decoded_content = content.decoded_content
                inside_content = decoded_content.decode('utf-8')

                # Count keywords
                if file.is_javascript():  # Javascript
                    self.programming_counter('javascript', file,
                                             inside_content)
                elif file.is_python():  # Python
                    self.programming_counter('python', file, inside_content)
                elif file.is_java():  # Java
                    self.programming_counter('java', file, inside_content)
                elif file.is_php():  # PHP
                    self.programming_counter('php', file, inside_content)

            return self
Пример #8
0
def get_files(path: str, type: str, filter: str) -> RenameFiles:
    switcher = {
        'numeric': RenameFilesToNumeric,
        'updated_at': RenameFilesToUpdatedAt,
        'default': RenameFiles
    }
    filtered_files = switcher[type]([])

    if filter:
        splitted_filters = filter.split(',')

        for filter in splitted_filters:
            file_result = glob.iglob(path + '/*.' + filter)
            for file in file_result:
                if os.path.isfile(file):
                    filtered_files.add_file(File(file))
    else:
        file_result = glob.iglob(path + '/*')
        for file in file_result:
            if os.path.isfile(file):
                filtered_files.add_file(File(file))

    return filtered_files
Пример #9
0
    def __init__(
        self,
        display_name,
        name,
        installer,
        files=None,
        auto_start=None,
        comments=None,
        post_install_commands=None,
    ):
        self.display_name = display_name
        self.name = name
        self.installer = installer

        if files is None:
            self.files = []
        else:
            self.files = [
                File(
                    _file["name"],
                    _file["path_destination"],
                    _file["path_source"],
                    _file["text"],
                    _file["create_link"],
                    _file["sudo"],
                    _file["comments"],
                ) for _file in files
            ]

        if comments is None:
            self.comments = []
        else:
            self.comments = comments

        if auto_start is None:
            self.auto_start = []
        else:
            self.auto_start = auto_start

        if post_install_commands is None:
            self.post_install_commands = []
        else:
            self.post_install_commands = post_install_commands
Пример #10
0
from classes.file import File
from os.path import exists

f = File('text.txt')
assert f.write_bytes(b'testing bytes i/o'), 17
assert f.read_bytes(), b'testing bytes i/o'
f.open() # does it open any text editor on your system?
f.remove()
assert exists('text.txt'), False
Пример #11
0
from classes.file import File
from os.path import exists

f = File('text.txt')
assert f.write_bytes(b'testing bytes i/o'), 17
assert f.read_bytes(), b'testing bytes i/o'
f.open()  # does it open any text editor on your system?
f.remove()
assert exists('text.txt'), False
Пример #12
0
logger = Logger(logfile)
#logger.set_param('covid_maker.log')
#conn = args.connection

# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    args.date_start, args.date_end = ('2021-05-01', '2021-06-17')
    args.output = './report'

    t0 = timer.get_time()
    report = DIT_report(args.date_start, args.date_end, args.config,
                        args.output, args.contract)
    query = f"SELECT day,sender,template_id,count(1) AS msg FROM new_message WHERE sender='7757' AND " \
            f"day>='{args.date_start}' AND day<'{args.date_end}' AND status!=6  " \
            f"GROUP BY day,sender,template_id ORDER BY day,sender,msg"
    print(query)
    query = "select day,receiver,count(1) as msgs from new_message WHERE sender='7757' AND day>='2021-06-05' AND day<'2021-06-17' AND status!=6 AND template_id=480 group by day,receiver order by day,receiver,msgs;"
    report.tunnels.start()
    report.set_db('postgres', 'mapi')
    rows = report.get_db().call_select(query)

    print(rows[0])
    filepath = f"{report.get_output_dir()}/7757_tmpl_report_num.csv"
    print(filepath)
    file = File(filepath, 'csv')

    file.csv_save(['receiver', 'count of msgs'], rows)

    t2 = timer.time_execute(t0)
    logger.log(f"Finished. Time execute: {t2}", 'INFO', True)
Пример #13
0
    def interactive_insert(group_name=None):
        """Create a new package object from the command line"""
        package_display_name = ""
        package_name = ""
        package_installer = config.default_installer
        package_files = []
        package_auto_start = []
        package_comments = []
        package_post_install_commands = []

        while True:
            message.heading("Creating a new package.")
            if group_name is not None:
                message.info(f"Current group: {group_name}")

            package_display_name = message.question(
                "What is the display name of the package?")
            package_name = message.question(
                "What is the exact name of the package? (Will be used for installing, needs to be exact)"
            )
            package_installer = message.choose(
                ["default", "pacman", "aur", "pip"])
            if package_installer == "default":
                package_installer = config.default_installer

            if message.question("Will this package be autostarted?",
                                "boolean"):
                while True:
                    command = message.question(
                        "New command for autostart (will appear on a newline):"
                    )
                    package_auto_start.append(command)
                    if not message.question("Add another autostart command?",
                                            "boolean"):
                        break

            if message.question(
                    "Will this package have post install commands?",
                    "boolean"):
                while True:
                    command = message.question(
                        "New command for post install (${vars} supported):")
                    package_post_install_commands.append(command)
                    if not message.question("Add another command?", "boolean"):
                        break

            if message.question("Will this package have files associated?",
                                "boolean"):
                while True:
                    _file = File.interactive_insert(group_name,
                                                    package_name).to_dict()
                    package_files.append(_file)
                    if not message.question("Add another file?", "boolean"):
                        break

            if message.question(
                    "Will the package have comments to aid the user?",
                    "boolean"):
                while True:
                    comment = message.question("New comment:")
                    package_comments.append(comment)
                    if not message.question("Add another comment?", "boolean"):
                        break

            package = Package(
                package_display_name,
                package_name,
                package_installer,
                package_files,
                package_auto_start,
                package_comments,
                package_post_install_commands,
            )

            package.evaluate()

            message.info(f"""Package info:
            [Display Name]: '{package.display_name}'
            [Install Name]: '{package.name}'
            [Installer]: '{package.installer}'
            [Autostart]: '{package.auto_start}'
            [Post Install Commands]: '{package.post_install_commands}'
            [Files]: '{[_file.name for _file in package.files]}'
            [Comments]: {package.comments}""")
            if message.question("Confirm?", "boolean"):
                break

        return package
Пример #14
0
    def migrate(self, conn_destination, migrateIds):
        cur = self.getConnection().cursor()
        cur_dest = conn_destination.cursor()

        tables = self.getLinkedTables()
        for table in tables:

            # Get columns from the current table
            columns = self.getTableFields(table)
            str_columns = ",".join(columns)

            strIds = ", ".join(str(i) for i in migrateIds)
            strIds = strIds.strip(", ")

            if table != "users":
                columnName = "user_id"
            else:
                columnName = "id"

            cur.execute("SELECT {} FROM {} WHERE {} IN ({})".format(
                str_columns, table, columnName, strIds))
            data = cur.fetchall()

            # Check if migrated data list from current table is not empty
            if data:
                for line in data:
                    i = 0
                    strValues = ""
                    status = True
                    # Build string for parameters to be replaced in SQL query
                    while i < len(line):
                        strValues += "%s"
                        if i != (len(line) - 1):
                            strValues += ","
                        i += 1
                    try:
                        cur_dest.execute(
                            " INSERT INTO {} ({}) VALUES ({}) ".format(
                                table, str_columns, strValues), (line))
                        conn_destination.commit()
                    except:
                        status = False
                        file = File("logging.txt")
                        file.log(
                            "[{}] WARNING! Entry with id {} already exist in {} table \n"
                            .format(datetime.datetime.now(), line[0], table))
            else:
                print("Table has no relevant data to migrate")

        conn_destination.close()
        print("\nMigration completed!")

        if not status:
            print("\nDetected duplicates in destination DB")
            print("For more details refer to log file: {}".format(
                "storage/logging.txt"))
        else:
            file = File("logging.txt")
            file.log(
                "[{}] SUCCESS! Migration successfully completed! \n".format(
                    datetime.datetime.now()))
user_id1 = 1
user_id2 = 2
user_id3 = 3

pathname1 = "../../files/test.txt"
pathname2 = "../../files/test3.txt"
pathname3 = "../../files/test4.txt"

course_id = None
tags = None

script1 = False
script2 = True

file_test1 = File(user_id1, pathname1, course_id, 1, script1, tags)
file_test2 = File(user_id2, pathname2, course_id, 2, script1, tags)
file_test3 = File(user_id3, pathname3, course_id, 3, script2, tags)

tag1 = "tag1"
tag2 = "tag2"
tag3 = "tag3"
tag4 = "tag4"
tag5 = "tag5"
tag6 = "tag6"

file_test1.add_tag(tag1)
file_test1.add_tag(tag2)

file_test2.add_tag(tag3)
file_test2.add_tag(tag4)
Пример #16
0
class Base(object):
    def __init__(self,
                 config: str = 'config/config.xml',
                 output_dir='./report'):
        if not config:
            config = 'config/config.xml'

        if isinstance(config, str):
            config = Config(config)
        self.config = config

        if not output_dir:
            if 'output_dir' in config.data:
                output_dir = config.data['output_dir']
            else:
                output_dir = '../report'
        self.__output_dir = output_dir
        self.config_db = dict()
        self.__db = DB(typedb='postgres', **self.config_db)

        self.__file = File(f"{self.get_output_dir()}/file.csv", 'csv')

    def set_db(self, typedb='postgres', prefix=None):
        if prefix:
            self.config_db = self.get_config_db(prefix)
        self.__db = DB(typedb=typedb, **self.config_db)

    def get_db(self):
        return self.__db

    def get_config(self):
        return self.config

    def set_config(self, config):
        if isinstance(config, Config):
            self.config = config
        if isinstance(config, str):
            self.config = Config(config)

    def get_output_dir(self):
        return self.__output_dir

    def set_output_dir(self, output_dir='./report'):
        self.__output_dir = output_dir

    def get_config_db(self, prefix: str = 'tgw') -> dict():
        result = dict()
        for key, value in self.get_config().data[prefix].items():
            result[key] = value
        if 'pass' in result.keys():
            result['password'] = result.pop('pass')

        return result

    def get_file(self):
        return self.__file

    def set_file(self, filename, filetype):
        basepath = None
        fullpath = filename
        if '/' in filename:
            filename = (filename.split('/'))[-1]
            basepath = fullpath.replace(filename, '')
        self.__file.set_filetype(filetype)
        if not basepath:
            filename = f"{self.__output_dir}/{filename}"
        else:
            filename = f"{basepath}/{filename}"
        self.__file.set_file(filename)
Пример #17
0
contents = repo.get_contents("")

# Counter
total = 0
javascript = 0
python = 0
java = 0
php = 0

while contents:
    file_content = contents.pop(0)
    if file_content.type == 'dir':
        contents.extend(repo.get_contents(file_content.path))
    else:
        fileName = file_content.name
        file = File(fileName)
        if file.is_python() or file.is_java() or file.is_php(
        ) or file.is_javascript():
            decoded_content = file_content.decoded_content
            inside_content = decoded_content.decode('utf-8')
            length = len(
                re.findall(
                    r'(@GetMapping|@PostMapping|@PutMapping|@DeleteMapping|.get|.post|.put|.delete|::get|::post|::put|::delete|.route)',
                    inside_content))
            total += length

            if file.is_javascript():  # Javascript
                javascript += length
            elif file.is_python():  # Python
                python += length
            elif file.is_java():  # Java