tesseract v5.3.3.20231005
upload.VersionControlSystem Class Reference
Inheritance diagram for upload.VersionControlSystem:
upload.GitVCS upload.MercurialVCS upload.SubversionVCS

Public Member Functions

def __init__ (self, options)
 
def GenerateDiff (self, args)
 
def GetUnknownFiles (self)
 
def CheckForUnknownFiles (self)
 
def GetBaseFile (self, filename)
 
def GetBaseFiles (self, diff)
 
def UploadBaseFiles (self, issue, rpc_server, patch_list, patchset, options, files)
 
def IsImage (self, filename)
 

Public Attributes

 options
 

Detailed Description

Abstract base class providing an interface to the VCS.

Definition at line 603 of file upload.py.

Constructor & Destructor Documentation

◆ __init__()

def upload.VersionControlSystem.__init__ (   self,
  options 
)
Constructor.

Args:
  options: Command line options.

Reimplemented in upload.SubversionVCS, upload.GitVCS, and upload.MercurialVCS.

Definition at line 606 of file upload.py.

606 def __init__(self, options):
607 """Constructor.
608
609 Args:
610 options: Command line options.
611 """
612 self.options = options
613

Member Function Documentation

◆ CheckForUnknownFiles()

def upload.VersionControlSystem.CheckForUnknownFiles (   self)
Show an "are you sure?" prompt if there are unknown files.

Definition at line 628 of file upload.py.

628 def CheckForUnknownFiles(self):
629 """Show an "are you sure?" prompt if there are unknown files."""
630 unknown_files = self.GetUnknownFiles()
631 if unknown_files:
632 print "The following files are not added to version control:"
633 for line in unknown_files:
634 print line
635 prompt = "Are you sure to continue?(y/N) "
636 answer = raw_input(prompt).strip()
637 if answer != "y":
638 ErrorExit("User aborted")
639
def ErrorExit(msg)
Definition: upload.py:124

◆ GenerateDiff()

def upload.VersionControlSystem.GenerateDiff (   self,
  args 
)
Return the current diff as a string.

Args:
  args: Extra arguments to pass to the diff command.

Reimplemented in upload.SubversionVCS, upload.GitVCS, and upload.MercurialVCS.

Definition at line 614 of file upload.py.

614 def GenerateDiff(self, args):
615 """Return the current diff as a string.
616
617 Args:
618 args: Extra arguments to pass to the diff command.
619 """
620 raise NotImplementedError(
621 "abstract method -- subclass %s must override" % self.__class__)
622

◆ GetBaseFile()

def upload.VersionControlSystem.GetBaseFile (   self,
  filename 
)
Get the content of the upstream version of a file.

Returns:
  A tuple (base_content, new_content, is_binary, status)
    base_content: The contents of the base file.
    new_content: For text files, this is empty.  For binary files, this is
      the contents of the new file, since the diff output won't contain
      information to reconstruct the current file.
    is_binary: True iff the file is binary.
    status: The status of the file.

Reimplemented in upload.SubversionVCS, upload.GitVCS, and upload.MercurialVCS.

Definition at line 640 of file upload.py.

640 def GetBaseFile(self, filename):
641 """Get the content of the upstream version of a file.
642
643 Returns:
644 A tuple (base_content, new_content, is_binary, status)
645 base_content: The contents of the base file.
646 new_content: For text files, this is empty. For binary files, this is
647 the contents of the new file, since the diff output won't contain
648 information to reconstruct the current file.
649 is_binary: True iff the file is binary.
650 status: The status of the file.
651 """
652
653 raise NotImplementedError(
654 "abstract method -- subclass %s must override" % self.__class__)
655
656

◆ GetBaseFiles()

def upload.VersionControlSystem.GetBaseFiles (   self,
  diff 
)
Helper that calls GetBase file for each file in the patch.

Returns:
  A dictionary that maps from filename to GetBaseFile's tuple.  Filenames
  are retrieved based on lines that start with "Index:" or
  "Property changes on:".

Definition at line 657 of file upload.py.

657 def GetBaseFiles(self, diff):
658 """Helper that calls GetBase file for each file in the patch.
659
660 Returns:
661 A dictionary that maps from filename to GetBaseFile's tuple. Filenames
662 are retrieved based on lines that start with "Index:" or
663 "Property changes on:".
664 """
665 files = {}
666 for line in diff.splitlines(True):
667 if line.startswith('Index:') or line.startswith('Property changes on:'):
668 unused, filename = line.split(':', 1)
669 # On Windows if a file has property changes its filename uses '\'
670 # instead of '/'.
671 filename = filename.strip().replace('\\', '/')
672 files[filename] = self.GetBaseFile(filename)
673 return files
674
675

◆ GetUnknownFiles()

def upload.VersionControlSystem.GetUnknownFiles (   self)
Return a list of files unknown to the VCS.

Reimplemented in upload.SubversionVCS, upload.GitVCS, and upload.MercurialVCS.

Definition at line 623 of file upload.py.

623 def GetUnknownFiles(self):
624 """Return a list of files unknown to the VCS."""
625 raise NotImplementedError(
626 "abstract method -- subclass %s must override" % self.__class__)
627

◆ IsImage()

def upload.VersionControlSystem.IsImage (   self,
  filename 
)
Returns true if the filename has an image extension.

Definition at line 728 of file upload.py.

728 def IsImage(self, filename):
729 """Returns true if the filename has an image extension."""
730 mimetype = mimetypes.guess_type(filename)[0]
731 if not mimetype:
732 return False
733 return mimetype.startswith("image/")
734
735

◆ UploadBaseFiles()

def upload.VersionControlSystem.UploadBaseFiles (   self,
  issue,
  rpc_server,
  patch_list,
  patchset,
  options,
  files 
)
Uploads the base files (and if necessary, the current ones as well).

Definition at line 676 of file upload.py.

677 files):
678 """Uploads the base files (and if necessary, the current ones as well)."""
679
680 def UploadFile(filename, file_id, content, is_binary, status, is_base):
681 """Uploads a file to the server."""
682 file_too_large = False
683 if is_base:
684 type = "base"
685 else:
686 type = "current"
687 if len(content) > MAX_UPLOAD_SIZE:
688 print ("Not uploading the %s file for %s because it's too large." %
689 (type, filename))
690 file_too_large = True
691 content = ""
692 checksum = md5.new(content).hexdigest()
693 if options.verbose > 0 and not file_too_large:
694 print "Uploading %s file for %s" % (type, filename)
695 url = "/%d/upload_content/%d/%d" % (int(issue), int(patchset), file_id)
696 form_fields = [("filename", filename),
697 ("status", status),
698 ("checksum", checksum),
699 ("is_binary", str(is_binary)),
700 ("is_current", str(not is_base)),
701 ]
702 if file_too_large:
703 form_fields.append(("file_too_large", "1"))
704 if options.email:
705 form_fields.append(("user", options.email))
706 ctype, body = EncodeMultipartFormData(form_fields,
707 [("data", filename, content)])
708 response_body = rpc_server.Send(url, body,
709 content_type=ctype)
710 if not response_body.startswith("OK"):
711 StatusUpdate(" --> %s" % response_body)
712 sys.exit(1)
713
714 patches = dict()
715 [patches.setdefault(v, k) for k, v in patch_list]
716 for filename in patches.keys():
717 base_content, new_content, is_binary, status = files[filename]
718 file_id_str = patches.get(filename)
719 if file_id_str.find("nobase") != -1:
720 base_content = None
721 file_id_str = file_id_str[file_id_str.rfind("_") + 1:]
722 file_id = int(file_id_str)
723 if base_content != None:
724 UploadFile(filename, file_id, base_content, is_binary, status, True)
725 if new_content != None:
726 UploadFile(filename, file_id, new_content, is_binary, status, False)
727
def EncodeMultipartFormData(fields, files)
Definition: upload.py:513
def StatusUpdate(msg)
Definition: upload.py:112

Member Data Documentation

◆ options

upload.VersionControlSystem.options

Definition at line 612 of file upload.py.


The documentation for this class was generated from the following file: