Simple Package Tool 学习

Simple Package Tool 学习

1.getattr内置函数

getattr(object, name[, default])

python Packages.py install -p "$host_ip" -s "$build_series" -v "$build_version" -n "$ne_type" -i "$ini_path" -d "$dir_name" -b "$sw_name" -m "$active_omu" -g "$digi_ip"

Packages.py

 1 ACTION_LIST = (‘config‘, ‘install‘, ‘patch‘, ‘burn‘, ‘sync‘)
 2
 3 class Packages(object):
 4
 5   def __init__(self):
 6
 7     pass;
 8
 9   def __getattr__(self, arg):
10
11     if arg in ACTION_LIST:
12
13           return getattr(self, ‘handle_%s_cmd‘ % arg)
14
15        raise AttributeError
16
17
18
19 #sys.argv[]是用来获取命令行参数的,sys.argv[0]表示代码本身文件路径,所以参数从1开始
20
21 def main(argv=None):
22
23   args = argv[1:]
24
25   action = args[0]
26
27   action_args = args[1:]
28
29   actor = getattr(Packages(), action)(action_args) #getattr()为获取某个类里的某个属性函数等,后面再接括号即为运行该函数
32
33
34
35 if __name__ == "__main__":
36
37   sys.exit(main())

2.optparse模块

from optparse import OptionParser  

parser = OptionParser()  

parser.add_option("-f","--file",dest="filename",help="write report to FILE",metavar="FILE")  

parser.add_option("-q", "--quiet", action="store_false", dest="verbose", default=True,help="don‘t print status messages to stdout")  

(options, args) = parser.parse_args() 

3.

    SW-PACKAGE     STATUS   DIRECTORY           ENVIRONMENT          DEF  ACT
                            PACKAGE-ID (REP-ID) DELIVERY
                                                CD-ID

    CRND8155       BU       CRND81550           CB 15.5-0             -    Y
                            CB 15.5-0           CNR51840 2.7-15   

    CR2CZ154       NW       CR2CZ15444          CB 15.4-44            Y    Y
                            CB 15.4-0           CNR51840 2.7-15   

    CRE8H154       UT       CRE8H1540           CB 15.4-0             -    Y
                            CB 15.4-0           CNR51840 2.7-15   

    CRPEY154       UT       CRPEY15443          CB 15.4-43            -    Y
                            CB 15.4-0           CNR51840 2.7-15
                                                          

如何将每一行数据和对应的title成键值对输出?

上述数据的特点:每一列的起始位置都是对齐的,因此可以利用这一点,每一列的距离 = 下一列的起始位置 - 该列的起始位置,这样就能将每一列数据获取出来和title对应.

例:我们要获取CRND8155这个值(将该行先定义为line4,第一行定义为line1):line4[line1.index(‘SW-PACKAGE‘):line1.index(‘STATUS‘)].strip()

时间: 2024-08-29 05:52:31

Simple Package Tool 学习的相关文章

Debug tool 学习笔记

GDB调试命令大全 gdb --pid 1235 gdb core.1234 where (bt)    //where the segmentation fault occurred f 1              //切换栈帧 info locals  //打印内存 WinDBG调试技巧 .ecxr command displays the context record Debug tool 学习笔记

[Tools] Create a Simple CLI Tool in Node.js with CAC

Command-line tools can help you with all sorts of tasks. This lesson covers the very basics of setting up a CLI tool in Node.js by creating your project with npm, setting up your bin script, and using CAC to parse a single argument. Create a new proj

static wechat red package tool

---------------------------------------------------------------------------------------------| name      | wechat   | lock       | in chat  | speed     | return   | support ||                | is focus  | screen   |              |               |    

大三学习规划路线图

路线图介绍: 本课程对大数据生态系统进行全方位讲解,有hadoop实操与底层原理应用,DFS与MapRedcue的全新解读,内含有全网独家发布的YARN调度框架的底层事件二次分发机制和Google源码级IPC和RPC的通信技术原理与报文字节码级别的协议分析,Scala语言的编程技巧与java语言的互操作性,Spark中数据处理如何弹性化.如何调优以及对Scala编程语言的典型应用.ZooKeeper作为分布式系统协同服务的原理实现与实战应用,zkCli下同zk的交互模式以及素有瑞士***之称的N

从0开始学习ssh之搭建环境

ssh即struts+spring+Hibernate,从头开始学习这个框架. struts环境配置,首先在apps目录下找到struts2-blank-xxx.war这个文件,这是已经发布好的war包.其中找到lib文件夹,添加其中所有jar到网站lib下面.再找到src/java下面的struts.xml文件,添加到网站的src文件夹中.打开web.xml拷贝struts的核心配置到网站的web.xml,核心配置如下 <filter> <filter-name>struts2&

【web开发学习笔记】Struts-Tags学习笔记1 - 通用标签和控制标签

通用标签和控制标签 第一部分:代码 //前端 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GB18030" /> <title>Insert title here</title> </head> <body> 访问属性 <a href="<%=contextP

Object-Oriented Analysis and Design Using UML 翻译与学习 (目录)

Object-Oriented Analysis and Design Using UML 面向对象分析与使用UML设计 最近找了本书<Object-Oriented Analysis and Design Using UML>,这个书是Oracle培训里面的,同时也是获取scjd和scja可选的课程. 所以,我准备一边翻译,一边学习.嗯,只翻译重点. 转载请注明出处!!! Copyright 2010 Sun Microsystems, Inc., 4150 Network Circle,

深度强化学习(Deep Reinforcement Learning)入门:RL base &amp; DQN-DDPG-A3C introduction

转自https://zhuanlan.zhihu.com/p/25239682 过去的一段时间在深度强化学习领域投入了不少精力,工作中也在应用DRL解决业务问题.子曰:温故而知新,在进一步深入研究和应用DRL前,阶段性的整理下相关知识点.本文集中在DRL的model-free方法的Value-based和Policy-base方法,详细介绍下RL的基本概念和Value-based DQN,Policy-based DDPG两个主要算法,对目前state-of-art的算法(A3C)详细介绍,其他

YUM repository and package management: Complete Tutorial

Every operating system must have some or the other way to install a program. What's important is the fact that the user must not be given the responsibility of managing the overhead involved in the installation of the program. You would ask,what's th