2016年5月22日 今天完成的代码实践 定义类和方法

不知道能不能跑通。。。最大的坑在于,如何让python找到指定的文件路径,而又不需要扫描全盘。。。经过高人指点,尝试了os.getcwd()的方法首先确定当前的工作路径,然后周一去找老大确认一下可能的绝对路径再拼凑吧

try:
    import sys
    import time
    import os
    import platform
    import linecache
    os.chdir('../res')
    sys.path.append(os.getcwd())
    from adb import ADB

    except ImportError as e:
        print("[f] Required module missing. %s" % e.args[0])
        sys.exit(-1)
#f = open(r'E:\工作\Python_practice\Cienet_Monkey\monkey\configFile.txt','r')
work_space = r'E:\工作\Python_practice\Cienet_Monkey\monkey\configFile.txt'
class check_parameters:
    def __init__(self):
        self.serial_no = serial_no
        self.test_hour = test_hour
        self.cycle_time = cycle_time
        self.target_project = target_project
        self.test_type = test_type
        self.pkg_file = pkg_file
        self.execute_method = execute_method
        self.jira_project = jira_project
        self.change_profile_hour = change_profile_hour
        self.get_all_parameters = get_all_parameters
        self.get_configfile_path = get_configfile_path

    def get_cofigfile_path(self):
        base_dir = os.getcwd\..\test #从工作路径向上寻找configfile所在的绝对路径
        configfile_path = os.path.join(base_dir, 'configfile.txt') #获取configfile.txt
        configfile = open(configfile_path, 'r')
        return configfile

    def _get_serial_no():
        linecache.clear() #clear cache
        serial_no = linecache.getline(configfile,1)
        return serial_no

    def _get_test_hour():
        linecache.clear() #clear cache
        test_hour = linecache.getline(configfile,2)
        return test_hour

    def _get_cycle_time():
        linecache.clear() #clear cache
        cycle_time = linecache.getline(configfile,3)
        return cycle_time

    def _get_target_project():
        linecache.clear() #clear cache
        target_project = linecache.getline(configfile,4)
        return target_project

    def _get_test_type():
        linecache.clear() #clear cache
        test_type = linecache.getline(configfile,5)
        return test_type

    def _get_pkg_file():
        linecache.clear() #clear cache
        pkg_file = linecache.getline(configfile,6)
        return pkg_file

    def _get_execute_method():
        linecache.clear() #clear cache
        execute_method = linecache.getline(configfile,7)
        return execute_method

    def _get_jira_project():
        linecache.clear() #clear cache
        jira_project = linecache.getline(configfile,8)
        return jira_project

    def _get_change_profile_hour():
        linecache.clear() #clear cache
        change_profile_hour = linecache.getline(configfile,9)
        return change_profile_hour

    def _get_all_parameters():
        linecache.clear() #clear cache
        get_all_parameters = configfile.readlines()
        return get_all_parameters




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值