p4cmd 2.5.0__tar.gz → 2.7.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. {p4cmd-2.5.0 → p4cmd-2.7.0}/PKG-INFO +1 -1
  2. {p4cmd-2.5.0 → p4cmd-2.7.0}/p4cmd/__init__.py +1 -1
  3. {p4cmd-2.5.0 → p4cmd-2.7.0}/p4cmd/p4cmd.py +181 -2
  4. {p4cmd-2.5.0 → p4cmd-2.7.0}/p4cmd.egg-info/PKG-INFO +1 -1
  5. {p4cmd-2.5.0 → p4cmd-2.7.0}/LICENSE +0 -0
  6. {p4cmd-2.5.0 → p4cmd-2.7.0}/README.md +0 -0
  7. {p4cmd-2.5.0 → p4cmd-2.7.0}/p4cmd/p4errors.py +0 -0
  8. {p4cmd-2.5.0 → p4cmd-2.7.0}/p4cmd/p4file.py +0 -0
  9. {p4cmd-2.5.0 → p4cmd-2.7.0}/p4cmd/resources/__init__.py +0 -0
  10. {p4cmd-2.5.0 → p4cmd-2.7.0}/p4cmd/resources/perforce_DEPOT_ONLY.png +0 -0
  11. {p4cmd-2.5.0 → p4cmd-2.7.0}/p4cmd/resources/perforce_MOVED.png +0 -0
  12. {p4cmd-2.5.0 → p4cmd-2.7.0}/p4cmd/resources/perforce_NEED_SYNC.png +0 -0
  13. {p4cmd-2.5.0 → p4cmd-2.7.0}/p4cmd/resources/perforce_OPEN_FOR_ADD.png +0 -0
  14. {p4cmd-2.5.0 → p4cmd-2.7.0}/p4cmd/resources/perforce_OPEN_FOR_DELETE.png +0 -0
  15. {p4cmd-2.5.0 → p4cmd-2.7.0}/p4cmd/resources/perforce_OPEN_FOR_EDIT.png +0 -0
  16. {p4cmd-2.5.0 → p4cmd-2.7.0}/p4cmd/resources/perforce_UNKNOWN.png +0 -0
  17. {p4cmd-2.5.0 → p4cmd-2.7.0}/p4cmd/resources/perforce_UNTRACKED.png +0 -0
  18. {p4cmd-2.5.0 → p4cmd-2.7.0}/p4cmd/resources/perforce_UP_TO_DATE.png +0 -0
  19. {p4cmd-2.5.0 → p4cmd-2.7.0}/p4cmd/utils.py +0 -0
  20. {p4cmd-2.5.0 → p4cmd-2.7.0}/p4cmd.egg-info/SOURCES.txt +0 -0
  21. {p4cmd-2.5.0 → p4cmd-2.7.0}/p4cmd.egg-info/dependency_links.txt +0 -0
  22. {p4cmd-2.5.0 → p4cmd-2.7.0}/p4cmd.egg-info/top_level.txt +0 -0
  23. {p4cmd-2.5.0 → p4cmd-2.7.0}/setup.cfg +0 -0
  24. {p4cmd-2.5.0 → p4cmd-2.7.0}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: p4cmd
3
- Version: 2.5.0
3
+ Version: 2.7.0
4
4
  Summary: Simple P4 python module
5
5
  Home-page: https://github.com/nielsvaes/p4cmd
6
6
  Author: Niels Vaes
@@ -1,4 +1,4 @@
1
- VERSION = "2.5.0"
1
+ VERSION = "2.7.0"
2
2
 
3
3
  from .p4cmd import P4Client
4
4
  from .p4file import P4File
@@ -51,6 +51,8 @@ class P4Client(object):
51
51
  self.server = self.get_p4_setting("P4PORT")
52
52
  if self.server is None:
53
53
  raise p4errors.WorkSpaceError("Could not find P4PORT")
54
+
55
+ self.depot_root = self.get_depot_paths([self.perforce_root])[0]
54
56
 
55
57
  @classmethod
56
58
  def from_env(cls, *args, **kwargs):
@@ -304,7 +306,73 @@ class P4Client(object):
304
306
  if len(changelists):
305
307
  return True
306
308
  return False
309
+
310
+ def update_changelist_description(self, changelist, new_description):
311
+ """
312
+ Updates the description of an existing changelist.
307
313
 
314
+ :param changelist: *string* or *int* changelist number
315
+ :param new_description: *string* new description for the changelist
316
+ :return: *bool* True if successful, False otherwise
317
+ """
318
+
319
+ # ... not super elegant, but it works
320
+ try:
321
+ changelist = self.__ensure_changelist(changelist)
322
+
323
+ # do some formatting so that we have the proper indentation
324
+ formatted_description = []
325
+ for line in new_description.split('\n'):
326
+ formatted_description.append(f"\t{line}")
327
+ formatted_description = '\n'.join(formatted_description)
328
+
329
+ output = subprocess.check_output(f'p4 change -o {changelist}', shell=True).decode()
330
+
331
+ # Split the output into sections based on field names
332
+ sections = []
333
+ current_section = []
334
+ current_field = None
335
+
336
+ # take the output and start parsing it
337
+ for line in output.split('\n'):
338
+ # check if it's a new field
339
+ if line.strip() and ':' in line and not line.startswith('\t'):
340
+ # if it is, save the previous section
341
+ if current_field:
342
+ sections.append((current_field, current_section))
343
+ # now start a new section
344
+ current_field = line.split(':', 1)[0].strip()
345
+ current_section = [line]
346
+ else:
347
+ # if it's not a new field, add to the current section
348
+ current_section.append(line)
349
+
350
+ # add the last section
351
+ if current_field:
352
+ sections.append((current_field, current_section))
353
+
354
+ # new remake the Description field with the update description
355
+ new_output = []
356
+ for field, section_lines in sections:
357
+ if field == "Description":
358
+ # replace the description section
359
+ new_output.append(section_lines[0]) # keep the "Description:" line because perforce needs this
360
+ new_output.append(formatted_description)
361
+ else:
362
+ # keep everything else as-is
363
+ new_output.extend(section_lines)
364
+
365
+ updated_output = '\n'.join(new_output)
366
+
367
+ # TODO: modify run_cmd to allow input so that commands like this can also run through it.
368
+ result = subprocess.check_output(f'p4 change -i', input=updated_output.encode(), shell=True).decode()
369
+
370
+ return True
371
+ except Exception as e:
372
+ if not self.silent:
373
+ logging.error(f"Failed to update changelist description: {e}")
374
+ return False
375
+
308
376
  @validate_not_empty
309
377
  def move_files_to_changelist(self, file_list, changelist="default"):
310
378
  """
@@ -594,6 +662,117 @@ class P4Client(object):
594
662
 
595
663
  return files_and_cl
596
664
 
665
+ @validate_not_empty
666
+ def shelve_files(self, changelist, file_list=None, revert_after_shelve=False, force=False):
667
+ """
668
+ Shelves files in a changelist. If no files are specified, shelves all files in the changelist.
669
+
670
+ :param changelist: *string* or *int* changelist number or description
671
+ :param file_list: *list* or *None* list of files to shelve. If None, shelves all files in the changelist
672
+ :param revert_after_shelve: *bool* if True, reverts the files after shelving them
673
+ :param force: *bool* if True, forces the shelving operation even if files are already shelved
674
+ :return: *list* of info dictionaries
675
+ """
676
+ changelist = self.__ensure_changelist(changelist)
677
+
678
+ # if no files specified, get all files in the changelist
679
+ if file_list is None:
680
+ file_list = self.get_files_in_changelist(changelist)
681
+ else:
682
+ file_list = convert_to_list(file_list) if not isinstance(file_list, list) else file_list
683
+ if not self.silent:
684
+ self.__validate_file_list(file_list)
685
+
686
+ # if there are no files to shelve, return empty list
687
+ if not file_list:
688
+ if not self.silent:
689
+ logging.warning(f"No files to shelve in changelist {changelist}")
690
+ return []
691
+
692
+ # iuild args list based on options
693
+ args = ["-c", str(changelist)]
694
+ if force:
695
+ args.append("-f")
696
+
697
+ # run the shelve command
698
+ info_dicts = self.run_cmd("shelve", args=args, file_list=file_list)
699
+
700
+ for info_dict in info_dicts:
701
+ if self.__get_dict_value(info_dict, "code") == "error" and not self.silent:
702
+ logging.error(self.__get_dict_value(info_dict, "data"))
703
+
704
+ # revert files if requested
705
+ if revert_after_shelve and file_list:
706
+ revert_info_dicts = self.revert_files(file_list)
707
+ # add revert info to the return data
708
+ info_dicts.extend(revert_info_dicts)
709
+
710
+ return info_dicts
711
+
712
+ def unshelve_files(self, changelist, file_list=None, target_changelist="default", force=False, delete_shelved_files=False):
713
+ """
714
+ Unshelves files from a shelved changelist. If no files are specified, unshelves all files.
715
+
716
+ :param changelist: *string* or *int* source changelist number containing shelved files
717
+ :param file_list: *list* or *None* list of files to unshelve. If None, unshelves all files
718
+ :param target_changelist: *string* or *int* target changelist to unshelve files into
719
+ :param force: *bool* if True, forces the unshelve operation even if files are already opened
720
+ :param delete_shelved_files: *bool* if True, deletes the shelved files after unshelving them
721
+ :return: *list* of info dictionaries
722
+ """
723
+ source_changelist = self.__ensure_changelist(changelist)
724
+ target_changelist = self.__ensure_changelist(target_changelist)
725
+
726
+ # build the arguments list
727
+ args = []
728
+
729
+ # add force flag if requested
730
+ if force:
731
+ args.append("-f")
732
+
733
+ # add source changelist (required)
734
+ args.extend(["-s", str(source_changelist)])
735
+
736
+ # add target changelist if specified and not default
737
+ if target_changelist != "default":
738
+ args.extend(["-c", str(target_changelist)])
739
+
740
+ # prepare file list if provided
741
+ if file_list is not None:
742
+ file_list = convert_to_list(file_list) if not isinstance(file_list, list) else file_list
743
+ if not self.silent:
744
+ self.__validate_file_list(file_list)
745
+ else:
746
+ file_list = []
747
+
748
+ # run the unshelve command
749
+ info_dicts = self.run_cmd("unshelve", args=args, file_list=file_list)
750
+
751
+ # check for errors in the unshelve operation
752
+ has_error = False
753
+ for info_dict in info_dicts:
754
+ if self.__get_dict_value(info_dict, "code") == "error" and not self.silent:
755
+ logging.error(self.__get_dict_value(info_dict, "data"))
756
+ has_error = True
757
+
758
+ # delete shelved files if requested and unshelve was successful
759
+ if delete_shelved_files and not has_error:
760
+ # build the arguments for the shelve -d command
761
+ delete_args = ["-d", "-c", str(source_changelist)]
762
+
763
+ # if file_list provided, use it for the delete operation as well
764
+ delete_info_dicts = self.run_cmd("shelve", args=delete_args, file_list=file_list)
765
+
766
+ # check for errors in the delete operation
767
+ for info_dict in delete_info_dicts:
768
+ if self.__get_dict_value(info_dict, "code") == "error" and not self.silent:
769
+ logging.error(self.__get_dict_value(info_dict, "data"))
770
+
771
+ # add the delete info to the return data
772
+ info_dicts.extend(delete_info_dicts)
773
+
774
+ return info_dicts
775
+
597
776
  @validate_not_empty
598
777
  def add_or_edit_folders(self, folders, include_subfolders=True, changelist="default"):
599
778
  """
@@ -1039,6 +1218,6 @@ class P4Client(object):
1039
1218
  # Easy utility to check that the file is underneath the correct perforce root
1040
1219
  # Quicker than waiting for the result of a p4 fstat
1041
1220
  for f in file_list:
1042
- if not f.lower().startswith(self.perforce_root.lower()):
1043
- raise Exception(f'{f} is not under perforce root: {self.perforce_root}')
1221
+ if not f.lower().startswith(self.perforce_root.lower()) and not f.lower().startswith(self.depot_root.lower()):
1222
+ raise Exception(f'{f} is not under perforce root: {self.perforce_root}, {self.depot_root}')
1044
1223
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: p4cmd
3
- Version: 2.5.0
3
+ Version: 2.7.0
4
4
  Summary: Simple P4 python module
5
5
  Home-page: https://github.com/nielsvaes/p4cmd
6
6
  Author: Niels Vaes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes