How to implement the full contents of the Python backup directory and directory

Source: Internet
Author: User
Tags tortoisesvn
I was going to write something. You can call TortoiseSVN to save the current code under a branch.

Unfortunately the part of calling SVN is still being researched. You write the part of the directory copy first.

If you have children's shoes that like to study python and would like to provide ideas or suggestions,

Here, thank you first. :)

As for the part of the catalog copy, the idea is simple. Read the configuration information in the configuration file.

Generate a name for the project and a date-time folder named the branch name. Put all the content under the current project

Copy to this directory.

The next study is to call the TORTOISESVN command to embed this part of the code.

Now look at the code:

1. Read the configuration file

The configuration file is simple. The TXT file is used. The format is similar to:

# root:/users/lichallenger/test_src/# project:test# destination:/users/lichallenger/test_dst/

BTW: I use a Mac so the directory format is like this. If you are using Windows, please

When you modify the configuration file.

Reading the file is the simplest. Open the file directly with the file operation module of the standard library and read out all the configuration. Three lines altogether, so

You don't have to think about efficiency or anything.

# Open config file and read config information# author:bruce liclass confighandler (object):  #  def __init__ (self,c Onfig_path):    ' initializer '    self.config_path = config_path    #read config infor  def read_config ( Self):    f = open (Self.config_path)    try:      self.all_lines = F.readlines ()    except:      raise      Else :  

2. Copy directory and directory contents

The copy directory uses the Shutil module. There is a way to copy all the contents and directories directly to the other directory.

This saves code such as directory traversal.

# copy Dir (s) & file (s) to configured path# author:bruce liimport shutilclass Copyhandler (object):  #  def __in It__ (Self,src_path,dest_path):    self.src_path = src_path    Self.dest_path = Dest_path  def move_content ( Self):    try:      shutil.copytree (Self.src_path,self.dest_path)    except:      raise    @staticmethod  def  move_src_content (SRC, dest):    try:      shutil.copytree (Src_path,dest_path)    except:      Raise

3. Synthetic invocation

This takes the time module to get the current times and then generates a portion of the target folder name.

The first of the system parameters that the outside world has passed to Python is the file name. This file is equivalent to the program file in the C # project.

It contains a main function. Although this function is not necessarily named Main.

Also note that the line break for Python code is \.

# main of dir copy function

Import sysimport timefrom code_bk_cpy import *from code_bk_config import * #print __name__def Main (): Config_path = sys.ar GV[1] # Check if path of configuration path is empty if (not Config_path): print ' configuration information is need Ed ' return-1 Config_handler = Confighandler (Config_path) config_handler.read_config () Config_list = Config_handl  Er.all_lines If Len (config_list)! = 3:print ' configuration information is not correct ' return-1 # set source Sep = ': ' Current_datetime = Time.localtime (Time.time ()) Root_path = Config_list[0].split (Sep) [1] prj_name = Config_lis T[1].split (Sep) [1] dst_path = config_list[2].split (Sep) [1] Root_path = (Root_path + prj_name). replace (' \ n ', ') prj_fold ER = prj_name + str (current_datetime.tm_year) + str (current_datetime.tm_mon) + \str (current_datetime.tm_mday) + str ( Current_datetime.tm_hour) + \str (current_datetime.tm_min) + str (current_datetime.tm_sec) Dst_path = (Dst_path + '/' + PRJ _folder + '/'). Replace (' \ n ', ' ') Copy_handler = Copyhandler (Root_path,dst_path) copy_handler.move_content () print ' content moved ' # start main functi OnPrint __name__if __name__ = = "__main__": Main ()

When I have time, I'll look at what TortoiseSVN calls that piece. Estimation is not difficult, that is, the problem of invoking EXE parameters.

I beginner python, if you have any questions please correct me! Thank you.

The above Python backup directory and the contents of the entire content of the implementation method is small to share all the content of everyone, hope to give you a reference, but also hope that we support the script home.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.